nuna 2 Posted May 15, 2017 Hello may i request for some script like for example npc to claim item but in random chance. list of items,qty / Chance 607,5 50% 608,6 52% 678,4 50% 672,1 2% something like that. Thank you in advance Quote Share this post Link to post Share on other sites
0 meko 170 Posted May 15, 2017 (edited) here, I made this for you: <map>,<x>,<y>,<dir> script <name> <sprite>,{ mes("Hi there."); mes("Can I help you?"); next(); select("claim reward"); mes("..."); next(); for (.@i = 0; .@i < .reward_len; .@i += 3) { if (rand(100) < .reward[.@i + 2]) { getitem(.reward[.@i], .reward[.@i + 1]); mesf("You obtained %i %s.", .reward[.@i + 1], getitemname(.reward[.@i])); .@reward = true; // got at least one reward next(); } } if (.@reward != true) { mes("It seems you're out of luck."); next(); } mes("Come back anytime!"); close; OnInit: setarray(.reward[0], //ID,QTY,% 607, 5, 50, 608, 6, 52, 678, 4, 50, 672, 1, 2); .reward_len = getarraysize(.reward); } hope it helps UPDATE: added reward_len (sorry, forgot that) Edited May 15, 2017 by meko 1 tedexx reacted to this Quote Share this post Link to post Share on other sites
0 nuna 2 Posted May 18, 2017 here, I made this for you: <map>,<x>,<y>,<dir> script <name> <sprite>,{ mes("Hi there."); mes("Can I help you?"); next(); select("claim reward"); mes("..."); next(); for (.@i = 0; .@i < .reward_len; .@i += 3) { if (rand(100) < .reward[.@i + 2]) { getitem(.reward[.@i], .reward[.@i + 1]); mesf("You obtained %i %s.", .reward[.@i + 1], getitemname(.reward[.@i])); .@reward = true; // got at least one reward next(); } } if (.@reward != true) { mes("It seems you're out of luck."); next(); } mes("Come back anytime!"); close; OnInit: setarray(.reward[0], //ID,QTY,% 607, 5, 50, 608, 6, 52, 678, 4, 50, 672, 1, 2); .reward_len = getarraysize(.reward); } hope it helps UPDATE: added reward_len (sorry, forgot that) Hello sir thank you but how can i make it only 1 can get? Quote Share this post Link to post Share on other sites
0 meko 170 Posted May 19, 2017 You want the player to get only one item? Your percents make a total of 154% ... list of items,qty / Chance 607,5 50% 608,6 52% 678,4 50% 672,1 2% Try this: .@rnd = rand(154); if (.@rnd < 50) { getitem(607, 5); } else if (.@rnd < 102) { getitem(608, 6); } else if (.@rnd < 152) { getitem(678, 4); } else { getitem(672, 1); } Quote Share this post Link to post Share on other sites
0 nuna 2 Posted May 19, 2017 You want the player to get only one item? Your percents make a total of 154% ... list of items,qty / Chance 607,5 50% 608,6 52% 678,4 50% 672,1 2% Try this: .@rnd = rand(154); if (.@rnd < 50) { getitem(607, 5); } else if (.@rnd < 102) { getitem(608, 6); } else if (.@rnd < 152) { getitem(678, 4); } else { getitem(672, 1); } Yes i only want player to get any 1 items of the list with chance sir thanks a lot Quote Share this post Link to post Share on other sites
0 meko 170 Posted May 19, 2017 well I assumed it was more than one because your percentage exceeds 100%, which implies you want to give 1~2 (154% ➜ 1.54) items Quote Share this post Link to post Share on other sites
Hello may i request for some script like
for example
npc to claim item but in random chance.
list of items,qty / Chance
607,5 50%
608,6 52%
678,4 50%
672,1 2%
something like that.
Thank you in advance
Share this post
Link to post
Share on other sites