nuna 2 Posted October 11, 2017 hello how can i add announce on specific item if get and make it have amount value? function script boxrandom { setarray .@reward, 607, 60, 612, 10, 611, 10, 608, 10, 678, 5, 675, 5; set .@size, getarraysize( .@reward ); for( set .@i, 1; .@i < .@size; .@i += 2 ) { .@percent[.@i] = .@total + .@reward[.@i]; .@total += .@reward[.@i]; } .@r = rand( .@total +1 ); for( set .@i, 1; .@i < .@size; .@i += 2 ) if( .@percent[.@i] > .@r ) break; getitem .@reward[ .@i-1 ], 1; end; } how can i add also on what amount per item? example since 612 - id name and 10 is the chance. please help me to make it 612,1->amount,10->chance Example i want the id number 678 if get to be announce" char name got 1x Poison bottle " Quote Share this post Link to post Share on other sites
0 meko 170 Posted October 11, 2017 Try this: function script loot_crate { .@index = getarrayindex(getarg(0)); .@size = getarraysize(getarg(0)); for (.@i = .@index; .@i < .@size - .@index; .@i += 3) { for (.@e = 0; .@e < getelementofarray(getarg(0), .@i + 2); ++.@e) { .@loot[.@count++] = .@i; } } .@rand = .@loot[rand(.@count)]; getitem(getelementofarray(getarg(0), .@rand), getelementofarray(getarg(0), .@rand + 1)); announce(sprintf("Player %s obtained %ix %s from a loot crate!" strcharinfo(PC_NAME), getelementofarray(getarg(0), .@rand + 1), getitemname(getelementofarray(getarg(0), .@rand))), getarg(1, bc_all)); return true; } And in your NPC do something like this: MAP,X,Y,DIR script NAME SPRITE,{ mes("Hello"); next(); loot_crate(.rewards, bc_all); mes("Goodbye!"); close; OnInit: setarray(.rewards, // Item, Amount, Chance Yggdrasilberry, 1, 60, Portable_Furnace, 1, 10, Spectacles, 1, 10, Seed_Of_Yggdrasil, 1, 10, Poison_Bottle, 1, 5, Silver_Coin, 1, 5); } Quote Share this post Link to post Share on other sites
0 meko 170 Posted October 11, 2017 @nuna see also item_packages.conf Quote Share this post Link to post Share on other sites
hello how can i add announce on specific item if get and make it have amount value?
function script boxrandom { setarray .@reward, 607, 60, 612, 10, 611, 10, 608, 10, 678, 5, 675, 5; set .@size, getarraysize( .@reward ); for( set .@i, 1; .@i < .@size; .@i += 2 ) { .@percent[.@i] = .@total + .@reward[.@i]; .@total += .@reward[.@i]; } .@r = rand( .@total +1 ); for( set .@i, 1; .@i < .@size; .@i += 2 ) if( .@percent[.@i] > .@r ) break; getitem .@reward[ .@i-1 ], 1; end; }
how can i add also on what amount per item? example since 612 - id name and 10 is the chance. please help me to make it 612,1->amount,10->chance
Example i want the id number 678 if get to be announce" char name got 1x Poison bottle "
Share this post
Link to post
Share on other sites