Jump to content
  • 0

Question

Posted (edited)

how i do player buy item in npc for ponts in Sql?

 

table:

ALTER TABLE `char` ADD `pontos` INT NOT NULL ;

i make this but no ok!

when player buy decrease  -1 ponto in table this char.

 

query_sql "UPDATE `char` SET `pontos` = `pontos` -1";
Edited by brunoshp

9 answers to this question

Recommended Posts

Posted
ALTER TABLE `char` ADD `pontos` int(11) unsigned NOT NULL default '0';
query_sql "UPDATE `char` SET `pontos` = `pontos` -1 WHERE `charid` = "+getcharid(0)+" AND `pontos` <> 0;";
It's kind of hard for me to understand what you want exactly.
Posted (edited)

-	shop	custom_seller1	-1,501:50

morocc,159,97,5 script SQL NPC Shop 60,{

mes "Welcome to my shop!";

callshop "custom_seller1",1;

npcshopattach "custom_seller1";

end;

OnBuyItem:

for(set @i,0; .shop_list[@i]; set @i,@i+1) {

for(set @d,0; @d<getarraysize(@bought_nameid); set @d,@d+1){

set .@shpl, .shop_list[@i];

set .@pril, .price_list[@i];

set .@boun, @bought_nameid[@d];

set .@bouq, @bought_quantity[@d];

if(.@boun==.@shpl) {

if(checkweight(.@shpl,.@bouq)){

if(query_sql("UPDATE `char` SET `pontos` = `pontos` -"+( .@pril*.@bouq )+" WHERE `char_id` = "+getcharid(0)+" AND `pontos` -"+( .@pril*.@bouq )+" > 0;",.@a)){

getitem .@boun,.@bouq;

} else { dispbottom "I'm sorry you don't have enough points for "+getitemname(.@shpl)+"s."; }

} else { dispbottom "I'm sorry but you can't hold that many "+getitemname(.@shpl)+"s."; }

}

}

}

deletearray @bought_quantity, getarraysize(@bought_quantity);

deletearray @bought_nameid, getarraysize(@bought_nameid);

close;

OnInit:

//=================Configuration================

//Itemlist

setarray .shop_list[0],607,678;

setarray .price_list[0],20,15;

//=================================================

npcshopitem "custom_seller1",0,0;

for(set .i,0; .shop_list[.i]; set .i,.i+1) npcshopadditem "custom_seller1",.shop_list[.i],.price_list[.i];

end;

}

Edited by Skorm
Posted

Very sorry I have to go to school right now x.x. Maybe someone else can fix it? It looks like the variable for .@boun is mistaken somewhere O_O. You wouldn't be getting that warning had the transaction not gone through. If nobody has fixed by the time I get home. Will help more. tytyty!

Posted


- shop falseshop -1,909:-1

prontera,155,160,5 script dffddf 56,{

callshop "falseshop",1;

npcshopattach "falseshop";

end;

OnBuyItem:

query_sql "select `pontos` from `char` where `char_id` = "+ getcharid(0), .@pontos;

while( @bought_nameid[.@j] ) {

for ( .@i = 0; .@i < .size_shop; .@i += 2 )

if ( .item_shop[.@i] == @bought_nameid[.@j] ) break;

.@amount = .@amount + @bought_quantity[.@j] * .item_shop[.@i+1];

.@j++;

}

if ( .@amount > .@pontos ) {

dispbottom "You need "+ .@amount +" point(s) and you have "+ .@pontos +" point(s).";

end;

}

query_sql "update `char` set `pontos` = ( `pontos` - "+ .@amount +" ) where `char_id` = "+ getcharid(0);

for ( .@i = 0; .@i < getarraysize( @bought_nameid ); .@i++ )

getitem @bought_nameid[.@i], @bought_quantity[.@i];

dispbottom "You use "+ .@amount +" point(s). "+ .@pontos +" point(s) remains.";

end;

OnInit:

setarray .item_shop, 7447,5, 7448,6; // <Item ID>, <amount points required>

.size_shop = getarraysize( .item_shop );

npcshopdelitem "falseshop",909;

while( .@i < .size_shop ) {

npcshopadditem "falseshop", .item_shop[.@i], .item_shop[.@i+1] ;

.@i += 2;

}

}

  • Upvote 1
Posted

-	shop	custom_seller1	-1,501:50
morocc,159,97,5	script	SQL NPC Shop	60,{
mes "Welcome to my shop!";
callshop "custom_seller1",1;
npcshopattach "custom_seller1";
end;
OnBuyItem:
for(set @i,0; .shop_list[@i]; set @i,@i+1) {
	for(set @d,0; @d<getarraysize(@bought_nameid); set @d,@d+1){
		set .@shpl,	.shop_list[@i];
		set .@pril,	.price_list[@i];
		set .@boun,	@bought_nameid[@d];
		set .@bouq,	@bought_quantity[@d];
		if(.@boun==.@shpl) {
			if(checkweight(.@shpl,.@bouq)){
				if(query_sql("SELECT `pontos` FROM `char` WHERE `char_id` = "+getcharid(0)+" AND `pontos` -"+( .@pril*.@bouq )+"  > 0 FOR UPDATE;",.@a)){
					query_sql("UPDATE `char` SET `pontos` = `pontos` -"+( .@pril*.@bouq )+" WHERE `char_id` = "+getcharid(0)+";");
					getitem .@shpl,.@bouq;
					dispbottom "Transaction complete you have "+(.@a-(.@pril*.@bouq))+" points left.";
				} else { dispbottom "I'm sorry you don't have enough points for "+getitemname(.@shpl)+"s."; }
			} else { dispbottom "I'm sorry but you can't hold that many "+getitemname(.@shpl)+"s."; }
		}
	}
}

deletearray @bought_quantity, getarraysize(@bought_quantity);
deletearray @bought_nameid, getarraysize(@bought_nameid);
close;

OnInit:
//=================Configuration================
//Itemlist
setarray .shop_list,607,678;
setarray .price_list,20,15;
//=================================================

npcshopdelitem "custom_seller1",501;
for(set .i,0; .i<getarraysize(.shop_list); set .i,.i+1) npcshopadditem "custom_seller1",.shop_list[.i],.price_list[.i];
end;
}

LOL I didn't see your post Chapuche!

Chapuche, you forgot to add a weight check.

  • Upvote 1

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...