Jump to content
  • 0

Script edit to check overweight status before buying


johnbond

Question


  • Group:  Members
  • Topic Count:  113
  • Topics Per Day:  0.03
  • Content Count:  457
  • Reputation:   11
  • Joined:  02/17/13
  • Last Seen:  

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! :)

Link to comment
Share on other sites

3 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  196
  • Reputation:   72
  • Joined:  12/12/11
  • Last Seen:  

try this

 

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:
	getinventorylist;
	set .@tmp_weight, 0;
	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);
				set .@tmp_weight, .@tmp_weight +(getiteminfo(@bought_nameid[@i], 6) * @bought_quantity[@i]);
				break;
			}
		}
	}

	if (@inventorylist_count > MAX_INVENTORY)
	{
		message strcharinfo(0),"Over max inventory";
		end;
	}

	if ((Weight + .@tmp_weight) > MaxWeight)
	{
		message strcharinfo(0),"Over max weight";
		end;
	}

	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
Edited by Napster
Link to comment
Share on other sites


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

OnBuyItem:
	if ( !checkweight2( @bought_nameid,@bought_quantity ) ) {
		mes "Overweight, terminated.";
		close;
	}

checkweight2 support array.

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...