Givecash
#1

Hey i just noticed that i can steal money from others with this code
Код:
CMD:givecash(playerid, params[])
{
	new
		giveplayerid,
		amount;
	if (sscanf(params, "dd", giveplayerid, amount)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid] [amount]");
	else if (!IsPlayerConnected(giveplayerid)) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
	else if (amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000AA, "Insufficient Funds");
	else
	{
		RewardPlayer(giveplayerid, amount,0);
		RewardPlayer(playerid, 0 - amount, 0);
		SendClientMessage(playerid, 0x00FF00AA, "Money sent");
		SendClientMessage(giveplayerid, 0x00FF00AA, "Money recieved");
	}
	return 1;
}
But how can i prevent that?

Greets Thimo
Reply
#2

How can you steal their money?
Like /givecash [playerid] -1000000?

Then I think :

pawn Код:
if (amount <1)) SendClientMessage(playerid, 0xFF0000AA, "Insufficient Funds");
Reply
#3

A little check if the player is near the target should fix it (If I understand you right?)
pawn Код:
stock IsPlayerNearPlayer(playerid, playerid2)
{
    new Float:Pos[3];
    GetPlayerPos(playerid2, Pos[0], Pos[1], Pos[2]);
    if(IsPlayerInRangeOfPoint(playerid, 6.0, Pos[0], Pos[1], Pos[2])) return 1;
    return 0;
}
//Example:
if (!IsPlayerNearPlayer(playerid, giveplayerid)) SendClientMessage(playerid, RED, "You need to be closer to the player!");
Reply
#4

Change.
pawn Код:
else if (amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000AA, "Insufficient Funds");
// to
else if (amount > GetPlayerMoney(playerid) || ammount < 0) SendClientMessage(playerid, 0xFF0000AA, "Insufficient Funds");
Reply
#5

Код:
CMD:givecash(playerid, params[])
{
	new
		giveplayerid,
		amount;
	if (sscanf(params, "dd", giveplayerid, amount)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid] [amount]");
	else if (!IsPlayerConnected(giveplayerid)) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
	else if (amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000AA, "Insufficient Funds");
	else if (amount < 0) SendClientMessage(playerid, 0xFF0000AA, "Invalid Amount");
        else
	{
		RewardPlayer(giveplayerid, amount,0);
		RewardPlayer(playerid, 0 - amount, 0);
		SendClientMessage(playerid, 0x00FF00AA, "Money sent");
		SendClientMessage(giveplayerid, 0x00FF00AA, "Money recieved");
	}
	return 1;
}
Reply
#6

Quote:
Originally Posted by OPremium
Посмотреть сообщение
Код:
CMD:givecash(playerid, params[])
{
	new
		giveplayerid,
		amount;
	if (sscanf(params, "dd", giveplayerid, amount)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid] [amount]");
	else if (!IsPlayerConnected(giveplayerid)) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
	else if (amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000AA, "Insufficient Funds");
	else if (amount < 0) SendClientMessage(playerid, 0xFF0000AA, "Invalid Amount");
        else
	{
		RewardPlayer(giveplayerid, amount,0);
		RewardPlayer(playerid, 0 - amount, 0);
		SendClientMessage(playerid, 0x00FF00AA, "Money sent");
		SendClientMessage(giveplayerid, 0x00FF00AA, "Money recieved");
	}
	return 1;
}
I guess we were already done here?..
Reply
#7

Quote:
Originally Posted by OPremium
Посмотреть сообщение
Код:
CMD:givecash(playerid, params[])
{
	new
		giveplayerid,
		amount;
	if (sscanf(params, "dd", giveplayerid, amount)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid] [amount]");
	else if (!IsPlayerConnected(giveplayerid)) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
	else if (amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000AA, "Insufficient Funds");
	else if (amount < 0) SendClientMessage(playerid, 0xFF0000AA, "Invalid Amount");
        else
	{
		RewardPlayer(giveplayerid, amount,0);
		RewardPlayer(playerid, 0 - amount, 0);
		SendClientMessage(playerid, 0x00FF00AA, "Money sent");
		SendClientMessage(giveplayerid, 0x00FF00AA, "Money recieved");
	}
	return 1;
}
that was already replied
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)