[SOLVED] add GetDistanceBetweenPlayers to /givecash
#1

Hey sa-mp forum,

I have a working dcmd /givecash command and I wish to add GetDistanceBetweenPlayers so that players may only send and recieve money if they are close enough to each other. Also, I would like to add to it something like: If player is too faraway, then sendclientmessage "You are too faraway".

This is the dcmd:
Код:
dcmd_givecash(playerid, params[])
{
  new giveplayerid, amount;
  if(sscanf(params, "dd", giveplayerid, amount)) SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /givecash [playerid] [amount]");
  else if(!IsPlayerConnected(giveplayerid)) SendClientMessage(playerid, 0xFF0000FF, "* Invalid player ID!");
  else if(amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000FF, "* Invalid amount!");
  else
  {
    new playername[24], string[80];
    GetPlayerName(giveplayerid, playername, 24);
    format(string, 80, "* You sent $%d to %s (ID %d)", amount, playername, giveplayerid);
    SendClientMessage(playerid, 0x00FF00FF, string);
    GetPlayerName(playerid, playername, 24);
    format(string, 80, "* You revceived $%d from %s (ID %d)", amount, playername, playerid);
    SendClientMessage(giveplayerid, 0x00FF00FF, string);
    GivePlayerMoney(giveplayerid, amount);
    GivePlayerMoney(playerid, 0 - amount);
  }
  return true;
}
Any ideas of what I can do?

Thanks,
borg245
Reply
#2

Код:
dcmd_givecash(playerid, params[])
{
	new giveplayerid, amount;
	if(sscanf(params, "dd", giveplayerid, amount)) SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /givecash [playerid] [amount]");
	else if(!IsPlayerConnected(giveplayerid)) SendClientMessage(playerid, 0xFF0000FF, "* Invalid player ID!");
	else if(amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000FF, "* Invalid amount!");
	else
	{
		new Float:X,Float:Y,Float:Z,InRange;
		GetPlayerPos(playerid,X,Y,Z);
		if(IsPlayerInRangeOfPoint(giveplayerid,20,X,Y,Z))
		{
			new playername[24], string[80];
			GetPlayerName(giveplayerid, playername, 24);
			format(string, 80, "* You sent $%d to %s (ID %d)", amount, playername, giveplayerid);
			SendClientMessage(playerid, 0x00FF00FF, string);
			GetPlayerName(playerid, playername, 24);
			format(string, 80, "* You revceived $%d from %s (ID %d)", amount, playername, playerid);
			SendClientMessage(giveplayerid, 0x00FF00FF, string);
			GivePlayerMoney(giveplayerid, amount);
			GivePlayerMoney(playerid, 0 - amount);
		}
		else
		{
			SendClientMessage(playerid, 0xFF0000FF, "* You are too far away!");
		}
	}
	return true;
}
Reply
#3

nice babul should work
Reply
#4

Quote:
Originally Posted by Babul
Код:
dcmd_givecash(playerid, params[])
{
	new giveplayerid, amount;
	if(sscanf(params, "dd", giveplayerid, amount)) SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /givecash [playerid] [amount]");
	else if(!IsPlayerConnected(giveplayerid)) SendClientMessage(playerid, 0xFF0000FF, "* Invalid player ID!");
	else if(amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000FF, "* Invalid amount!");
	else
	{
		new Float:X,Float:Y,Float:Z,InRange;
		GetPlayerPos(playerid,X,Y,Z);
		if(IsPlayerInRangeOfPoint(giveplayerid,20,X,Y,Z))
		{
			new playername[24], string[80];
			GetPlayerName(giveplayerid, playername, 24);
			format(string, 80, "* You sent $%d to %s (ID %d)", amount, playername, giveplayerid);
			SendClientMessage(playerid, 0x00FF00FF, string);
			GetPlayerName(playerid, playername, 24);
			format(string, 80, "* You revceived $%d from %s (ID %d)", amount, playername, playerid);
			SendClientMessage(giveplayerid, 0x00FF00FF, string);
			GivePlayerMoney(giveplayerid, amount);
			GivePlayerMoney(playerid, 0 - amount);
		}
		else
		{
			SendClientMessage(playerid, 0xFF0000FF, "* You are too far away!");
		}
	}
	return true;
}
Thanks alot for that, it worked :0. I had 1 warning, but I managed to fix it
Cheers
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)