function script F_MesItemInfo {
.@item = getarg(0);
.@itemname$ = getitemname(.@item);
if (.@itemname$ != "null") {
.@itemslot = getitemslots(.@item);
if (.@itemslot)
.@itemname$ = sprintf("%s [%d]", .@itemname$, .@itemslot);
}
else
.@itemname$ = "Unknown Item";
if (PACKETVER >= 20150729)
return sprintf("<ITEM>%s<INFO>%d</INFO></ITEM>", .@itemname$, .@item);
else if (PACKETVER >= 20130130)
return sprintf("<ITEMLINK>%s<INFO>%d</INFO></ITEMLINK>", .@itemname$, .@item);
else
return .@itemname$;
}
//===== Hercules Script ======================================
//= Lotti Girl
//===== By: ==================================================
//= AnnieRuru
//===== Current Version: =====================================
//= 1.0
//===== Compatible With: =====================================
//= Hercules 2019-02-22
//===== Description: =========================================
//= Roll a lottery ticket and get some cool items
//= even if you get all the trash items, you still collecting points to buy in lotti shop
//===== Topic ================================================
//= http://herc.ws/board/topic/16579-lotti-girl/
//===== Additional Comments: =================================
//=
//============================================================
/*
create table lotti_rank (
char_id int(11),
name varchar(24),
lotti_point int(11),
primary key (char_id),
key (lotti_point)
) engine = innodb;
*/
prontera,155,180,5 script Lotti Girl 1_F_MARIA,{
goto L_talk;
OnInit:
// Announce to the server when player roll on a rare item
.rare_announcement = 1; // Default 1 : means any item with 0.00%~0.99%
// Amount of points gain for each roll
.lotti_points = 1;
// If the player choose to Roll Repeatedly, what is the maximum amount of Roll in the input
.max_roll = 100;
setarray .item,
Id_Lottery_Ticket, // Item ID requirement
1, // amount of the Item needed
0, // chance of not getting any items
// chance of getting the items
// <Item ID>, <amount>, <chance>
Apple, 10, 1000,
Red_Potion, 5, 50,
Orange_Potion, 4, 40,
Yellow_Potion, 3, 30,
White_Potion, 2, 20,
Blue_Potion, 1, 10;
setarray .itemshop,
// Item sold in the shop
// <Item ID>, <Lotti Points needed>
Red_Potion, 100,
Orange_Potion, 200,
Yellow_Potion, 300,
White_Potion, 400,
Blue_Potion, 500;
// =========================================================================================================
.size = getarraysize(.item);
for ( .@i = 2; .@i < .size; .@i += 3 )
.totalchance += .item[.@i];
for ( .@i = 2; .@i < .size; .@i += 3 ) {
.@chance = .item[.@i] *10000 / .totalchance;
.@division = .@chance / 100;
.@remainder$ = .@chance % 100;
while ( getstrlen(.@remainder$) < 2 )
.@remainder$ = insertchar(.@remainder$, "0", 0);
.chance_display$[.@i] = .@division +"."+ .@remainder$ +"%";
if ( .@division < .rare_announcement )
.announce[.@i] = true;
}
.shop_size = getarraysize(.itemshop);
npcshopdelitem "Lotti#hidden", 512;
for ( .@i = 0; .@i < .shop_size; .@i += 2 )
npcshopadditem "Lotti#hidden", .itemshop[.@i], .itemshop[.@i +1];
npcshopattach "Lotti#hidden";
.npcname$ = "["+ strnpcinfo(NPC_NAME) +"]";
end;
L_talk:
mes .npcname$;
mes "Hello, do you want to play lottery ?";
next;
switch( select( "Deal me in!", "More Information", "Lotti Shop", "Lotti Ranking" ) ) {
mes .npcname$;
case 1:
mesf "It costs %dx %s to play.", .item[1], F_MesItemInfo( .item[0] );
if ( countitem( .item[0] ) < .item[1] )
close;
next;
if ( select( "Play", "Roll Repeatedly" ) == 1 ) {
mes .npcname$;
while ( true ) {
mes "Here we go...";
mes " ";
.@r = rand(.totalchance);
for ( .@i = 2; ( .@r -= .item[.@i] ) >= 0; .@i += 3 );
if ( checkweight( .item[.@i -2], .item[.@i -1] ) == false ) {
mes "It appears you have overweight";
break;
}
delitem .item[0], .item[1];
if ( .@i == 2 )
mes "You get nothing...";
else {
mesf "You get %s%dx%s %s", F_MesColor(C_TEAL), .item[.@i -1], F_MesColor(C_BLACK), F_MesItemInfo(.item[.@i -2]);
getitem .item[.@i -2], .item[.@i -1];
if ( .announce[.@i] )
announce sprintf( _$( "Lotti Girl: Player [%s] has roll on [%s](%s)" ), strcharinfo(0), getitemname(.item[.@i -2]), .chance_display$[.@i] ), bc_all, C_PINK;
}
lotti_points += .lotti_points;
query_sql "insert into lotti_rank values ( "+ getcharid(CHAR_ID_CHAR) +", '"+ escape_sql( strcharinfo(PC_NAME) ) +"', "+ .lotti_points +" ) on duplicate key update lotti_point = lotti_point + "+ .lotti_points;
mes " ";
mes "wanna try again ?";
next;
if ( select( "Yes", "No" ) == 2 ) break;
mes .npcname$;
if ( countitem( .item[0] ) < .item[1] ) {
mes " ";
mesf "It appears you have ran out of %s", F_MesItemInfo( .item[0] );
break;
}
}
}
else {
mes .npcname$;
mes "Input how many rounds to roll";
mesf "Currently you have %dx %s", countitem( .item[0] ), F_MesItemInfo( .item[0] );
next;
input .@roll_input, 1, min( countitem( .item[0] ) / .item[1], .max_roll );
mes .npcname$;
mesf "Are you sure you want to roll %d times ?", .@roll_input;
next;
if ( select( "Yes", "No" ) == 2 ) close;
mes .npcname$;
mes "Here we go...";
mes " ";
// freeloop true;
for ( .@j = 0; .@j < .@roll_input; ++.@j ) {
.@r = rand(.totalchance);
for ( .@i = 2; ( .@r -= .item[.@i] ) >= 0; .@i += 3 );
if ( checkweight( .item[.@i -2], .item[.@i -1] ) == false ) {
mes "It appears you have overweight";
break;
}
delitem .item[0], .item[1];
if ( .@i == 2 )
mes "You get nothing...";
else {
mesf "You get %s%dx%s %s", F_MesColor(C_TEAL), .item[.@i -1], F_MesColor(C_BLACK), F_MesItemInfo(.item[.@i -2]);
getitem .item[.@i -2], .item[.@i -1];
if ( .announce[.@i] )
announce sprintf( _$( "Lotti Girl: Player [%s] has roll on [%s](%s)" ), strcharinfo(0), getitemname(.item[.@i -2]), .chance_display$[.@i] ), bc_all, C_PINK;
}
++.@roll;
sleep2 1; // prevent lag the server
}
lotti_points += .lotti_points * .@roll;
query_sql "insert into lotti_rank values ( "+ getcharid(CHAR_ID_CHAR) +", '"+ escape_sql( strcharinfo(PC_NAME) ) +"', "+ .lotti_points +" ) on duplicate key update lotti_point = lotti_point + "+( .lotti_points * .@roll );
mesf "Total roll : %d times.", .@roll;
}
mes " ";
mes "Thank you for using Lotti service~";
close;
case 2:
freeloop true;
mesf "Item required: %s%dx%s %s", F_MesColor(C_TEAL), .item[1], F_MesColor(C_BLACK), F_MesItemInfo(.item[0]);
if ( .item[2] )
mesf "Chance to gain nothing : %s%s%s", F_MesColor(C_CHOCOLATE), .chance_display$[2], F_MesColor(C_BLACK);
mes "Possible gains:";
for ( .@i = 3; .@i < .size; .@i += 3 )
mesf "%s%dx%s %s (%s%s%s)", F_MesColor(C_TEAL), .item[.@i +1], F_MesColor(C_BLACK), F_MesItemInfo(.item[.@i]), F_MesColor(C_CHOCOLATE), .chance_display$[.@i +2], F_MesColor(C_BLACK);
next;
mes .npcname$;
mesf "Each time you roll, will gain %d Lotti Points.", .lotti_points;
mes "Which can be use to buy rare items in Lotti Shop.";
close;
case 3:
mesf "You currently have %s Lotti Points.", lotti_points;
dispbottom sprintf( _$("You currently have %s Lotti Points."), lotti_points );
close2;
callshop "Lotti#hidden", 1;
end;
case 4:
.@query$ = "SELECT `name`, IF(@d=t.`lotti_point`, @r, @r:=@i), @d:=t.`lotti_point`, @i:=@i+1 ";
.@query$ += "FROM `lotti_rank` t, (SELECT @d:=0, @r:=0, @i:=1)q ";
.@query$ += "ORDER BY `lotti_point` DESC LIMIT 5";
.@nb = query_sql(.@query$, .@name$, .@rank, .@points, .@dummy);
if ( !.@nb ) {
mes "There's no ranking yet ~";
close;
}
for ( .@i = 0; .@i < .@nb; ++.@i )
mesf "%d. %s%s %s%d%s Points", .@rank[.@i], F_MesColor(C_TEAL), .@name$[.@i], F_MesColor(C_CHOCOLATE), .@points[.@i], F_MesColor(C_BLACK);
mes " ";
if ( !query_sql( "SELECT `lotti_point`, 1+(SELECT COUNT(1) FROM `lotti_rank` t1 WHERE t1.lotti_point > t2.lotti_point) FROM `lotti_rank` t2 WHERE `char_id` = "+ getcharid(CHAR_ID_CHAR), .@points, .@rank ) ) {
mes "You are not in the rank.";
close;
}
mesf "Your current Point > %d", .@points;
mesf "Your current Rank > %d", .@rank;
close;
}
end; // shouldn't reach
OnBuyItem:
mes .npcname$;
if ( !@bought_quantity ) end;
if ( checkweight2( @bought_nameid, @bought_quantity ) == false ) {
mes "It appears you can't carry them all";
close;
}
.@size = getarraysize( @bought_nameid );
for ( .@i = 0; .@i < .@size; .@i++ ) {
for ( .@j = 0; .@j < .shop_size; .@j += 2 )
if ( @bought_nameid[.@i] == .itemshop[.@j] )
break;
.@itemcost += .itemshop[.@j +1] * @bought_quantity[.@i];
}
if ( .@itemcost > lotti_points ) {
mes "You don't have enough Lotti Points";
close;
}
lotti_points -= .@itemcost;
for ( .@i = 0; .@i < .@size; ++.@i )
getitem @bought_nameid[.@i], @bought_quantity[.@i];
deletearray @bought_nameid;
deletearray @bought_quantity;
mes "Thanks for buying ~";
close;
}
- shop Lotti#hidden -1,512:1000
how to work this on rathena? error on mesf lines