SA-MP Forums Archive
How to make this afk command? - 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: How to make this afk command? (/showthread.php?tid=283336)



How to make this afk command? - rangerxxll - 14.09.2011

If I wanted to make a system where a player types /afk and gets teleported to a location, and cant move until he types /back (Also I want him to have unlimited health untill he types /back) Where would I start exactly? I currently have this.
pawn Код:
COMMAND:afk(playerid, cmdtext)
{
  if(afk[playerid] == 1) return SendClientMessage(playerid, blue, "You are already AFK!");
  {
    SetPlayerPos(playerid,  620.1089,892.7344,-37.1285);
    SendClientMessage(playerid, blue, "You are now AFK type /back to come back");
  }
  return 1;
}
What else do I need to do?


Re: How to make this afk command? - Kaperstone - 14.09.2011

Quote:
Originally Posted by rangerxxll
Посмотреть сообщение
If I wanted to make a system where a player types /afk and gets teleported to a location, and cant move until he types /back (Also I want him to have unlimited health untill he types /back) Where would I start exactly? I currently have this.
pawn Код:
COMMAND:afk(playerid, cmdtext)
{
  if(afk[playerid] == 1) return SendClientMessage(playerid, blue, "You are already AFK!");
  {
    SetPlayerPos(playerid,  620.1089,892.7344,-37.1285);
    SendClientMessage(playerid, blue, "You are now AFK type /back to come back");
  }
  return 1;
}
What else do I need to do?
pawn Код:
// Somewhere in your script
new oldHealth;
new oldArmour;
new Float:X,Float:Y,Float:Z,Float:Angle;
new Timer;
forward UH&A(playerid);

COMMAND:afk(playerid, cmdtext)
{
  if(afk[playerid] == 1) return SendClientMessage(playerid, blue, "You are already AFK!");
  {
    Timer = SetTimer("UH&A", 500, 1);
    GetPlayerHealth(playerid, oldHealth); // Get player old Armour
    GetPlayerArmour(playerid, oldArmour); // Get player old Health
    GetPlayerPos(playerid, X, Y, Z); // Get player old pos
    GetPlayerFacingAngle(playerid, Angle); // Get player old angle
    SetPlayerHealth(playerid, 999999999); // UNLIMITED ARMOUR!
    SetPlayerHealth(playerid, 999999999); // UNLIMITED HEALTH!
    SetPlayerPos(playerid,  620.1089,892.7344,-37.1285);
    SendClientMessage(playerid, blue, "You are now AFK type /back to come back");
    TogglePlayerControllable(playerid, 0); // freezeing the player | thats all :)
  }
  return 1;
}
COMMAND:back(playerid, cmdtext)
{
  if(afk[playerid] == 0) return SendClientMessage(playerid, blue, "You are not AFK!");
  {
    KillTimer(Timer);
    SetPlayerHealth(playerid, oldHealth); // set player old armour
    SetPlayerArmour(playerid, oldArmour); // set player old health
    SetPlayerPos(playerid, X, Y, Z); // Set player old pos
    SetPlayerFacingAngle(playerid, Angle); // Set player old facing angle
    SendClientMessage(playerid, blue, "You are now AFK type /back to come back");
    TogglePlayerControllable(playerid, 1); // unfreezeing player
  }
  return 1;
}
public UH&A(playerid)
{
SetPlayerHealth(playerid, 999999999); // UNLIMITED ARMOUR!
SetPlayerHealth(playerid, 999999999); // UNLIMITED HEALTH!
}



Re: How to make this afk command? - rangerxxll - 14.09.2011

Quote:
Originally Posted by xkirill
Посмотреть сообщение
pawn Код:
COMMAND:afk(playerid, cmdtext)
{
  if(afk[playerid] == 1) return SendClientMessage(playerid, blue, "You are already AFK!");
  {
    SetPlayerPos(playerid,  620.1089,892.7344,-37.1285);
    SendClientMessage(playerid, blue, "You are now AFK type /back to come back");
    TogglePlayerControllable(playerid, 0); // freezeing the player | thats all :)
  }
  return 1;
}
Now how would I make it so no one can kill the player that has been teleported?


Re: How to make this afk command? - Kaperstone - 14.09.2011

Quote:
Originally Posted by rangerxxll
Посмотреть сообщение
Now how would I make it so no one can kill the player that has been teleported?
check again


Re: How to make this afk command? - wouter0100 - 14.09.2011

pawn Код:
#include <a_samp>
#include <zcmd>

new afk[MAX_PLAYERS] = 0, Float:Pos[MAX_PLAYERS][3], Float:Health[MAX_PLAYERS], Float:Armor[MAX_PLAYERS];

COMMAND:afk(playerid, cmd[])
{
    if(afk[playerid] == 0)
    {
        GetPlayerHealth(playerid, Health[playerid]);
        GetPlayerArmour(playerid, Armor[playerid]);
        GetPlayerPos(playerid, Pos[playerid][0], Pos[playerid][1], Pos[playerid][2]);
        SetPlayerPos(playerid,  620.1089,892.7344,-37.1285);
        SetPlayerHealth(playerid, 9999999999999999999);
        SetPlayerArmour(playerid, 9999999999999999999);
        SendClientMessage(playerid, -1, "You are now AFK type /back to come back");
        TogglePlayerControllable(playerid, 0);
        afk[playerid] = 1;
    }else return SendClientMessage(playerid, -1, "You are already AFK!");
    return 1;
}

COMMAND:back(playerid, cmd[])
{
    if(afk[playerid] == 1)
    {
        SetPlayerPos(playerid,  Pos[playerid][0], Pos[playerid][1], Pos[playerid][2]);
        SetPlayerHealth(playerid, Health[playerid]);
        SetPlayerArmour(playerid, Armor[playerid]);
        SendClientMessage(playerid, -1, "You are back!");
        TogglePlayerControllable(playerid, 1);
        afk[playerid] = 0;
    }else return SendClientMessage(playerid, -1, "You are not AFK!");
    return 1;
}



Re: How to make this afk command? - rangerxxll - 14.09.2011

Quote:
Originally Posted by xkirill
Посмотреть сообщение
check again
Thanks lol. How do you think I can get there position back when they type /back? I already have
pawn Код:
enum _pos_data
{
    Float:X,
    Float:Y,
    Float:Z,
    Float:A,
};
pawn Код:
new pData[_pos_data];
And before you edited your post, I had
pawn Код:
COMMAND:afk(playerid, cmdtext)
{
  if(afk[playerid] == 1) return SendClientMessage(playerid, blue, "You are already AFK!");
  {
    GetPlayerPos(playerid, pData[X], pData[Y], pData[Z]);
    GetPlayerFacingAngle(playerid, pData[A]);
    SetPlayerPos(playerid,  620.1089,892.7344,-37.1285);
    SendClientMessage(playerid, blue, "You are now AFK type /back to come back");
    TogglePlayerControllable(playerid, 0);
  }
  return 1;
}
How can we make it so it gets there position now?


Re: How to make this afk command? - array13 - 14.09.2011

PHP код:
COMMAND:afk(playeridcmdtext

    if(
afk[playerid] == 1) return SendClientMessage(playeridblue"You are already AFK!"); 
    new 
Floatp[3]; 
    
GetPlayerPos(playeridp[0], p[1], p[2]); 
    
SetPlayerPos(playerid,  p[0], p[1], p[2]); 
    
TogglePlayerControllable(playerid0); 
    
SendClientMessage(playeridblue"You are now AFK type /back to come back"); 
    
SetPlayerVirtualWorld(playerid19999); 
    
afk[playerid] = 1
    return 
1
}   
COMMAND:back(playeridcmdtext

    if(
afk[playerid] == 0) return SendClientMessage(playeridblue"You are not AFK"); 
    new 
Float:p[3]; 
    
GetPlayerPos(playeridp[0], p[1], p[2]); 
    
SetPlayerPos(playeridp[0], p[1], p[2]); 
    
TogglePlayerControllable(playerid1); 
    
SendClientMessage(playeridblue"Welcome Back"); 
    
SetPlayerVirtualWorld(playerid0); 
    
afk[playerid] = 0
    return 
1




Re: How to make this afk command? - wouter0100 - 14.09.2011

@xkirill Better use mine, You forgot the [MAX_PLAYERS].
Example:
When player 1 types /afk.
His pos + health + armor get saved.
When player 2 types /afk.
His pos + health + armor get saved.
When player 1 types /back.
He got the armor, pos, health of player 2.

@kikito You are repos his location? wtf ;p


Re: How to make this afk command? - Kaperstone - 14.09.2011

Quote:
Originally Posted by wouter0100
Посмотреть сообщение
@xkirill Better use mine, You forgot the [MAX_PLAYERS].
Example:
When player 1 types /afk.
His pos + health + armor get saved.
When player 2 types /afk.
His pos + health + armor get saved.
When player 1 types /back.
He got the armor, pos, health of player 2.

@kikito You are repos his location? wtf ;p
oh...
thanks for the info

btw i have 666 posts >.<


Re: How to make this afk command? - rangerxxll - 14.09.2011

Quote:
Originally Posted by kikito
Посмотреть сообщение
PHP код:
COMMAND:afk(playeridcmdtext)
{
  if(
afk[playerid] == 1) return SendClientMessage(playeridblue"You are already AFK!");
  {
    new 
Floatp[3];
    
GetPlayerPos(playeridp[0], p[1], p[2]);
    
SetPlayerPos(playerid,  p[0], p[1], p[2]);
    
TogglePlayerControllable(playerid0);
    
SendClientMessage(playeridblue"You are now AFK type /back to come back");
    
SetPlayerVirtualWorld(playerid19999);
  }
  return 
1;

PHP код:
COMMAND:back(playeridcmdtext)
{
  if(
afk[playerid] == 0) return SendClientMessage(playeridblue"You're not afk!");
  {
    new 
Float:p[3];
    
GetPlayerPos(playeridp[0], p[1], p[2]);
    
SetPlayerPos(playeridp[0], p[1], p[2]);
    
TogglePlayerControllable(playerid1);
    
SendClientMessage(playeridblue"Welcome Back");
    
SetPlayerVirtualWorld(playerid0);
  }
  return 
1;

One little problem, when I do /afk and get frozen, then type /back it says I'm not afk.