SA-MP Forums Archive
Use a command on dead players - 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: Use a command on dead players (/showthread.php?tid=510668)



Use a command on dead players - Ananisiki - 02.05.2014

I have a command there i want to do so only it can be used on dead people, if the player is alive and he type the command like


/restinpiece id/nick

he will get a msg like

%s is alive, you cant use this command


Re: Use a command on dead players - Abagail - 02.05.2014

pawn Код:
CMD:restinpeace(playerid, params[])
{
new giveplayerid = GetClosestPlayer(playerid, 10.0);
if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Your not near anyone.");
if(pDead[giveplayerid] == 0) {
new string[128];
format(string, sizeof(string), "%s is alive, you cant use this command.");
return SendClientMessage(playerid, -1, string);
}
// Put the code here
return 1;
}

stock GetClosestPlayer(playerid,Float:limit)
{
    new Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2;
    GetPlayerPos(playerid,x1,y1,z1);
    new Float:Range = 999.9;
    new id = -1;
    foreach(Player,i)
    {
        if(playerid != i)
        {
            GetPlayerPos(i,x2,y2,z2);
            new Float:Dist = GetDistanceBetweenPoints(x1,y1,z1,x2,y2,z2);
            if(floatcmp(Range,Dist) == 1 && floatcmp(limit,Range) == 1)
            {
                Range = Dist;
                id = i;
            }
        }
    }
    return id;
}
The code for GetClosestPlayer is not my scripting and was found on a post by cessil.(Source: https://sampforum.blast.hk/showthread.php?tid=202122)

Just ask if you want it with sscanf...


Re: Use a command on dead players - Ananisiki - 02.05.2014

not what am looking for


Re: Use a command on dead players - ic3cr3am - 02.05.2014

PHP код:
#include <a_samp>
new DEAD[MAX_PLAYERS];
public 
OnPlayerConnect(playerid)
{
    
DEAD[playerid] = 0;//player is alive
    
return 1;
}
public 
OnPlayerSpawn(playerid)
{
    
DEAD[playerid] = 0;//player is alive
    
return 1;
}
public 
OnPlayerDeath(playeridkilleridreason)
{
    
DEAD[playerid] = 1;//player is dead
    
return 1;
}
public 
OnPlayerCommandText(playeridcmdtext[])
{
    if(
DEAD[playerid] == 1)
    {
        
//dead commands
        
if (strcmp("/mycommand"cmdtexttrue10) == 0)
        {
            return 
1;
        }
    }
    else
    {
        
//alive commands
        
if (strcmp("/mycommand"cmdtexttrue10) == 0)
        {
        }
    }
     return 
0;




Re: Use a command on dead players - Ananisiki - 02.05.2014

um?


Re: Use a command on dead players - Aerotactics - 02.05.2014

Quote:
Originally Posted by Ananisiki
Посмотреть сообщение
um?
I hate it when people post here wanting a script made for them. Both the previous helpers posted scripts that both work. They did exactly what you asked for.


Re: Use a command on dead players - DobbysGamertag - 02.05.2014

Use:

pawn Код:
if(GetPlayerState(id) == PLAYER_STATE_WASTED)
"id" being the target you'd use in the command.