Advertisement
Skorm

Get random items based on chance.

Apr 20th, 2019
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.73 KB | None | 0 0
  1. // The chance of getting any item in this list is that items chance out of '.chance'...
  2. -    script    World_Drops    -1,{
  3.     end;
  4. OnNPCKillEvent:
  5.     .@rnd = rand(.chance);
  6.     if( getmonsterinfo( killedrid,1 ) ) {
  7.         for( .@i = 0; .@i < getarraysize(.items); .@i+=3 ) {
  8.             if( .@rnd < .items[.@i+2] ) {
  9.                 getitem .items[.@i], .items[.@i+1];
  10.  
  11.                 .@remainder$ = .items[.@i+2] % 10000;
  12.                 .@division = (.items[.@i+2] * 100) / .chance;
  13.  
  14.                 while ( getstrlen(.@remainder$) < 4 )
  15.                     .@remainder$ = insertchar(.@remainder$, "0", 0);
  16.  
  17.                 while ( charat(.@remainder$,getstrlen(.@remainder$)) == "0" && getstrlen(.@remainder$) > 2 )
  18.                     delchar(.@remainder$,getstrlen(.@remainder$));
  19.  
  20.                 .@display_chance$ = .@division +"."+ .@remainder$;
  21.                 dispbottom2 "Congratulations! Player "+ strcharinfo(0) +" has obtained "+ getitemname( .items[.@i] ) +" ["+ .items[.@i+1] +"] from "+ getmonsterinfo(killedrid, 0) +" (chance: "+.@display_chance$+"%).",0xFFFFFF;
  22.             }
  23.         }
  24.     }
  25.     end;
  26.  
  27.    
  28. OnInit:
  29.     .chance = 1000000;
  30.     setarray .items[0],
  31.         501,    1,    400,    //0.04%
  32.         501,    1,    100,    //0.01%
  33.         501,    1,    100,    //0.01%
  34.         501,    1,    100,    //0.01%
  35.         501,    1,    100,    //0.01%
  36.         501,    1,    500,    //0.05%
  37.         501,    1,    500,    //0.05%
  38.         501,    1,    500,    //0.05%
  39.         501,    1,    1,        //0.0001%
  40.         501,    1,    1,        //0.0001%
  41.         501,    1,    1,        //0.0001%
  42.         501,    1,    1,        //0.0001%
  43.         501,    1,    1        //0.0001%
  44.         ;
  45.     end;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement