Jump to content
  • 0

Random get item with percentage


kevinyrchua

Question


  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  07/14/17
  • Last Seen:  

Hi!

I want to create a box or egg that gives 1 item from a 10 item pool with adjustable percentage chance.
 

This is the closest script that I've found from the forum, script is commented back in 2014.

switch(rand(0,3)){ // 4 choices: no bonus, Mask, Glove, Belt
	case 1:if(rand(0,100) < 15) getitem 5482,1; break; // player will get Dark Knight Mask. but, 15% chance (random, 0~99. if number is < 15, get)
	case 2:if(rand(0,100) < 5) getitem 2780,1; break; // player will get Dark Knight Glove. but, 5% chance (random, 0~99. if number is < 5, get)
	case 3:if(rand(0,100) < 5) getitem 2780,1; break;  // player will get Dark Knight Belt. but, 5% chance (random, 0~99. if number is < 5, get)
	default: end;} // player did not get any bonus

Just wondering if there is an easier script to work with or?

Example chance structure (thinking if it needs to be a total of 100%)
item1           - 1%
item2           - 4%
item3           - 5%
item4           - 10%
item5           - 10%
item6           - 10%
item7           - 15%
item8           - 15%
item9           - 15%
item10         - 15%

Edited by kevinyrchua
Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  15
  • Topics Per Day:  0.01
  • Content Count:  81
  • Reputation:   17
  • Joined:  07/18/16
  • Last Seen:  

I recommend you to use this function

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  07/14/17
  • Last Seen:  

2 hours ago, kodkodkub said:

I recommend you to use this function

Checking this, seems like it doesn't support percentage chance? just an equal chance for all items is that right?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  15
  • Topics Per Day:  0.01
  • Content Count:  81
  • Reputation:   17
  • Joined:  07/18/16
  • Last Seen:  

No, weight is working like %
more weight = more chance

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  61
  • Topics Per Day:  0.02
  • Content Count:  911
  • Reputation:   166
  • Joined:  11/27/14
  • Last Seen:  

Is this what you mean ?
 

	//<Chance><ItemID><Item Amount>
	setarray .@P1[0],0,8012,1;
	setarray .@P2[0],1,8011,1;
	setarray .@P3[0],5,8006,1;
	setarray .@P4[0],20,8010,1;
	setarray .@P5[0],90,13517,5;
	setarray .@P6[0],80,12080,10;
	setarray .@P7[0],90,30110,5;
	setarray .@P8[0],80,12075,10;
	setarray .@Default[0],30095,5;



Here

Quote

 

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  07/14/17
  • Last Seen:  

53 minutes ago, Poring King said:

Is this what you mean ?
 


	//<Chance><ItemID><Item Amount>
	setarray .@P1[0],0,8012,1;
	setarray .@P2[0],1,8011,1;
	setarray .@P3[0],5,8006,1;
	setarray .@P4[0],20,8010,1;
	setarray .@P5[0],90,13517,5;
	setarray .@P6[0],80,12080,10;
	setarray .@P7[0],90,30110,5;
	setarray .@P8[0],80,12075,10;
	setarray .@Default[0],30095,5;



Here

 

Ahh, maybe similar but what im thinking is a script or function "maybe" for a box or a scroll or an egg. it's like obb, but controlled percentage of getting specific item.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  61
  • Topics Per Day:  0.02
  • Content Count:  911
  • Reputation:   166
  • Joined:  11/27/14
  • Last Seen:  

// db/pre/item_bluebox.txt
// Old Blue Box Obtainable Items Database
//
// Structure of Database:
// GroupID,ItemID,Rate
MYCustomBox,Item1,100; = 100%
MYCustomBox,Item2,10; = 10%
MYCustomBox,Item3,1; = 1%

item script for item_db
{ getrandgroupitem(MYCustomBox),1; }

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.01
  • Content Count:  52
  • Reputation:   0
  • Joined:  07/14/17
  • Last Seen:  

On 7/24/2020 at 10:39 AM, kodkodkub said:

No, weight is working like %
more weight = more chance

is this like if I need to make if 1% chance out of 100 items, I need to list down 100 to make it a real 1% chance? I read his comment on the link you provided he said, weight over total weight and on his example is 1/4, so I need to list down 100 items to make it 1/100, is that right?

also can we add an announce function here for the 5% chance and below items? shout name of person and what he got?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  68
  • Reputation:   8
  • Joined:  05/12/20
  • Last Seen:  


setarray .@item,5482,2780;
setarray .@chance,20,10;

set .@rd, rand(0,getarraysize(.@item));
if (.@rd){
  if (rand(99) < .@chance[@rd])
    getitem(.@item[.@rd);
} else {
   // player did not get any bonus
}

I have not tested. But maybe something like this...

Edited by buraquera
Link to comment
Share on other sites

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.

×
×
  • Create New...