Bisuke Posted November 12, 2014 Posted November 12, 2014 I'm currently coding my own mining system, I just want to ask on how to make an npc that gives a random loot with different chances? Example Stone 55% Iron Ore 35% Iron 25% Elunium 3% Oridecon 5% Gold 1% If i click my npc randomly it'll generate a drop that is based on the rates. My code is something like this set @chance,rand(1,200); if(@chance == 1) getitem 998,1; if(@chance == 2) getitem 998,1; if(@chance == 3) getitem 998,1; if(@chance == 4) getitem 998,1; if(@chance == 5) getitem 998,1; if(@chance == 6) getitem 998,1; if(@chance == 7) getitem 998,1; if(@chance == 8) getitem 998,1; I assigned items on every numbers which made my code very hard to modify. Can someone help me make the code more efficient and easy to modify, like adding new drops with new rates? Thanks! Quote
Stickhead Posted November 12, 2014 Posted November 12, 2014 .@i = rand(100); // = 100%if( .@i < 1 ) setarray .@Item[0],969,1;else if( .@i < 5 ) setarray .@Item[0],984,1;else if( .@i < 3 ) setarray .@Item[0],985,1;else if( .@i < 25 ) setarray .@Item[0],998,1; else if( .@i < 35 ) setarray .@Item[0],1002,1; else if( .@i < 55 ) setarray .@Item[0],7049,1; how to change the value of the reward? .@Item[0],7049,5; // Gives 5 Stones Credit to Emistry use search bar or google for better result next time Quote
Question
Bisuke
I'm currently coding my own mining system, I just want to ask on how to make an npc that gives a random loot with different chances?
Example
Stone 55%
Iron Ore 35%
Iron 25%
Elunium 3%
Oridecon 5%
Gold 1%
If i click my npc randomly it'll generate a drop that is based on the rates.
My code is something like this
I assigned items on every numbers which made my code very hard to modify.
Can someone help me make the code more efficient and easy to modify, like adding new drops with new rates?
Thanks!
2 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.