[Help]Life - 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: [Help]Life (
/showthread.php?tid=594670)
[Help]Life -
BrnFec - 21.11.2015
someone help me do cmd: life for whom this near
Код:
CMD:lifep(playerid, params[])
{
for(new i=0;i<MAX_PLAYERS;i++)
SetPlayerHealth(i, 100);
return true;
}
is giving life to all the server
Re: [Help]Life -
N0FeaR - 21.11.2015
Try this
PHP код:
CMD:lifep(playerid, params[])
{
SetPlayerHealth(playerid, 100);
return 1;
}
Re: [Help]Life -
Detoria - 21.11.2015
He said that he wants to give health for everyone who's near the player who did the command.
PHP код:
CMD:lifep(playerid, params[])
{
new i;
for(; i < MAX_PLAYERS; ++i)
{
if(IsPlayerConnected(playerid))
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
if(IsPlayerInRangeOfPoint(i, X, Y, Z, 5.0))
{
SetPlayerHealth(i, GetPlayerHealth(i)+100.0);
}
}
}
return 1;
}
Remember, when you create a variable, It's value is zero, It will have another value only if you set it to another value, and try to create a variable to use on "for's" before using It, It's faster that way.
Re: [Help]Life -
PrO.GameR - 22.11.2015
Detoria's code is well ... flawed to the point of not working, I'll try to optimize and fix it
but credits to him for trying
PHP код:
CMD:lifep(playerid, params[])
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
for(new i; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i, 5.0, X, Y, Z))
SetPlayerHealth(i, 100.0);
}
return 1;
}
A couple notes ^
A) when a player does the cmd, he IS connected, there is no need to check
B) natives have a built-in connected check, so just use SetPlayerHealth, if it fails he is not connected