Command bug
#1

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;
}
Reply
#2

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);
Reply
#3

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

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;

Reply
#5

use this

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

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

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.
Reply
#8

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.
Reply
#9

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^
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)