Jump to content
  • 0

Chance item random


Yasunari Ishibashi

Question


  • Group:  Members
  • Topic Count:  49
  • Topics Per Day:  0.01
  • Content Count:  157
  • Reputation:   2
  • Joined:  01/06/12
  • Last Seen:  

example script :

function script CustomBoxUpper { setarray .BoxItems[0],25194,25195,25197,25199,25202,25203,25205; set .Random, rand( getarraysize( .BoxItems ) ); getitem .BoxItems[ .Random ], 1; announce "["+strcharinfo(0)+"] baru saja memperoleh ["+getitemname(.BoxItems[ .Random ])+"] dari Custom Box.",0; end; }

Please help me edit the script,

I want to add percent chance each get an item.

eg:

25194 -> 40%

25195 -> 25%

25196 -> 10%

25199 -> 1%

if anyone can help edit my scripts?

sorry my bad english :D

Edited by Yasunari Ishibashi
Link to comment
Share on other sites

20 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  69
  • Topics Per Day:  0.02
  • Content Count:  592
  • Reputation:   31
  • Joined:  11/14/11
  • Last Seen:  

the better way to do this is to make another type of obb..

http://rathena.org/board/topic/68778-how-to-make-a-custom-obb-or-oca/#entry126978

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  49
  • Topics Per Day:  0.01
  • Content Count:  157
  • Reputation:   2
  • Joined:  01/06/12
  • Last Seen:  

the better way to do this is to make another type of obb..

http://rathena.org/b...ca/#entry126978

how to add annoucher items obtained from the box?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  69
  • Topics Per Day:  0.02
  • Content Count:  592
  • Reputation:   31
  • Joined:  11/14/11
  • Last Seen:  

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  49
  • Topics Per Day:  0.01
  • Content Count:  157
  • Reputation:   2
  • Joined:  01/06/12
  • Last Seen:  

whether it can make a sample script?

similar function as an additional type obb, annoucher if it get the items from the box /no1

sorry bad english /sry

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  49
  • Topics Per Day:  0.01
  • Content Count:  157
  • Reputation:   2
  • Joined:  01/06/12
  • Last Seen:  

what if adding

zeny 50 million 60%

poringcoin x 5 50%

goldcoin x 2 20%

please help /thx

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

what if adding

zeny 50 million 60%

poringcoin x 5 50%

goldcoin x 2 20%

please help /thx

set .@rand, rand( 20+50+60 );

if ( .@rand < 20 ) getitem "goldcoin", 2;

else if ( .@rand < 20+50 ) getitem "poringcoin", 5;

else if ( .@rand < 20+50+60 ) set zeny, zeny + 50000000;

I think you should see the trick

sort the conditions from lowest chance to higher chance

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  49
  • Topics Per Day:  0.01
  • Content Count:  157
  • Reputation:   2
  • Joined:  01/06/12
  • Last Seen:  

how to add annoucher when getting items from the box?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

change

if ( .@rand < 20 ) getitem "goldcoin", 2;

into

if ( .@rand < 20 ) {
   getitem "goldcoin", 2;
   announce strcharinfo(0) +" has earn gold coin x2", bc_all;
}

PS: lucky I'm the kind of scripter that is learn from ZERO (totally nothing)

this is the trick I used 5 years ago ...

of course now I use array x.x

and yeah ... I also asked this kind of questions before x.x

Edited by AnnieRuru
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  43
  • Topics Per Day:  0.01
  • Content Count:  400
  • Reputation:   5
  • Joined:  12/05/11
  • Last Seen:  

how to add annoucher when getting items from the box?

here?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  49
  • Topics Per Day:  0.01
  • Content Count:  157
  • Reputation:   2
  • Joined:  01/06/12
  • Last Seen:  

what if adding

zeny 50 million 60%

poringcoin x 5 50%

goldcoin x 2 20%

please help /thx

set .@rand, rand( 20+50+60 );

if ( .@rand < 20 ) getitem "goldcoin", 2;

else if ( .@rand < 20+50 ) getitem "poringcoin", 5;

else if ( .@rand < 20+50+60 ) set zeny, zeny + 50000000;

I think you should see the trick

sort the conditions from lowest chance to higher chance

thanks /no1

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  49
  • Topics Per Day:  0.01
  • Content Count:  157
  • Reputation:   2
  • Joined:  01/06/12
  • Last Seen:  

   parse_line: expect command, missing function name or calling undeclared function
   28 : {
*   29 : '.'@i = rand(100);
   30 :

please justify the script and adding the amount of the item obtained with annoucher,thanks

change

if ( .@rand < 20 ) getitem "goldcoin", 2;

into

if ( .@rand < 20 ) {
   getitem "goldcoin", 2;
   announce strcharinfo(0) +" has earn gold coin x2", bc_all;
}

PS: lucky I'm the kind of scripter that is learn from ZERO (totally nothing)

this is the trick I used 5 years ago ...

of course now I use array x.x

and yeah ... I also asked this kind of questions before x.x

function    script    sample    {
set .@rand, rand( 20+50+60 );
if ( .@rand < 20 ) {
   getitem "goldcoin", 2;
   announce strcharinfo(0) +" has earn gold coin x2", bc_all;
}
else if ( .@rand < 20+50 ) getitem "poringcoin", 5;
announce strcharinfo(0) +" has earn poring coin x5", bc_all;
}
else if ( .@rand < 20+50+60 ) set zeny, zeny + 50000000;
announce strcharinfo(0) +" has earn zeny 50.000.000", bc_all;
}
}

please justify the script /thx

Edited by Yasunari Ishibashi
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

.... are you asking to be spoon feed ?

xxxxx, ...... ,{ doevent "asdf::Onasdf"; },{},{}

-	script	asdf	-1,{
Onasdf:
set .@rand, rand( 20+50+60 );
if ( .@rand < 20 ) {
	getitem "gold_coin", 2;
	announce strcharinfo(0) +" has earn gold coin x2", bc_all;
}
else if ( .@rand < 20+50 ) {
	getitem "poring_coin", 5;
	announce strcharinfo(0) +" has earn poring coin x5", bc_all;
}
else if ( .@rand < 20+50+60 ) {
	set zeny, zeny + 50000000;
	announce strcharinfo(0) +" has earn zeny 50,000,000", bc_all;
}
}

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

.... are you asking to be spoon feed ?

set .@rand, rand( 20+50+60 );
// [...]
else if ( .@rand < 20+50+60 ) {
//Do stuff
}

What's the point of this? .@rand goes from 0 to (20+50+60)-1, it's obvious that its lower than (20+50+60) xD You added an useless check.

Just like this will be enough ;)

set .@rand, rand( 20+50+60 );
// [...]
else {
//Do stuff
}

Edited by Ryokem
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

What's the point of this? .@rand goes from 0 to (20+50+60)-1, it's obvious that its lower than (20+50+60) xD You added an useless check.

Just like this will be enough ;)

set .@rand, rand( 20+50+60 );
// [...]
else {
   //Do stuff
   }

yeah its lower , that's why I use < and not using <=

how about you post up your script so let's compare our methods

EDITING post : ... using arrays

because I know you are the kind of person who loves to complicate the topic, and I can play with you

EDIT2: here you go

-    script    asdf    -1,{
Onasdf:
   .@rand = rand(.totalchance);
   while ( ( .@rand = .@rand - getd( ".r"+ .@r +"[0]" ) ) >= 0 ) .@r++;
   announce strcharinfo(0) +" has earn "+ .ann$[.@r], bc_all;
   if ( getd( ".r"+ .@r +"[1]" ) )
       zeny = zeny + getd( ".r"+ .@r +"[1]" );
   if ( .size[.@r] > 2 )
       for ( .@i = 0; .@i < .size[.@r]; .@i += 2 )
           getitem getd( ".r"+ .@r +"["+ .@i +"]" ), getd( ".r"+ .@r +"["+( .@i +1 )+"]" );
   end;
OnInit:
   // <chance>, <zeny>, <require item ID 1>, <require item amount 1>, <require item ID 2>, <require item amount 2>, ....
   setarray .r1, 20, 0, 671,2 ;
   setarray .r2, 50, 0, 7539,2 ;
   setarray .r3, 60, 50000000;
   .total = 3;

   freeloop 1;
   .@i = 1;
   while ( .@i <= .total ) {
       .totalchance = .totalchance + getd(".r"+ .@i );
       if ( getd( ".r"+ .@i +"[1]" ) )
           .ann$[.@i] = .ann$[.@i] +"zeny "+ callfunc( "int__", getd( ".r"+ .@i +"[1]" ) );
       .@j = 2;
       .size[.@i] = getarraysize( getd(".r"+ .@i ) );
       if ( getd( ".r"+ .@i +"[1]" ) && .size[.@i] > 2 )
           .ann$[.@i] = .ann$[.@i] +" and ";
       while ( .@j < .size[.@i] ) {
           .ann$[.@i] = .ann$[.@i] + getitemname( getd( ".r"+ .@i +"["+ .@j +"]" ) ) +" x"+ getd( ".r"+ .@i +"["+( .@j +1 )+"]" )+( ( .@j == .size[.@i] -2 )? "":"," );
           .@j += 2;
       }
//        announce .ann$[.@i], 0;
       .@i++;
   }
   freeloop 0;
   end;
}

function	script	int__	{
.@i = getstrlen( .@str$ = getarg(0) ) -3;
.@is_negative = charat( .@str$, 0 ) == "-";
while ( .@i > .@is_negative ) {
	.@str$ = insertchar( .@str$, ",", .@i );
	.@i -= 3;
}
return .@str$;
}

]

Edited by AnnieRuru
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

yeah its lower , that's why I use < and not using <=

how about you post up your script so let's compare our methods

I meant like this

-	script	asdf	-1,{
Onasdf:
set .@rand, rand( 20+50+60 );
if ( .@rand < 20 ) {
	getitem "gold_coin", 2;
	announce strcharinfo(0) +" has earn gold coin x2", bc_all;
}
else if ( .@rand < 20+50 ) {
	getitem "poring_coin", 5;
	announce strcharinfo(0) +" has earn poring coin x5", bc_all;
}
//else if ( .@rand < 20+50+60 ) { //Your version.
else {
	set zeny, zeny + 50000000;
	announce strcharinfo(0) +" has earn zeny 50,000,000", bc_all;
}
}

'Cause you will 100% fall in that case if it jumps to that else.

So no need to do the if (.@rand < 20+50+60 ) check :)

Edited by Ryokem
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

I can hardly believe I am being taught to use ELSE... /...

that was for educational purpose .... ok we are complicating this topic

'Cause you will 100% fall in that case if it jumps to that else.

I like an explanation to this ...

post-8685-0-08620400-1355153694_thumb.jpg

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  205
  • Reputation:   19
  • Joined:  10/12/12
  • Last Seen:  

I can hardly believe I am being taught to use ELSE... /...

that was for educational purpose .... ok we are complicating this topic

'Cause you will 100% fall in that case if it jumps to that else.

I like an explanation to this ...

What's so hard to understand?

set .@rand, rand( 20+50+60 ) ;

Will randomize a number from 0 to (20+50+60)-1. Are you fine with this?

else if ( .@rand < 20+50+60 )

.@rand is OBVIOUSLY < (20+50+60) because its range goes from

Will randomize a number from 0 to (20+50+60)-1.

So you are just using server memory to check something obvious.

Then, just use else, instead of else if, as there no need to check the obvious.

Is this really so difficult to understand? O.o

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  71
  • Reputation:   25
  • Joined:  11/23/11
  • Last Seen:  

I can hardly believe I am being taught to use ELSE... /...

that was for educational purpose .... ok we are complicating this topic

'Cause you will 100% fall in that case if it jumps to that else.

I like an explanation to this ...

What's so hard to understand?

set .@rand, rand( 20+50+60 ) ;

Will randomize a number from 0 to (20+50+60)-1. Are you fine with this?

else if ( .@rand < 20+50+60 )

.@rand is OBVIOUSLY < (20+50+60) because its range goes from

Will randomize a number from 0 to (20+50+60)-1.

So you are just using server memory to check something obvious.

Then, just use else, instead of else if, as there no need to check the obvious.

Is this really so difficult to understand? O.o

She already knows it, what she said is that she made it that way to show how it's done.

  • Upvote 2
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...