SA-MP Forums Archive
[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(playeridparams[])
    {
        
SetPlayerHealth(playerid100);
           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(playeridparams[])
{
    new 
i;
    for(; 
MAX_PLAYERS; ++i)
    {
        if(
IsPlayerConnected(playerid))
       {
            new 
Float:XFloat:YFloat:Z;
            
GetPlayerPos(playeridXYZ);
            if(
IsPlayerInRangeOfPoint(iXYZ5.0))
            {
                 
SetPlayerHealth(iGetPlayerHealth(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(playeridparams[])
{
    new 
Float:XFloat:YFloat:Z;
    
GetPlayerPos(playeridXYZ);
    for(new 
iMAX_PLAYERSi++)
    {
            if(
IsPlayerInRangeOfPoint(i5.0XYZ))
                 
SetPlayerHealth(i100.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