I have this Vote Points exchanger NPC wherein players talk to NPC to exchange their vote points to get items. The script uses a shop for this.
Now my problem is when players are overweight or inventory full the item being bought drops to the ground and is lost by players. The vote points are also deducted.
Please help me make this script check if character can be able to carry the item(s) being bought and cancel the transaction if they will be overweight or inventory full after buying it to avoid it being dropped to the ground.
Here is the script I use.
prt_in,118,37,5 script Vote Shop 868,{
set .@count, query_sql("SELECT `amount` FROM ea_voting WHERE `account_id` = " + getcharid(3), .@VotingPoints);
set @VotingPoints, .@VotingPoints;
message strcharinfo(0),"You currently have [ "+ @VotingPoints +" ] Vote Points.";
message strcharinfo(0),"Vote Points are used to buy from me even if the windows displays 'Z'.";
message strcharinfo(0),"You can get Vote Points by Voting from our website ";
callshop "Donator_SHOP#03",1;
npcshopattach "Donator_SHOP#03";
end;
OnBuyItem:
for(set @i,0; @i < getarraysize(@bought_nameid); set @i,@i+1) {
for(set @j,0; @j < getarraysize(.POD_ITEMS); set @j,@j+2) {
if(.POD_ITEMS[@j] == @bought_nameid[@i]) {
set @itemcost,(.POD_ITEMS[(@j+1)]*@bought_quantity[@i]);
set @totalcost,(@totalcost+@itemcost);
break;
}
}
}
set .@count, query_sql("SELECT `amount` FROM ea_voting WHERE `account_id` = " + getcharid(3), .@VotingPoints);
set @VotingPoints, .@VotingPoints;
if(@totalcost > @VotingPoints) {
message strcharinfo(0),"You don't have enough Vote Points. Relog to be able to buy again with correct Vote Points.";
end;
} else {
for(set @i,0; @i < getarraysize(@bought_nameid); set @i,@i+1) {
getitem @bought_nameid[@i],@bought_quantity[@i];
query_sql "INSERT INTO `votepointlog` VALUES ( NULL,"+getcharid(3)+",'"+ escape_sql(strcharinfo(0)) +"',"+@bought_nameid[@i]+","+@bought_quantity[@i]+",'KAFRAPOINTS',NOW() )";
}
set @VotingPoints,@VotingPoints-@totalcost;
query_sql "UPDATE ea_voting SET amount = " + @VotingPoints + " WHERE account_id = " + getcharid(3);
message strcharinfo(0),"You now have ["+@VotingPoints+"] Vote Points left. Get more Vote Points by Voting from our website ";
}
set @totalcost,0;
deletearray @bought_nameid[0],128;
deletearray @bought_quantity[0],128;
sleep2 1000;
message strcharinfo(0),"Trade Information is Logged for Security Reason(s). No return no exchange.";
end;
OnInit:
waitingroom strnpcinfo(2) + "" + strnpcinfo(1)+"",0;
query_sql "CREATE TABLE IF NOT EXISTS `votepointlog` (`id` int(11) NOT NULL auto_increment,`account_id` int(11) NOT NULL default '0',`name` varchar(30) NOT NULL default '',`item` int(11) NOT NULL default '0', `amount` int(11) NOT NULL default '1',`point` varchar(30) NOT NULL default '', `time` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`), KEY `char_id` (`account_id`)) ENGINE=MyISAM";
npcshopdelitem "Donator_SHOP#03",677;
setarray .POD_ITEMS[0],12210,80,12103,80,12214,80; // Input as many items as you want (item::price)
set .table, "ea_voting";
for(set .@i,0; .@i < getarraysize(.POD_ITEMS); set .@i,.@i+2) {
npcshopadditem "Donator_SHOP#03",.POD_ITEMS[.@i],.POD_ITEMS[(.@i+1)];
}
}
- shop Donator_SHOP#03 139,677:100
I hope somebody could help me with this.
Thank you my friends!