[Tutorial] AFK System
#1

Hello World I'm new on scripting so i don't know very good how to script
But I had learned how to make a AFK system so ...i will learn you how to make this
First: we create a variable: and add it in top of scripts!

Code:
 new AFK[MAX_PLAYERS];
This will help us to see if player is afk or if isn't.

now go to public OnPlayerConnect , if you don't know where PRESS ctrl + f and write OnPlayerConnect in the box

after you find it, type next functions between
Code:
{
    AFK[playerid] = 0;
  return 1;
}
Now we gonna make 3 commands, /afk, /back, /afklist if you use zcmd, or foreach wil be more easily to do it

now go to OnPlayerCommandText(playerid,cmdtext[])
and write next between {
}
we create first the /afk command
Code:
          if(strcmp(cmdtext, "/afk", true) == 0)
         {
             if(AFK[playerid] == 1) return SendClientMessage(playerid,-1,"You are already AFK"); //verify if the player is afk if is will send a message
                  AFK[playerid] = 1;// set AFK as on. for player..
                       new name[MAX_PLAYER_NAME], string[256]; // create variable for player called name and string for message and more..
                               GetPlayerName(playerid,name,sizeof(name)); // now setting NAme as the name of the player
                                      format(string,sizeof(string), "[AFK]%s",name);
                                      SetPlayerName(playerid,string); // set the name with AFK when he type /afk
                                          SetPlayerColor(playerid,-1); // set the  color of the player to white
                                        SetPlayerWeather(playerid,-1); // setting the weather to -1 to create a real AFK effect
                                         TogglePlayerControllable(playerid,0);       //frezeze the player                              
         }
/brb cmd
Code:
          if(strcmp(cmdtext,"/back",true) == 0)
             {
             if(AFK[playerid] == 0) return SendClientMessage(playerid,-1,"You are not AFK"); //verify if the player is afk if is not will send a message
                     else
                    {
                  AFK[playerid] = 0;// set AFK as off. for player..
                       new name[MAX_PLAYER_NAME], string[256]; // create variable for player called name and string for message and more..
                               GetPlayerName(playerid,name,sizeof(name)); // now setting NAme as the name of the player
                                      format(string,sizeof(string), "%s",name);
                                      SetPlayerName(playerid,string); // set the name to his/hi normal name
                                          SetPlayerColor(playerid,-1); // set the  color of the player to white
                                        SetPlayerWeather(playerid,-2); // setting the weather to 2 for nice weather
                                         TogglePlayerControllable(playerid,1);           //unfreeze the player      
               }    
                return 1;
         }
now create the /afklist cmd

Code:
if(strcmp(cmdtext,"/afklist",true) == 0)
{
          for(new i = 0; i != MAX_PLAYERS; i++)
          {
                  new name[MAX_PLAYER_NAME], string[256];
                  GetPlayerName(i,name,sizeof(name));
                   format(string,sizeof(string),"AFK Set Player : %s (id : %i)",name,playerid);
         }
            SendClientMessage(playerid,-1,string);
       return 1;
}
Now i hope this had helped you
I'm not a crazy rep + man so if you want to rep or not is

If i did some mistake just comment
Above is the link for script
http://pastebin.com/BSUqzhG0
Reply


Messages In This Thread
How to make AFK script - by XStormiest - 26.06.2012, 08:35
Re: AFK System - by [M.A]Angel[M.A] - 31.07.2012, 14:34
Re: AFK System - by Dan. - 31.07.2012, 16:27
Respuesta: AFK System - by CaptainMactavish - 31.07.2012, 19:05
Re: AFK System - by MarTaTa - 01.08.2012, 06:17
Re: AFK System - by Tigerkiller - 02.08.2012, 20:17
Re: AFK System - by Squirrel - 02.08.2012, 21:36
Re: AFK System - by XStormiest - 04.08.2012, 17:21

Forum Jump:


Users browsing this thread: 1 Guest(s)