Jump to content
  • 0
Sign in to follow this  
Wolfeh

Rand item with setarray amount

Question

I'm trying to make a random reward that keeps the amount in the amount array. I've tried several variations/methods and this is the closest I have gotten:

 

    setarray .Prize[1],604,12129,617,12208,12103,12414;
    setarray .Prize[2],25,5,5,1,1,1;

 

getitem .Prize[rand(getarraysize(.Prize))],.Prize[2];

 

This actually doesn't work, .Prize[1] in place of the rand command works, only getting the first values in each array, but as soon as I put the rand in there it won't get the .Prize[1] array. It says in map-server:

 

[Error]: buildin_getitem: Nonexistant item 5 requested.
[Debug]: Source (NPC): Disguise Event at quiz_02 (303,259)

 

Item 5 being from .Prize[2], it just skips .Prize[1].

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Start the arrays at [0] not [1] or [2]

It look like you want one array for items, and another one for amount? Your problem is, reading out the array size while you actually want its values.

And yes, you Basically give a random item out of a random array. May take a look here:

http://herc.ws/board/topic/14354-how-to-use-string-as-a-value-in-script/

Share this post


Link to post
Share on other sites
  • 0

Thank you!! Took me a bit of fiddling but I was able to work it out thanks to your informative post. End solution:

 

In script:

    .@r = rand(5);
    getitem(.Prize[.@r]), .PrizeAmt[.@r];

 

At the end of script:

OnInit:
    setarray(.Prize[0], Branch_Of_Dead_Tree, Fantastic_Cooking_Kits, Old_Violet_Box, Battle_Manual, Bloody_Dead_Branch, Guarana_Candy);
    setarray(.PrizeAmt[0],25,5,5,1,1,1);

Edited by Wolfeh

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.