Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
106 lines (98 sloc)
3.67 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // A simple script where the player can get some defined items at some rates using some defined item | |
| // Example: | |
| // setarray .p0, 671,50, 2462,1,20, 1161,1,30, 5394,1,50; // 50% to get something using a gold coin (id: 671). Then [20/(20+30+50)]% (which is.. 20%) to get the item id 2462. | |
| // https://rathena.org/board/topic/80167-gatcha-item-use-gold-coin-and-tcg/ | |
| prontera,155,180,5 script Random 98,{ | |
| mes .npc_name$; | |
| mes "Hello, do you want to play ?"; | |
| next; | |
| switch( select( "Play !", "More Informations", "Leave" ) ) { | |
| case 1: | |
| break; | |
| case 2: | |
| while( getd(".p"+ .@j ) ) { | |
| mes .npc_name$; | |
| mes "Item required: ^FFCC00"+ getitemname( getd(".p"+ .@j ) ) +"^000000"; | |
| mes "Chance to gain something: ^CC0000"+ getd(".p"+ .@j +"[1]" ) +"%^000000"; | |
| mes "Possible gains:"; | |
| .@total_rates = getd(".totalchance"+ .@j ); | |
| for( .@i = 3; .@i < getarraysize( getd(".p"+ .@j ) ); .@i += 3 ) { | |
| .@amount = getd(".p"+ .@j +"["+ .@i +"]" ); | |
| .@id = getd(".p"+ .@j +"["+ (.@i -1) +"]" ); | |
| .@rates = getd(".p"+ .@j +"["+ (.@i +1) +"]" ); | |
| .@percent = .@rates * 100 / .@total_rates; | |
| mes "^0000FFx"+ .@amount +"^000000 "+ getitemname(.@id) +" (^CC0000"+ .@percent +"%^000000)"; | |
| } | |
| .@j++; | |
| next; | |
| } | |
| break; | |
| case 3: | |
| mes .npc_name$; | |
| mes "Bye!~"; | |
| close; | |
| } | |
| mes .npc_name$; | |
| mes "Which item do you want to use ?"; | |
| next; | |
| for( .@j = 0; getd(".p"+ .@j ); .@j++ ) { | |
| .@size = getarraysize( .@menu$ ); | |
| .@menu$[ .@size ] = getitemname( getd(".p"+ .@j ) ); | |
| .@sel[ .@size ] = .@j; | |
| } | |
| .@s = .@sel[ select( implode( .@menu$, ":" ) ) -1 ]; | |
| .@item_required = getd(".p"+ .@s ); | |
| .@basic_chance = getd(".p"+ .@s +"[1]" ); | |
| .@total_rates = getd(".totalchance"+ .@s ); | |
| while (1) { | |
| if ( countitem(.@item_required) < 1 ) { | |
| mes .npc_name$; | |
| mes "It seems you have ran out of "+ getitemname(.@item_required) + "."; | |
| close; | |
| } | |
| mes .npc_name$; | |
| mes "Here we go..."; | |
| delitem .@item_required, 1; | |
| if (rand(100) > .@basic_chance) // lose | |
| mes "You got nothing."; | |
| else { | |
| .@rand = rand(.@total_rates); | |
| .@r = 1; | |
| while ( ( .@rand = .@rand - getd( ".p"+ .@s +"["+ (1+ 3 * .@r) +"]" ) ) >= 0 ) .@r++; | |
| .@amount = getd( ".p"+ .@s +"["+( 1+3*.@r -1 )+"]" ); | |
| .@id = getd( ".p"+ .@s +"["+ (1+ 3*.@r -2) +"]" ); | |
| .@rates = getd( ".p"+ .@s +"["+ (1+ 3 * .@r) +"]" ); | |
| .@percent = .@rates * 100 / .@total_rates; | |
| getitem .@id, .@amount; | |
| mes "You got ^FF00CC"+ .@amount +" "+ getitemname(.@id) +"^000000."; | |
| if (.@percent <= .display_announce) | |
| announce strcharinfo(0) + " got ^FF00CC"+ .@amount +" "+ getitemname(.@id) +"^000000 !", 0; | |
| } | |
| mes " "; | |
| mes "wanna try again ?"; | |
| next; | |
| if ( select( "Yes", "No" ) == 2 ) close; | |
| } | |
| close; | |
| OnInit: | |
| // (item ID need) (rate), (reward 1) (number of reward 1) (rate to gain), (reward 2) (number of reward 2) (chance to gain)... | |
| // For each array the chance to gain something is : (rate) | |
| // and the chance to gain the item is : [ rate to gain / sum of all the rate ] | |
| setarray .p0, 671,50, 2462,1,20, 1161,1,30, 5394,1,50; // 50% to get something using a gold coin. | |
| setarray .p1, 7227,20, 2462,1,10, 2541,1,10, 1161,1,10, 13517,1,70; | |
| // Below which PERCENT the system display an announce. | |
| // For example in | |
| // setarray .p1, 7227,20, 2462,1,10, 2541,1,10, 1161,1,10, 13517,1,50; | |
| // the chance to get item id 2462 is 10% and the server will display an announce when the player get this item. | |
| .display_announce = 10; | |
| // others | |
| while ( getd(".p"+ .@j) ) { | |
| if (getd(".p"+ .@j +"[1]") > 100) | |
| setd ".p"+ .@j +"[1]", 100; | |
| for( .@i = 4; .@i < getarraysize( getd(".p"+ .@j ) ); .@i += 3 ) | |
| setd ".totalchance"+ .@j, getd(".totalchance"+ .@j ) + getd(".p"+ .@j +"["+ .@i +"]" ); | |
| .@j++; | |
| } | |
| .npc_name$ = "[ "+ strnpcinfo(1) +"]"; | |
| end; | |
| } |