Jump to content
  • 0

Help with my script.


Mabuhay

Question


  • Group:  Members
  • Topic Count:  105
  • Topics Per Day:  0.02
  • Content Count:  446
  • Reputation:   229
  • Joined:  03/20/12
  • Last Seen:  

function script randbox {
mes "Do you really want to open one(1) Lottery Box?";
mes "^FF0000NOTE: Dont press cancel(beside OK) or the box will be gone.^000000";
mes "No refund will be given if you do so.";
//next;
switch(select("Yes Please:No! Not yet!")) {
case 1:
set .@r, rand(100);
//if( .@r >= 0 && .@r < 2) { 
// switch( rand(1) ) {
// case 0: getitem 32025,1; break;
// }
//}
if( .@r >= 1 && .@r < 5 ) { 
switch( rand(1,6) ) {
case 1: getitem 32008,1; break;
case 2: getitem 32009,1; break;
case 3: getitem 32010,1; break;
case 4: getitem 32011,1; break;
case 5: getitem 32012,1; break;
case 6: getitem 32013,1; break;
}
}
if( .@r >= 6 && .@r < 10 ) { 
switch( rand(1,9) ) {
case 1: getitem 32025,1; break;
case 2: getitem 8400,2; break;
case 3: getitem 8403,2; break;
case 4: getitem 8402,6; break;
case 5: getitem 607,25; break;
case 6: getitem 8400,10; break;
case 7: getitem 8402,20; break;
case 8: getitem 8403,8; break; 
case 9: getitem 32025,3; break;
} 
}
if( .@r >= 11 && .@r < 20 ) { 
switch( rand(1,6) ) {
case 1: getitem 32007,1; break;
case 2: getitem 32006,1; break;
case 3: getitem 32005,1; break;
case 4: getitem 32004,1; break;
case 5: getitem 32003,1; break;
case 6: getitem 32002,1; break;
} 
}
if( .@r >= 21 && .@r < 35 ) { 
switch( rand(1,12) ) {
case 1: getitem 32021,60; break;
case 2: getitem 32022,60; break;
case 3: getitem 8404,rand(2,3); break;
case 4: getitem 32025,1; break;
case 5: getitem 6553,1; break;
case 6: getitem 6564,1; break;
case 7: getitem 6565,1; break;
case 8: getitem 6566,1; break;
case 9: getitem 8524,1; break;
case 10: getitem 8506,1; break;
case 11: getitem 8501,1; break;
case 12: getitem 608,35; break;
} 
}
if( .@r >= 36 && .@r < 47 ) { 
switch( rand(1,4) ) {
case 1: getitem 32023,40; break;
case 2: getitem 32024,40; break;
case 3: getitem 984,15; break;
case 4: getitem 985,15; break;
} 
}
if( .@r >= 48 && .@r < 60 ) { 
switch( rand(1,5) ) {
case 1: getitem 32001,1; break;
case 2: getitem 32000,1; break;
case 3: getitem 608,15; break;
case 4: getitem 607,10; break;
case 5: getitem 610,10; break;
}
}
if( .@r >= 61 && .@r < 79 ) { 
switch( rand(1,2) ) {
case 1: getitem 32023,20; break;
case 2: getitem 32024,20; break;
}
}
if( .@r >= 81 && .@r < 100 ) { 
switch( rand(1,2) ) {
case 1: getitem 32021,30; break;
case 2: getitem 32022,30; break;
}
}
emotion e_grat,1;
close;
case 2:
getitem 32020,1;
close;
}
//close;
}
My problem here is that sometimes, when the box is opened, no items will be given.

 

The goal of this script is to give items randomly with certain percentage. I was trying to conceptualize and make the script but this is all i can think of. If you have better version of this, please dont hesitate to edit this.

 

Waiting for reply. Thank you!

Edited by MrVandalBus
Link to comment
Share on other sites

6 answers to this question

Recommended Posts


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

 

My problem here is that sometimes, when the box is opened, no items will be given.

rand(100) throws a number between 0 and 99 and you don't give any item when it throws 0

here my view

function	script	randbox	{
	getitem 32020,1;
	mes "Do you really want to open one(1) Lottery Box?";
	mes "^FF0000NOTE: Dont press cancel(beside OK) or the box will be gone.^000000";
	mes "No refund will be given if you do so.";
	//next;
	if ( select("Yes Please:No! Not yet!") == 2 ) close;

	// setarray .@box1, "chance", item id, amount...
	setarray .@box1, 5, 32008,1, 32009,1, 32010,1, 32011,1, 32012,1, 32013,1;
	setarray .@box2, 10,32025,1,  8400,2,  8403,2,  8402,6,  607,25,  8400,10, 8402,20, 8403,8, 32025,3;
	setarray .@box3, 20,32007,1, 32006,1, 32005,1, 32004,1, 32003,1, 32002,1;
	// etc..

	delitem 32020,1;
	set .@r, rand(100);
	while( .@r >= getd( ".@box"+ .@i ) ) .@i++;
	.@rand_index = rand( ( getarraysize( getd( ".@box"+ .@i ) ) -1 )/2 ) *2 -1;
	getitem getd( ".@box"+ .@i +"["+ .@rand_index +"]" ), getd( ".@box"+ .@i +"["+ (.@rand_index +1) +"]" );
	emotion e_grat,1;
	close;
}
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  105
  • Topics Per Day:  0.02
  • Content Count:  446
  • Reputation:   229
  • Joined:  03/20/12
  • Last Seen:  

Thanks for your response Capuche!

 

I've tested it out and it seems to have some problems.

 

Here is how i modified it:

function	script	randbox	{
	getitem 32020,1;
	mes "Do you really want to open one(1) Lottery Box?";
	mes "^FF0000NOTE: Dont press cancel(beside OK) or the box will be gone.^000000";
	mes "No refund will be given if you do so.";
	//next;
	if ( select("Yes Please:No! Not yet!") == 2 ) close;

	// setarray .@box1, "chance", item id, amount...
	setarray .@box1, 5, 32008,1, 32009,1, 32010,1, 32011,1, 32012,1, 32013,1, 32025,3;
	setarray .@box2, 15,32021,60,  32022,60,  8403,8,  8402,20,  607,25,  8400,10;
	setarray .@box3, 20,32007,1, 32006,1, 32005,1, 32004,1, 32003,1, 32002,1, 608,35, 985,15, 8404,3;
	setarray .@box4, 25,32025,1, 6553,1, 6564,1, 6565,1, 6566,1, 8524,1, 8506,1, 8501,1;
	setarray .@box5, 30,32023,40, 32024,40, 610,10, 607,10, 984,15;
	setarray .@box6, 50,32001,1, 32000,1;
	setarray .@box7, 60,32023,20, 32024,20, 608,10, 32021,30, 32022,30;
	// etc..

	delitem 32020,1;
	set .@r, rand(100);
	while( .@r >= getd( ".@box"+ .@i ) ) .@i++;
	.@rand_index = rand( ( getarraysize( getd( ".@box"+ .@i ) ) -1 )/2 ) *2 -1;
	getitem getd( ".@box"+ .@i +"["+ .@rand_index +"]" ), getd( ".@box"+ .@i +"["+ (.@rand_index +1) +"]" );
	emotion e_grat,1;
	close;
}

Here is the problem:

 

I get stuck with that (in picture) some time then wont give item.

 

Screenshot2014-04-22065837_zpsfa86ae84.p

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

You get this infinity loop because I thought you would copy/past the chance of your previous script.. so I didn't make anything to prevent the loop.

The "chance" in the last box must be 100 (or more)

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  105
  • Topics Per Day:  0.02
  • Content Count:  446
  • Reputation:   229
  • Joined:  03/20/12
  • Last Seen:  

ohh sorry, i kinda didnt realize that. still learning on how to script though. thanks Capuche!

 

 

 

EDIT:

Now, having this error:

 

error_zps89b2aec1.png

 

Lol seriously sorry for being so noob.

Edited by MrVandalBus
Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

No it's my mistake. It should be

.@rand_index = rand( 1,( getarraysize( getd( ".@box"+ .@i ) ) -1 )/2 ) *2 -1;
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  105
  • Topics Per Day:  0.02
  • Content Count:  446
  • Reputation:   229
  • Joined:  03/20/12
  • Last Seen:  

finest! thanks

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