Jump to content
  • 0

Random Box with absolute item chance rate


Eross

Question


  • Group:  Members
  • Topic Count:  155
  • Topics Per Day:  0.11
  • Content Count:  349
  • Reputation:   12
  • Joined:  04/05/20
  • Last Seen:  

Hi ! Is it possible to make my random box have a chance of lower than 1% ? like .5% chance to get a certain jackpot item ? ..

I have this script I dont remember who gave this to me .. 


 

    setarray .i1[0],19824,40227,40239; // 1st Prize 5%
    set .i1random,rand(0,2); // Randomize Common Items; just change max amount if you add items
    set .chance, rand(100);

	if (.chance >= 1 && .chance <= 5){
		getitem .i1[.i1random],1;
		announce "[Lucky Draw Machine]: ["+strcharinfo(0)+"] obtained 1x ["+getitemname(.i1[.i1random])+"] (5%).",0;
		announce "[Lucky Draw Machine]: Try your luck and Win Special Prizes.",0;
		specialeffect2 699;
		end;

As you can see this script gives you a chance of 1 to 5%  .. How can I make it a chance of lower than 1% ? thanks

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  50
  • Reputation:   39
  • Joined:  01/13/12
  • Last Seen:  

46 minutes ago, erjsanmiguel said:

Hi ! Is it possible to make my random box have a chance of lower than 1% ? like .5% chance to get a certain jackpot item ? ..

I have this script I dont remember who gave this to me .. 


 


    setarray .i1[0],19824,40227,40239; // 1st Prize 5%
    set .i1random,rand(0,2); // Randomize Common Items; just change max amount if you add items
    set .chance, rand(100);

	if (.chance >= 1 && .chance <= 5){
		getitem .i1[.i1random],1;
		announce "[Lucky Draw Machine]: ["+strcharinfo(0)+"] obtained 1x ["+getitemname(.i1[.i1random])+"] (5%).",0;
		announce "[Lucky Draw Machine]: Try your luck and Win Special Prizes.",0;
		specialeffect2 699;
		end;

As you can see this script gives you a chance of 1 to 5%  .. How can I make it a chance of lower than 1% ? thanks

Yes, just change the 'range of rand' and you got it.

Like this:

Spoiler

	setarray .i1[0],19824,40227,40239;	// 1st Prize 5%
	set .i1random,rand(0,2);	// Randomize Common Items; just change max amount if you add items
	// Rate (1 = 0.01%, 10 = 0.10%, 100 = 1.00%, 1000 = 10.00%, 10000 = 100.00%)
	set .chance, 500; // 500 = 5.00%

	if (rand(10000) < .chance)
	{
		getitem .i1[.i1random],1;
		announce "[Lucky Draw Machine]: ["+strcharinfo(0)+"] obtained 1x ["+getitemname(.i1[.i1random])+"] (5%).",0;
		announce "[Lucky Draw Machine]: Try your luck and Win Special Prizes.",0;
		specialeffect2 699;
		end;
	}

 

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  155
  • Topics Per Day:  0.11
  • Content Count:  349
  • Reputation:   12
  • Joined:  04/05/20
  • Last Seen:  

33 minutes ago, Cretino said:

Yes, just change the 'range of rand' and you got it.

Like this:

  Reveal hidden contents


	setarray .i1[0],19824,40227,40239;	// 1st Prize 5%
	set .i1random,rand(0,2);	// Randomize Common Items; just change max amount if you add items
	// Rate (1 = 0.01%, 10 = 0.10%, 100 = 1.00%, 1000 = 10.00%, 10000 = 100.00%)
	set .chance, 500; // 500 = 5.00%

	if (rand(10000) < .chance)
	{
		getitem .i1[.i1random],1;
		announce "[Lucky Draw Machine]: ["+strcharinfo(0)+"] obtained 1x ["+getitemname(.i1[.i1random])+"] (5%).",0;
		announce "[Lucky Draw Machine]: Try your luck and Win Special Prizes.",0;
		specialeffect2 699;
		end;
	}

 

 

Hi sir ! you mean from 

set .chance, rand(100);

to what ? sorry hehe ^_^

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  50
  • Topics Per Day:  0.01
  • Content Count:  1702
  • Reputation:   238
  • Joined:  09/05/12
  • Last Seen:  

You can only use integer values when creating scripts so you have to adjust your rand() to achieve 0.5% chance

if (rand(1000) < 5) means 0.5%

if (rand(1000) < 1) means 0.1%

if (rand(1000) < 10) means 1%

 

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  155
  • Topics Per Day:  0.11
  • Content Count:  349
  • Reputation:   12
  • Joined:  04/05/20
  • Last Seen:  

8 minutes ago, Patskie said:

You can only use integer values when creating scripts so you have to adjust your rand() to achieve 0.5% chance


if (rand(1000) < 5) means 0.5%

if (rand(1000) < 1) means 0.1%

if (rand(1000) < 10) means 1%

 

Okay sir thankyou sir @Patskie ^_^

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  50
  • Reputation:   39
  • Joined:  01/13/12
  • Last Seen:  

6 hours ago, erjsanmiguel said:

Hi sir ! you mean from 


set .chance, rand(100);

to what ? sorry hehe ^_^

Look the content in the spoiler in my first post here. There has a solution with an example how to use it...

You'll need change the range of rand from '100' to '10000'.

Rate (1 = 0.01%, 10 = 0.10%, 100 = 1.00%, 1000 = 10.00%, 10000 = 100.00%)

And change the 'if' from:

if (.chance >= 1 && .chance <= 5){

To:

if (rand(10000) < .chance){

And change the value of variable '.chance' to the rate you want:

From:

set .chance, rand(100);

To:

set .chance, 500; // 500 = 5.00%
Edited by Cretino
  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  155
  • Topics Per Day:  0.11
  • Content Count:  349
  • Reputation:   12
  • Joined:  04/05/20
  • Last Seen:  

1 hour ago, Cretino said:

Look the content in the spoiler in my first post here. There has a solution with an example how to use it...

You'll need change the range of rand from '100' to '10000'.


Rate (1 = 0.01%, 10 = 0.10%, 100 = 1.00%, 1000 = 10.00%, 10000 = 100.00%)

And change the 'if' from:


if (.chance >= 1 && .chance <= 5){

To:


if (rand(10000) < .chance){

And change the value of variable '.chance' to the rate you want:

From:


set .chance, rand(100);

To:


set .chance, 500; // 500 = 5.00%

I get it clearly sir thankyou for the explanation ..I learned a lot

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