11
Scripting Board / Re: Trading Scripts
« Last post by erwin on January 06, 2017, 07:22:55 am »Trading script v3, uses real examples. Imms only need to edit the first part, and can add as many or as few items as wanted. Script takes care of the rest.
Wishlist: Can we hardcode this somehow? Something like medit / oedit / sedit. tradeedit?
Note: We're setting a flag for this, so we can also track how many items players have traded, for that vendor.
Wishlist: Can we hardcode this somehow? Something like medit / oedit / sedit. tradeedit?
Note: We're setting a flag for this, so we can also track how many items players have traded, for that vendor.
Code: [Select]
if !%actor.is_pc%
halt
endif
* Molly, Kvetch, whoever wants to add MORE trading stuff here, follow the
* comments
*
* If you want to reduce the number of items traded, it's a bit more complex.
* Send me a note, or any of the coders.
* Ideally, we should probably write this in C instead of DG scripts.
*
* Flag: trade_winter
* Currently, can trade SIX items, and mob rejects FOUR items
*
*********
*********
*** The Edit Place
* Edit the below if you want to change the number of items traded
set max_items 6
* na_flag is basically SIX nas (or however max_items nas)
set na_flag na na na na na na
* thinrope
set item1 52615
set speecha1 Bob says, 'OK, most of the mountaneers buy a thin rope from me.'
* thickrope
set item2 52616
set speecha2 Bob says, 'Right, thinropes are in most demand of course.
set speechb2 But there are situations when the mountaineers need thicker ropes too.
set speechc2 I've seen ten of them dangle over a precipice from the same rope.'
* longrope
set item3 52617
set speecha3 Bob says, 'Thanks! Just what I wanted.
set speechb3 I need a longrope in reserve in case some of them mountaneers falls into a deep ravine.'
* ropeladder
set item4 52618
set speecha4 Bob says, 'Great! I was just out of ropeladders!'
* wool yarn
set item5 52619 52620
set speecha5 Bob says, 'Yup, wool yarn is popular around here.'
* wool cloth
set item6 52624 52625
set speecha6 Bob says, 'Mmm, wool cloth is just what we need.
set speechb6 None of the other kinds keep you warm enough.'
* TP and EXP for each item
set tp_reward_vec 5 13 28 0 3 7
set brass_reward_vec 0 0 0 1 0 0
set exp_reward_vec 3000 6000 8000 10000 1000 1000
* rejected items
set rej_max_items 3
* cotton thread
set rej1 3266 30957
set rejspeecha1 Bob says, 'No thanks, I'm really just interested in wool yarn and cloth.
set rejspeechb1 It's too cold for other materials here.'
* silk
set rej2 52651 52661
set rejspeecha2 Bob says wistfully, 'I wish I could afford it.
set rejspeechb2 But nobody around here would buy silk, And it's too cold for it anyway.'
* cloth
set rej3 3267 30958 44653
set rejspeecha3 Bob says, 'Sorry, I cannot afford silk, and neither can my customers.'
****
* Can stop here for most cases. Below is generic stuff.
*
set trade_winter %na_flag%
if !%actor.varexists(trade_winter)%
remote trade_winter %actor.id%
elseif %actor.varexists(trade_winter)%
* Check to see if we have any changes in the length if this var exists
set findnumwords %actor.trade_winter%
function 21625
* Check to see if variable max_items (set above) is equal
* to number of words in trade_winter, eg if you modified above
* flag to trade NINE items instead of SIX.
if %max_items% != %num%
* someone added more items so that's fine
set ub 0
while %ub% < %num%
eval ub %ub% + 1
*%echo% Replacing...
replace_word %findnumwords.wordat(%ub%)% %ub% trade_winter
done
remote trade_winter %actor.id%
endif
endif
set trade_winter %actor.trade_winter%
* BEFORE CALLING 21627
* Make sure you have defined a prefix for the items traded
* Above it's item1, item2, item3, item4, item5, item6, so prefix is item
* Also make sure you've set max_items, which ought to be ABOVE
* For the purists: function 21627 takes in an input prefix, and max_items,
* gives an output item_in_list
set prefix item
function 21627
set traded_item %item_in_list%
** The reward for great trading items
** Can mostly ignore this part
if %traded_item% != 0
*Great, no rejected items. Now to find which one
wait 1
mjunk %object%
* evals the correct speech corresponding to the traded item
eval tosaypartone %%speecha%traded_item%%%
eval tosayparttwo %%speechb%traded_item%%%
eval tosaypartthree %%speechc%traded_item%%%
%send% %actor% %tosaypartone%
if %tosayparttwo%
%send% %actor% %tosayparttwo%
endif
if %tosaypartthree%
%send% %actor% %tosaypartthree%
endif
wait 1
* Reward goes here, corresponding to the traded_item
set tp_reward %tp_reward_vec.wordat(%traded_item%)%
nop %actor.trade(%tp_reward%)%
if %tp_reward% == 1
emote hands over %tp_reward% tradepoint.
elseif %tp_reward% > 1
emote hands over %tp_reward% tradepoints.
endif
eval d %actor.level% * %exp_reward_vec.wordat(%traded_item%)%
nop %actor.exp(%d%)%
* tokens
set bronze_reward %brass_reward_vec.wordat(%traded_item%)%
set counter 0
while %counter% < %bronze_reward
eval counter %counter% + 1
emote hands over a brass token.
%load% obj 3300 %actor%
done
set trade_winter %actor.trade_winter%
set curr_item %trade_winter.wordat(%traded_item%)%
if %curr_item% == na
set curr_item 1
else
eval curr_item %curr_item% + 1
endif
replace_word %curr_item% %traded_item% trade_winter
remote trade_winter %actor.id%
* Halt this script if we have successfully traded!
halt
endif
* Let's do the same for rejected items for special messages
* We are calling the same function 21627 again, but with
* rejected items as input
* So max_items is now rej_max_items, and prefix is rej
set max_items %rej_max_items%
set prefix rej
function 21627
set rej_traded_item %item_in_list%
if %rej_traded_item% != 0
eval tosay1 %%rejspeecha%rej_traded_item%%%
eval tosay2 %%rejspeechb%rej_traded_item%%%
%send% %actor% %tosay1%
if %tosay2%
%send% %actor% %tosay2%
endif
halt
else
emote says, 'Sorry, I don't trade in that kind of stuff.'
endif