Jump to content
  • 0

Need help on scripting with chances


Question

Posted

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!

2 answers to this question

Recommended Posts

Posted

.@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 ;)

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...