Jump to content
  • 0

Random Treasure chest drops problem.


Question

Posted

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.

4 answers to this question

Recommended Posts

Posted

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];

Posted (edited)

@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

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...