PiXLCAT Posted July 26, 2012 Posted July 26, 2012 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. Quote
Euphy Posted July 26, 2012 Posted July 26, 2012 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]; Quote
PiXLCAT Posted July 27, 2012 Author Posted July 27, 2012 (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 July 27, 2012 by PiXLCAT Quote
Euphy Posted July 27, 2012 Posted July 27, 2012 Since <ID>,<Amount> will always start on an even number, you want to restrict rand() so that you'll always get a predictable result. Quote
PiXLCAT Posted July 27, 2012 Author Posted July 27, 2012 I... don't think I understand. ^^; Sorry, I'm a bit slow at times. Quote
Question
PiXLCAT
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.
This script obviously does not work.
Thank you for helping and sharing the knowledge with me.
4 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.