SA-MP Forums Archive
Command bug - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Command bug (/showthread.php?tid=621925)



Command bug - Mijata - 16.11.2016

When i try to send money to other player it says you don't have enought money, and if i type number more than i have this player going to lose all his money...
Код:
CMD:givecash(playerid,params[])
{
   new
   id,
   amount,
   l_string[77],
   name[25];
   if(sscanf(params,"ui",id,amount)) return SendClientMessage(playerid,-1,"/givecash [id] [amount]");
   if(GetPlayerMoney(playerid) < amount || GetPlayerMoney(playerid) <= 0)return SendClientMessage(playerid,RED,"You don't have enought cash");
   if(id == playerid) return SendClientMessage(playerid,RED,"You can't give money to yourself.");
   GivePlayerMoney(playerid,-amount);
   GivePlayerMoney(id,amount);
   GetPlayerName(playerid,name,25);
   format(l_string,128,"%s has given to you the amount of cash: %i",name,amount);
   SendClientMessage(id,0x33CCFFAA,l_string);
   return 1;
}



Re: Command bug - DTV - 16.11.2016

If I'm reading it right, the way you have it set up to remove the player's money is instead of subtracting the amount from the total money he has, you're negating the value rather than removing it from their total money. Negating the value basically changes the amount given to the negative equivalent (i.e. Negating 10 would make it -10, not 0). Also the way GivePlayerMoney is named isn't accurate as it just sets the player's money to that amount rather than adding or subtracting from their total.

The way you'll want to do it is getting the player's current money amount via GetPlayerMoney and subtract from that and do the same with the receiving player but add the amount rather than subtract.

pawn Код:
GivePlayerMoney(playerid,GetPlayerMoney(playerid)-amount);
GivePlayerMoney(id,GetPlayerMoney(id)+amount);



Re: Command bug - Mijata - 17.11.2016

Works, but now when i give to player 1$ he get like 10 000 or more...


Re: Command bug - SickAttack - 17.11.2016

DTV is extremely wrong.

PHP код:
CMD:givecash(playerid,params[])
{
   new
   
id,
   
amount,
   
l_string[77],
   
name[25];
   if(
sscanf(params,"ui",id,amount)) return SendClientMessage(playerid,-1,"/givecash [id] [amount]");
   if(
GetPlayerMoney(playerid) < amount) return SendClientMessage(playerid,RED,"You don't have enought cash");
   if(
amount 0) return SendClientMessage(playerid,RED,"You have entered an invalid amount");
   if(
id == playerid) return SendClientMessage(playerid,RED,"You can't give money to yourself.");
   
GivePlayerMoney(playerid,-amount);
   
GivePlayerMoney(id,amount);
   
GetPlayerName(playerid,name,25);
   
format(l_string,128,"%s has given to you the amount of cash: %i",name,amount);
   
SendClientMessage(id,0x33CCFFAA,l_string);
   return 
1;




Re: Command bug - Yaa - 17.11.2016

use this

PHP код:
GivePlayerMoney(playerid,GetPlayerMoney(playerid)-amount);
GivePlayerMoney(id,amount); 



Re: Command bug - SickAttack - 17.11.2016

Quote:
Originally Posted by Yaa
Посмотреть сообщение
use this

PHP код:
GivePlayerMoney(playerid,GetPlayerMoney(playerid)-amount);
GivePlayerMoney(id,amount); 
No, no, no. That's wrong.

Why do you assume give means set here? Why would anyone?...

GivePlayerCookie(playerid, 5);

Player has 3 cookies, I give the player 5, player now has 5 cookies. Really...


Re: Command bug - oMa37 - 17.11.2016

Quote:
Originally Posted by Yaa
Посмотреть сообщение
use this

PHP код:
GivePlayerMoney(playerid,GetPlayerMoney(playerid)-amount);
GivePlayerMoney(id,amount); 
It will work fine without 'GetPlayerMoney(playerid);', It's not necessary.


Re: Command bug - GoldenLion - 17.11.2016

Quote:
Originally Posted by Yaa
Посмотреть сообщение
use this

PHP код:
GivePlayerMoney(playerid,GetPlayerMoney(playerid)-amount);
GivePlayerMoney(id,amount); 
This is not going to work as you are giving the player as much money as he had before subtracted by the amount. So like let's say player has $5000, the amount is $500, means you are giving him $4500 and he has $9500 in total now. So basically if you want to use it you need to reset player's money first, but it's just easier to do -amount. Also SickAttack already gave him a working code.

EDIT: SickAttack replied before me lol.


Re: Command bug - SickAttack - 17.11.2016

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
This is not going to work as you are giving the player as much money as he had before subtracted by the amount. So like let's say player has $5000, the amount is $500, means you are giving him $4500 and he has $9500 in total now. So basically if you want to use it you need to reset player's money first, but it's just easier to do -amount. Also SickAttack already gave him a working code.

EDIT: SickAttack replied before me lol.
5500^


Re: Command bug - GoldenLion - 17.11.2016

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
5500^
wat?