SA-MP Forums Archive
Quick question for my afk system - 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: Quick question for my afk system (/showthread.php?tid=607759)



Quick question for my afk system - 1fret - 23.05.2016

Ok guys im making an afk system but i want it like this, if i type /afk it will set my health to 100000 for example which i already know how to do that but i want when the playe type /back the old health restores how can i do that.

And if there is any way to avoid when a player pause and another player cant kill them even when they dont type /afk please tell me or set a link where i can find a tutorial on it


Re: Quick question for my afk system - SyS - 23.05.2016

store the health to a variable before he goes to afk and give the health using that variable on /back


Re: Quick question for my afk system - Slawiii - 23.05.2016

store the health to a variable example
PHP код:

new hh//write this up
//this under AFK CMD
hh GetPlayerHealth(playerid);
//then 
//under back CMD
SetPlayerHealth(playeridhh); 



Re: Quick question for my afk system - SyS - 23.05.2016

Quote:
Originally Posted by Slawiii
Посмотреть сообщение
store the health to a variable example
PHP код:

new hh//write this up
//this under AFK CMD
hh GetPlayerHealth(playerid);
//then 
//under back CMD
SetPlayerHealth(playeridhh); 
Thats not going to work
i suggeset you ro use pvars


Re: Quick question for my afk system - Dayrion - 23.05.2016

Like this ?
PHP код:
new Float:afkHealth[MAX_PLAYER]
// AFK CMD | Get player health :
GetPlayerHealth(playeridafkHealth[playerid]);

// Restore health
SetPlayerHealth(playeridafkHealth[playerid]); 



Re: Quick question for my afk system - SyS - 23.05.2016

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Like this ?
PHP код:
new Float:afkHealth[MAX_PLAYER]
// AFK CMD | Get player health :
GetPlayerHealth(playeridafkHealth[playerid]);
// Restore health
SetPlayerHealth(playeridafkHealth[playerid]); 
that will work you can try it


Re: Quick question for my afk system - 1fret - 23.05.2016

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Like this ?
PHP код:
new Float:afkHealth[MAX_PLAYER]
// AFK CMD | Get player health :
GetPlayerHealth(playeridafkHealth[playerid]);
// Restore health
SetPlayerHealth(playeridafkHealth[playerid]); 
Ok i will be testing


Re: Quick question for my afk system - Dayrion - 23.05.2016

Uhm, you have to edit something. I did a mistake :
MAX_PLAYER » MAX_PLAYERS

PHP код:
new Float:afkHealth[MAX_PLAYERS
// AFK CMD | Get player health : 
GetPlayerHealth(playeridafkHealth[playerid]); 

// Restore health 
SetPlayerHealth(playeridafkHealth[playerid]); 



Re: Quick question for my afk system - 1fret - 23.05.2016

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
that will work you can try it
How Could i make it so if the player is /afk for 2-3 mins they get kick.
pawn Код:
CMD:afk(playerid,params[])
{
    if( pInfo[playerid][Spawned]    != 1)
    {
        ShowMessage(playerid, red, 9);
        return 1;
    }
    else
    {
        GetPlayerHealth(playerid, afkH[playerid]);
        TogglePlayerControllable(playerid,0);
        GetPlayerArmour(playerid, afkA[playerid]);
        SetPlayerHealth(playerid,300000);
        SetPlayerArmour(playerid,100000);
        AFK[playerid]++;
        SetTimer("AFKCheck",1000,1);
    }
    return 1;
}
CMD:back(playerid,params[])
{
    if( pInfo[playerid][Spawned]    != 1)
    {
        ShowMessage(playerid, red, 9);
        return 1;
    }
    else
    {
        TogglePlayerControllable(playerid,1);
        SetPlayerHealth(playerid, afkH[playerid]);
        SetPlayerArmour(playerid, afkA[playerid]);
        SendClientMessage(playerid,red,"Your status has been set to Playing.");
        AFK[playerid] =0;
    }
    return 1;
forward AFKCheck(playerid);
public AFKCheck(playerid)
{
    if(AFK[playerid] == 60)
    {
        AFK[playerid] = 0;
        format(astring,sizeof(astring),"Andre[BOT]: Player %s has been kicked. [Reason: Inactivity ]",GetName(playerid));
        SendClientMessageToAll(yellow,astring);
        SetTimerEx("KickPlayer",200,false,"d", playerid);
    }
}
}
Because i attempt it but doesnt work


Re: Quick question for my afk system - Dayrion - 23.05.2016

Try this :
PHP код:
CMD:afk(playerid,params[])
{
     if(
pInfo[playerid][Spawned] != 1)
    {
        
ShowMessage(playeridred9);
        return 
1;
    }
    else
     {
        
GetPlayerHealth(playeridafkH[playerid]);
        
TogglePlayerControllable(playerid,0);
        
GetPlayerArmour(playeridafkA[playerid]);
        
SetPlayerHealth(playerid,300000);
        
SetPlayerArmour(playerid,100000);
        
AFK[playerid]++;
        
SetTimerEx("AFKCheck"60000,false,"i"playerid);
        return 
1;
    }
}
CMD:back(playerid,params[])
{
    if(
pInfo[playerid][Spawned] != 1)
    {
        
ShowMessage(playeridred9);
        return 
1;
    }
    else
    {
        
TogglePlayerControllable(playerid,1);
        
SetPlayerHealth(playeridafkH[playerid]);
        
SetPlayerArmour(playeridafkA[playerid]);
        
SendClientMessage(playerid,red,"Your status has been set to Playing.");
        
AFK[playerid] = 0;
        return 
1;
    }
}
forward AFKCheck(playerid);
public 
AFKCheck(playerid)
{
    if(
AFK[playerid] == 1)
    {
        
AFK[playerid] = 0;
        
format(astring,sizeof(astring),"Andre[BOT]: Player %s has been kicked. [Reason: Inactivity ]",GetName(playerid));
        
SendClientMessageToAll(yellow,astring);
        
SetTimerEx("KickPlayer",200,false,"d"playerid);
        return 
1;
    }
    else return 
printf("[Error] Can't check the afk status of %s (ID:%i)"GetName(playerid), playerid);

- Added an error message.