too many loop, simplify your script
prontera,181,204,4 script Card Buyer 658,{
mes "[Card Buyer]";
mes "You have any card to sell ? <3";
next;
getinventorylist;
for (.@i = 0; .@i < @inventorylist_count; .@i++)
{
.@card_id = @inventorylist_id[.@i];
.@card_qt = @inventorylist_amount[.@i];
if (getiteminfo(.@card_id, 2) != 6)
continue; // skip not card
// find if this card can be sold to this npc
.@f = inarray(.card_list, .@card_id);
// not in list card that can be sold, skip!
if (.@f == -1)
continue;
.@menu$[.@n] = getitemname(.@card_id) + callfunc("F_InsertComma", .card_price[.@card_id]);
.@card_ids[.@n] = .@card_id;
.@card_qts[.@n] = .@card_qt;
.@n++;
}
.@s = select(implode(.@menu$, ":")) -1;
mes "[Card Buyer]";
.@card_id = .@card_ids[.@s];
.@card_qt = .@card_qts[.@s];
mes "You want to sell "+ getitemname(.@card_id) +"?";
mes "I will pay you "+ callfunc("F_InsertComma", .card_price[.@card_id]) +"z/ea";
.@total = .card_price[.@card_id] * .@card_qt;
mes "Total Price: "+ callfunc("F_InsertComma", .@total)+"z.";
select("Yes");
delitem .@card_id, .@card_qt;
Zeny += .@total;
mes "[Card Buyer]";
mes "Thank you for your patronage!";
close;
OnInit:
function AddCard;
/*
@param price in zeny
@param "card id:card id:card id:...."
Sample:
AddCard(10000, "4001:4002:4003");
*/
freeloop(true);
AddCard(100000, "4032:4013:4023:4009:4004:4002:4026:4019:4006:4050:4008:4011:4001:4021:4022:4028:4016:4051");
AddCard(500000, "4043:4015:4052:4027:4003:4014:4012:4010:4034");
freeloop(false);
end;
function AddCard {
.@price = getarg(0, 0);
if (.@price < 1)
{
debugmes sprintf("[%s] AddCard: buying price is %d, minimum price is 1", strnpcinfo(0), .@price);
return;
}
.@card_list$ = getarg(1, "");
if (.@card$ == "")
{
debugmes sprintf("[%s] AddCard: card list is empty for price %d", strnpcinfo(0), .@price);
return;
}
explode(.@card$, .@card_list$, ":");
for (.@i = 0; .@i < getarraysize(.@card$); .@i++)
{
.@id = atoi(.@card$);
if (getitemname(.@id) == "null")
{
debugmes sprintf("[%s] AddCard: card id %d is not exist price %d", strnpcinfo(0), .@id, .@price);
continue;
}
.@f = inarray(.card_list, .@id);
if (.@f > -1)
{
debugmes sprintf("[%s] AddCard: card id %d duplicate entry, first set price %d", strnpcinfo(0), .@id, .card_price[.@id]);
continue;
}
.card_list[getarraysize(.card_list)] = .@id;
.card_price[.@id] = .@price;
}
return;
}
}
writing it with out testing it work or not, you can use this as sample tho.. if you want