Jump to content
  • 0

Random Treasure chest drops problem.


PiXLCAT

Question


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  13
  • Reputation:   0
  • Joined:  07/21/12
  • Last Seen:  

This is the last problem to my script project.

I am trying for a treasure chest to drop random drops but here is my problem.

I want them to drop a random Gold Coin (1,2,3) number or a random item such as an apple, carrot, banana, etc.

I have a script right now but it doesn't seem to work well and I am not sure how to proceed anymore to get what I want.

set .@r[0], 671; //Gold Coins
setarray .@a, 0,1,2,3; //Amount(Random)
getitem .@r[0], .@a[rand(getarraysize(.@a))];

set .@r[1], 512; //Apple
getitem .@r[1], 1;

set .@r[2], 513; //Banana
getitem .@r[2], 1;

set .@r[3], 514; //Grape
getitem .@r[3], 1;

set .@r[4], 515; //Carrot
getitem .@r[4], 1;

This script obviously does not work.

Thank you for helping and sharing the knowledge with me.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

It's easiest not to split two separate scenarios (random gold coin or constant fruit). Rather, group them into a single array:

// Format: <ID>,<Amount>,{...}
setarray .@i[0],671,1,671,2,671,3,512,1,513,1,514,1,515,1;
set .@j, rand(getarraysize(.@i)/2);
getitem .@i[2*.@j], .@i[2*.@j+1];

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  13
  • Reputation:   0
  • Joined:  07/21/12
  • Last Seen:  

@Euphy

I'm still in a learning phase when it comes to arrays and this is very useful information. Thank you so much, your code taught me something valuable today. I will go try it out!

Although I wonder:

rand(getarraysize(.@i)/2)

What is the /2 for?

Edited by PiXLCAT
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

Since <ID>,<Amount> will always start on an even number, you want to restrict rand() so that you'll always get a predictable result.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  13
  • Reputation:   0
  • Joined:  07/21/12
  • Last Seen:  

I... don't think I understand. ^^;

Sorry, I'm a bit slow at times.

Link to comment
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.   Paste as plain text instead

  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.

×
×
  • Create New...