Jump to content
  • 0

Help in sql Script


brunoshp

Question


  • Group:  Members
  • Topic Count:  64
  • Topics Per Day:  0.02
  • Content Count:  180
  • Reputation:   7
  • Joined:  12/19/12
  • Last Seen:  

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

9 answers to this question

Recommended Posts


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

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.
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  64
  • Topics Per Day:  0.02
  • Content Count:  180
  • Reputation:   7
  • Joined:  12/19/12
  • Last Seen:  

i need buy  item for pontos.

ex: 

item 607 for 20 pontos

item 678 for 15 pontos

and other items 

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

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


  • Group:  Members
  • Topic Count:  64
  • Topics Per Day:  0.02
  • Content Count:  180
  • Reputation:   7
  • Joined:  12/19/12
  • Last Seen:  

when i go buy , he talk me not have point , but i have  300!

http://imageshack.us/photo/my-images/189/error1d.png/

Edited by brunoshp
Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

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!

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  64
  • Topics Per Day:  0.02
  • Content Count:  180
  • Reputation:   7
  • Joined:  12/19/12
  • Last Seen:  

i will waiting you! ty

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  


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


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

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


  • Group:  Members
  • Topic Count:  64
  • Topics Per Day:  0.02
  • Content Count:  180
  • Reputation:   7
  • Joined:  12/19/12
  • Last Seen:  

Now is ok!!!! thz for alll!

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