SA-MP Forums Archive
How to use a command with out puttin the person`s id - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to use a command with out puttin the person`s id (/showthread.php?tid=270342)



How to use a command with out puttin the person`s id - MWhite_005 - 20.07.2011

Hey again guys,i was just wondering how to attack someone within a certain range and not needing to put there Ids to attack,for eg. '/rob (without id)' and the if the person isn't near it should state 'person not close enough'.Ive constructed a basic '/slap' script,it lacks those functions, here it is :
------------------------------------------------------------------------------
dcmd_fs(playerid, params[])
{

new ID;
if(sscanf(params, "i", ID)) SendClientMessage(playerid, COLOR_WHITE, "USAGE: /fs [id]");
else if(IsPlayerConnected(ID) == 0) SendClientMessage(playerid, COLOR_RED, "Player is not connected");
else
{
new Float:health;
new Float, Float:y, Float:z, name[60], string[100];
GetPlayerPos(ID, x, y, z);
SetPlayerPos(ID, x, y, z+1);
GetPlayerHealth(ID,health);
SetPlayerHealth(ID, health-5);
format(string, 100, "You have slapped %s[%d]", name, ID);
SendClientMessage(playerid, COLOR_YELLOW, string);
}

return 1;
}
--------------------------------------------------------------------------------
your help will be greatly appreciated


Re: How to use a command with out puttin the person`s id - Scenario - 20.07.2011

You can loop through all players and see which player is the closest to you. Obtain that players ID and then perform the necessary actions, using the obtained ID. Make sense?


Re: How to use a command with out puttin the person`s id - MWhite_005 - 20.07.2011

yea it make sense but where can i get teh obtain id?


Re: How to use a command with out puttin the person`s id - dowster - 20.07.2011

thats an example of getting the closest hospital i use in my script, the variables are initialized outside of the loop, therefore they still exist outside of the for loop.
Код:
new Float:x, Float:y, Float:z, chospital, Float:sdistance;
GetPlayerPos( playerid, x, y, z);
for (new i = 0; i < MAX_HOSPITALS; i++)
	{
		if (i == 0)
		{
			sdistance = DISTANCE(x, y, z, Hospitals[i][0], Hospitals[i][1], Hospitals[i][2]);
			chospital = i;
		}
		else if (DISTANCE(x, y, z, Hospitals[i][0], Hospitals[i][1], Hospitals[i][2]) < sdistance)
		{
			sdistance = DISTANCE(x, y, z, Hospitals[i][0], Hospitals[i][1], Hospitals[i][2]);
			chospital = i;
		}
	}