[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
#2

Nice script ty! +rep!!
Reply
#3

Horrible indentation.. also there is no point using [256] strings, because max clientmessage is like 144 characters or something like that. Well 3/10 for the effort.
Reply
#4

Awful indentation and optimization, bad explained, already posted and in my opinion is useless.
Reply
#5

Quote:
Originally Posted by Dan.
View Post
Horrible indentation.. also there is no point using [256] strings, because max clientmessage is like 144 characters or something like that. Well 3/10 for the effort.
The max clientmessage is actually 128 , and for the tutorial, it's not organized, not explained ( specialy the loop), or with other words this is copy / paste tutorial you don't learn nothing

P.S. Use [pawn] [./pawn] tags
Reply
#6

Error founded:

pawn 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;
}
To:

pawn Code:
if(strcmp(cmdtext,"/afklist",true) == 0)
{
          for(new i = 0; i < MAX_PLAYERS; i++)
          {
                  new name[MAX_PLAYER_NAME], string[50];
                  GetPlayerName(i,name,sizeof(name));
                   format(string,sizeof(string),"AFK Set Player : %s (id : %i)",name,i);
         }
            SendClientMessage(playerid,0xFF0000FF,string);
       return 1;
}
Reply
#7

Quote:

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,0xFF0000FF,string);
return 1;
}

error 017: undefined symbol "string"
Reply
#8

yeah sorry it was my first tutorial created...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)