Building & Scripting > Scripting Board

Trading Scripts

(1/2) > >>

erwin:
Here's one way to do a trading script, which would account for lots of different items being traded, and rejected.

However, before the script is posted, let's think about how the script would work. In the old days, the script would be something like (in pseudo code):

--- Code: ---if %item.vnum% == 100 || %item.vnum% == 101
  %send% %actor% Thank you for trading item number 100 or item 101!
  %send% %actor% Let me give you a reward
elseif %item.vnum% == 103
  %send% %actor% Thank you for trading item number 103!
  %send% %actor% Let me give you a reward
elseif %item.vnum% == 105
  %send% %actor% Thank you for trading item number 105!
  %send% %actor% Let me give you a reward!
elseif %item.vnum% == 110 || %item.vnum% == 114 || %item.vnum% == 120
  %send% %actor% Sorry, I don't take this type of items
  %send% %actor% Go away!
endif

--- End code ---

However, we see that a lot of things are repeated. For example, for a correct item, the code is always of the form:

--- Code: ---if %item.vnum% == "correct vnum"
  mob gives some reward for the item
  mob says thank you
endif

--- End code ---

For example, if the mob can receive 10 different items, then for each item, we might have the (duplicated) code

--- Code: ---wait 1s
mjunk %object%
say thank you
give TP reward
give XP reward

--- End code ---
10 items would mean 50 lines of duplicated code. This takes up a lot of space. Can we do better? (yes).

So here's a way to do it


--- Code: ---* First, set the number of items that the mob trades. Suppose the mob is a jeweller, and trades the six items only
* The numbers correspond to the correct vnums
* Speech is optional - could have lots of variables for this, just make sure the last "character" of the speech is the
* same number of the item. But if you want the mob to say the same thing for each item
* then in the loop below, could just "say thank you".

* Item 1 corresponds to diamonds
set item1 111 112 113 114 120
set speecha1 thank you for the diamonds
set speechb1 blah blah love you

* Item 2 corresponds to rubies
set item2 200 201 214 206
set speecha2 thank you for the rubies
set speechb2 blah blah love you


* Item 3 corresponds to garnets
set item3 300 301 333 399
set speecha3 thank you for the garnets
set speechb3 blah blah love you

* Item 4 corresponds to sapphires
set item4 400 420 490
set speecha4 thank you for the sapphires
set speechb4 blah blah love you


* Item 5 corresponds to quartz
set item5 500
set speecha5 thank you for the quartz
set speechb5 blah blah love you


* Item 6 corresponds to topaz
set item6 666 669
set speecha6 thank you for the topaz
set speechb6 blah blah love you


* Set the maximum items the mob trades, in this case 6
set max_items 6

* Set the rewards for each of them. So item 1 (diamonds) would get 1 TP and 1000 xp, and item 6 (topaz)
* would get 9 TP and 4000 xp

set tp_reward_vec 1 4 3 2 4 9
set exp_reward_vec 1000 3000 1000 1000 4000 4000

* You can set rejected items as well, for example, suppose the mob rejects fool's gold and iron pyrite

* rej_item 1 corresponds to fool's gold
set rej_item1 1000 1005 1110
set rej_speech1 I don't want fool's gold.

* rej_item 2 corresponds to iron pyrite
set rej_item2 2000 2222
set rej_speech2 I don't want iron pyrite.

* Set maximum number of rej items. In this case, 2
set rej_max_items 2

* Now comes the main part

set currvnum %object.vnum%

* We want to find which item it is, so we loop through all items (in item1 to item 6)
set traded_item 0
set i 1

while %i% <= %max_items%
  * look at first itemvec
  * Need to eval this!
  eval item_to_check %%item%i%%%
 
  set j 1
 
  while %j% != 0
    extract curr_item %j% %item_to_check%
    if !%curr_item%
      * Loop will stop
      set j 0
    else
      if %curr_item% == %currvnum%
        set traded_item %i%
        break
      endif
      eval j %j% + 1
    endif
  done
  if %traded_item% != 0
    eval i %max_items% + 1
  endif
  eval i %i% + 1
done

* This will create a variable traded_item which will tell you what item it is
* For example, if traded_item is 4, then the player gave sapphires
* If the traded_item was 0, means it was none of the 6 possible items

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%%%

  say %tosaypartone%
  say %tosayparttwo%
  wait 1
  * Reward goes here, corresponding to the traded_item
  set tp_reward %tp_reward_vec.wordat(%traded_item%)%
  nop %actor.trade(%tp_reward%)%
  eval d %actor.level%*%exp_reward_vec.wordat(%traded_item%)%
  nop %actor.exp(%d%)%
 
  * Halt this script if we have successfully traded! 
  halt
endif

* If traded_item is zero,  then it's a rejected item
return 0
wait 1
emote makes a refusing gesture.

* Check if it was either fool's gold or iron pyrite, same loop as above
set rej_traded_item 0
set i 1

while %i% <= %rej_max_items%
  * look at first itemvec
  * Need to eval this!
  eval item_to_check %%rej_item%i%%%
  set j 1 
  while %j% != 0
    extract curr_item %j% %item_to_check%
    if !%curr_item%
      * Loop will stop
      set j 0
    else
      if %curr_item% == %currvnum%
        set rej_traded_item %i%
        break
      endif
      eval j %j% + 1
    endif
  done
  if %rej_traded_item% != 0
    eval i %rej_max_items% + 1
  endif
  eval i %i% + 1
done

* same thing

if %rej_traded_item% != 0 
  eval tosay %%rej_speech%rej_traded_item%%%
  say %tosay%
  halt
else
  say This is a generic statement saying I don't like your item.
endif

--- End code ---

What are the benefits of this script?

1. You can trade LOTS of different items. So if we traded 50 items, writing the code the long way might mean duplicating 50*5 = 250 lines of code.

With this script, we save on 250 lines of code (there is extra code because of the loop, but that has a constant number of lines whether you trade 5 items or 500 items).

2. You don't need lots of ifchecks like

--- Code: ---if %object.vnum% == 1000 || %object.vnum% == 1001 || %object.vnum == 1002

--- End code ---
for every item. For example, did you notice in the code above, I left out a % in %object.vnum == 1002? Hard to spot such errors! However, with the above script, all a builder needs to do is to edit the first few lines. Fewer chances of mistakes.

Yay!

erwin:
Also, you can create two functions for the traded_item loop, and the rejected_item loop.

Then, for all traders in the MUD, just call these two functions whenever you trade something, so in the future, code might just look like


--- Code: ---set item1 111 112 113 114 120
set speecha1 thank you for the diamonds
set speechb1 blah blah love you

set item2 200 201 214 206
set speecha2 thank you for the rubies
set speechb2 blah blah love you

set item3 300 301 333 399
set speecha3 thank you for the garnets
set speechb3 blah blah love you

set item4 400 420 490
set speecha4 thank you for the sapphires
set speechb4 blah blah love you

set item5 500
set speecha5 thank you for the quartz
set speechb5 blah blah love you

set item6 666 669
set speecha6 thank you for the topaz
set speechb6 blah blah love you

set max_items 6

set tp_reward_vec 1 4 3 2 4 9
set exp_reward_vec 1000 3000 1000 1000 4000 4000

set rej_item1 1000 1005 1110
set rej_speech1 I don't want fool's gold.

set rej_item2 2000 2222
set rej_speech2 I don't want iron pyrite.

set rej_max_items 2

set currvnum %object.vnum%

* Loop for traded_item function
function 122

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%%%

  say %tosaypartone%
  say %tosayparttwo%
  wait 1
  * Reward goes here, corresponding to the traded_item
  set tp_reward %tp_reward_vec.wordat(%traded_item%)%
  nop %actor.trade(%tp_reward%)%
  eval d %actor.level%*%exp_reward_vec.wordat(%traded_item%)%
  nop %actor.exp(%d%)%
 
  * Halt this script if we have successfully traded! 
  halt
endif

* If traded_item is zero,  then it's a rejected item
return 0
wait 1
emote makes a refusing gesture.

* Loop for rejected items
function 125

if %rej_traded_item% != 0 
  eval tosay %%rej_speech%rej_traded_item%%%
  say %tosay%
  halt
else
  say This is a generic statement saying I don't like your item.
endif

--- End code ---

erwin:
One last post to explain what the first loop does. If it's complicated, pretend it's a DG function like .contains or replace_word (which are simple - but the code behind them is not so simple).

Think of this loop as a DG function which takes into input all your item#. In the first post, we had item1, item2, ... , item6.

Then, it outputs the number where the vnum occurs, and 0 otherwise.

So, think of this as a "black box". If we had


--- Code: ---set item1 111 112 113 114 120

set item2 200 201 214 206

set item3 300 301 333 399

set item4 400 420 490

set item5 500

set item6 666 669

--- End code ---

Then if the object vnum was 400, our loop would return the number 4 (because 400 was in item4).

If the object vnum was 206, our loop would return the number 2 (because 206 was in item2).

If the object vnum was 10000, our loop would return the number 0 (because 10000 is not in any of the items).

Returning the number is useful, because we can use this number to check for rewards.

We had (for example)

--- Code: ---set speecha1 thank you for the diamonds
set speechb1 blah blah love you
set tp_reward_vec 1 4 3 2 4 9
set exp_reward_vec 1000 3000 1000 1000 4000 4000

--- End code ---

Think of the number that the loop returns (or black box) helpful, by identifying what speech to give. Eg, if we had the number 4, then we will give speecha4 and speechb4, the value of the TP in the 4th number (2), and the value of the XP in the 4th number (1000).

So this portion

--- Code: ---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%%%

  say %tosaypartone%
  say %tosayparttwo%
  wait 1
  * Reward goes here, corresponding to the traded_item
  set tp_reward %tp_reward_vec.wordat(%traded_item%)%
  nop %actor.trade(%tp_reward%)%
  eval d %actor.level%*%exp_reward_vec.wordat(%traded_item%)%
  nop %actor.exp(%d%)%
 
  * Halt this script if we have successfully traded! 
  halt
endif

--- End code ---

if you read it line by line, it just checks for the number (in %traded_item%), finds the correct speech to give with

--- Code: ---  eval tosaypartone %%speecha%traded_item%%%
  eval tosayparttwo %%speechb%traded_item%%%

--- End code ---

and gives the right TP reward and XP reward in

--- Code: ---  set tp_reward %tp_reward_vec.wordat(%traded_item%)%
  nop %actor.trade(%tp_reward%)%
  eval d %actor.level%*%exp_reward_vec.wordat(%traded_item%)%
  nop %actor.exp(%d%)%

--- End code ---

If you have problems reading this code, here's another way to look at this.

We have the reward code as

--- Code: ---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%%%

  say %tosaypartone%
  say %tosayparttwo%
  wait 1
  * Reward goes here, corresponding to the traded_item
  set tp_reward %tp_reward_vec.wordat(%traded_item%)%
  nop %actor.trade(%tp_reward%)%
  eval d %actor.level%*%exp_reward_vec.wordat(%traded_item%)%
  nop %actor.exp(%d%)%
 
  * Halt this script if we have successfully traded! 
  halt
endif

--- End code ---

There's lots of variables, so let's pretend that we gave object vnum 206. Running the "black box" loop, we have %traded_item% to be 2, because we had

--- Code: ---set item2 200 201 214 206

--- End code ---
and 206 is inside.

Let's replace %traded_item% in the code by 2 (the value of %traded_item%)

--- Code: ---if 2 != 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 %%speecha2%%
  eval tosayparttwo %%speechb2%%

  say %tosaypartone%
  say %tosayparttwo%
  wait 1
  * Reward goes here, corresponding to the traded_item
  set tp_reward %tp_reward_vec.wordat(2)%
  nop %actor.trade(%tp_reward%)%
  eval d %actor.level%*%exp_reward_vec.wordat(2)%
  nop %actor.exp(%d%)%
 
  * Halt this script if we have successfully traded! 
  halt
endif

--- End code ---

Okay, we still have more variables now like %%speecha2%%, %%speechb2%%, and %tp_reward_vec.wordat(2)%, etc, but it should be easier to see. If not, we'll go through the code one more time and replace these variables by what we've defined.


--- Code: ---if 2 != 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 thank you for the rubies
  eval tosayparttwo blah blah love you

  say %tosaypartone%
  say %tosayparttwo%
  wait 1
  * Reward goes here, corresponding to the traded_item
  * because 4 was the word at 2 for the tp_reward_vec
  set tp_reward 4
  nop %actor.trade(%tp_reward%)%
  * because 3000 was the word at 2 for the exp_reward_vec
  eval d %actor.level%*3000
  nop %actor.exp(%d%)%
 
  * Halt this script if we have successfully traded! 
  halt
endif

--- End code ---

And that's it :)








------------

This is the loop to find the value of %traded_item% for further info. If it bothers you, pretend it's a DG function that gives you what you want :)


--- Code: ---while %i% <= %max_items%
  * look at first itemvec
  * Need to eval this!
  eval item_to_check %%item%i%%%
 
  set j 1
 
  while %j% != 0
    extract curr_item %j% %item_to_check%
    if !%curr_item%
      * Loop will stop
      set j 0
    else
      if %curr_item% == %currvnum%
        set traded_item %i%
        break
      endif
      eval j %j% + 1
    endif
  done
  if %traded_item% != 0
    eval i %max_items% + 1
  endif
  eval i %i% + 1
done

--- End code ---

I'm reluctant to say: "Use this code even if you don't understand it", because that's where lots of errors can occur. But in that case, we also shouldn't use cool DG commands like

--- Code: ---.contains
.wordat()
.strlen
replace_word

--- End code ---
etc, because we don't know how to "script" the equivalent in DG. But we still use them anyway. For example, replace_word as a DG function is easy to understand

--- Code: ---set sentence This is a dog and it is barking
replace_word boy 4 %sentence%

--- End code ---
will give This is a boy and it is barking. But not many of us will be able to script the equivalent in DG.

--- Code: ---set sentence This is a dog and it is barking
* want to replace boy in word 4
set word_to_replace boy
set num_at_replace 4

* After setting sentence, word_to_replace, num_at_replace, then:

* Find the maximum length of this sentence
set len 0
while %len%
  eval len %len% + 1
  extract tmp %len% %sentence%
  if !%tmp%
    break
  endif
done
eval len %len% - 1

*len is now the length of the sentence (ie number of words)


extract newsentence 1 %sentence%
set i 2
while %i% < %num_at_replace%
  extract nextword %i% %sentence%
  set newsentence %newsentence% %nextword%
  eval i %i% + 1
done

set newsentence %newsentence% %word_to_replace%
eval i %i% + 1
while %i% <= %len%
  extract nextword %i% %sentence%
  set newsentence %newsentence% %nextword%
  eval i %i% + 1
done

--- End code ---

However, hold on! This code won't work if we wanted to replace the first word. So the actual code would be something like

--- Code: ---set sentence This is a dog and it is barking
* want to replace that in word 1
set word_to_replace that
set num_at_replace 1

* After setting sentence, word_to_replace, num_at_replace, then:

* Find the maximum length of this sentence
set len 0
while %len%
  eval len %len% + 1
  extract tmp %len% %sentence%
  if !%tmp%
    break
  endif
done
eval len %len% - 1

*len is now the length of the sentence (ie number of words)

if %num_at_replace% == 1
  set newsentence %word_to_replace%
  set i 2
else
  extract newsentence 1 %sentence%
  set i 2
  while %i% < %num_at_replace%
    extract nextword %i% %sentence%
    set newsentence %newsentence% %nextword%
  eval i %i% + 1
  done
  set newsentence %newsentence% %word_to_replace%
  eval i %i% + 1
endif

while %i% <= %len%
  extract nextword %i% %sentence%
  set newsentence %newsentence% %nextword%
  eval i %i% + 1
done

--- End code ---

It's a pain to read, especially without comments. Most builders probably don't understand what that does, and wouldn't dare to use it, but they would use

--- Code: ---replace_word

--- End code ---

even though it does the same thing.

So maybe you have a question: If we can put that terrible looking loop in the form of

--- Code: ---replace_word

--- End code ---

then why can't we do the same for

--- Code: ---while %i% <= %max_items%
  * look at first itemvec
  * Need to eval this!
  eval item_to_check %%item%i%%%
 
  set j 1
 
  while %j% != 0
    extract curr_item %j% %item_to_check%
    if !%curr_item%
      * Loop will stop
      set j 0
    else
      if %curr_item% == %currvnum%
        set traded_item %i%
        break
      endif
      eval j %j% + 1
    endif
  done
  if %traded_item% != 0
    eval i %max_items% + 1
  endif
  eval i %i% + 1
done

--- End code ---
?

Well, let's see how replace_word works. The syntax is

--- Code: ---replace_word blah 4 sentence

--- End code ---
And you can read this as: "We are going to replace the 4th word of sentence by the word blah"

But, what the "black box" loop does is: Given any number of possible traded items (could be 6, could 10, could 2), the loop will return the item number. How would such an input look like if we had such a function? Eg if we wanted to check if vnum 12345 was in item1 to item3, then..

--- Code: ---blackboxloop 12345 item1 item2 item3

--- End code ---
?

But if we had 10 items, then

--- Code: ---blackboxloop 12345 item1 item2 item3 item4 item5 item6 item7 item8 item9 item10

--- End code ---
?

What if the builder transposed two numbers, eg

--- Code: ---blackboxloop 12345 item2 item1 item3

--- End code ---
, would it still return the right number? So maybe it's better if the loop was in DG instead of a function...

erwin:
Also, note that

--- Code: ---set speecha1 thank you for the diamonds
set speechb1 blah blah love you

--- End code ---

etc is optional. If the mob does a generic thank you, you might as well have

--- Code: ---if %traded_item% != 0
  *Great, no rejected items. Now to find which one
  wait 1
  mjunk %object%
  say thank you!
  wait 1
  * Reward goes here, corresponding to the traded_item
  set tp_reward %tp_reward_vec.wordat(%traded_item%)%
  nop %actor.trade(%tp_reward%)%
  eval d %actor.level%*%exp_reward_vec.wordat(%traded_item%)%
  nop %actor.exp(%d%)%
 
  * Halt this script if we have successfully traded! 
  halt
endif

--- End code ---

Similarly, if you have fewer / more speeches to give, you could have

--- Code: ---set speecha1 thank you for the diamonds
set speechb1 blah blah love you
set speechc1 laa

--- End code ---
if you wanted the mob to say three lines, for example.

You might then say: "What if for one item, I want the mob to do something different?" Well, then you can have

--- Code: ---if %traded_item% != 0
  *Great, no rejected items. Now to find which one
  wait 1
  mjunk %object%
  say thank you!
  wait 1
  * Reward goes here, corresponding to the traded_item
  set tp_reward %tp_reward_vec.wordat(%traded_item%)%
  nop %actor.trade(%tp_reward%)%
  eval d %actor.level%*%exp_reward_vec.wordat(%traded_item%)%
  nop %actor.exp(%d%)%
 
  if %traded_item% == 4
    %echo% This is a special item! Do special stuff here
  endif
 
  * Halt this script if we have successfully traded! 
  halt
endif

--- End code ---

erwin:
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.

--- Code: ---
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

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version