17.03.2013, 22:20
Hello guys ! In this short tutorial, I will talk about a simple AFK system which you can make it better if you want by adding a few lines to it. Let's start with our includes then !
At the top of our script there must be
You can add more includes if you need other includes for your other systems. But a_samp will be enough for our simple AFK system. So let's start ! After of
Add
So it shall look like this:
Next, we are going to define string. Below of
Add this
So our top of the script shall look like this now:
So we are done with the top of our script. Hope i explained well.. Now we are going to play with OnPlayerConnect. Search for
in your pawno and add this under of it
So it shall look like this now:
Now we are ready with everything, let's make our conmand then !
Search for
This time. And add this under of it
This means if a player types /afk in game... So let's continue our code.
Sorry if there is any mistakes or grammatical mistakes, i am in phone plus i am sleepy right now. Hope this helps, feel free to ask anywhere you didnt understand or looking for a support to make this script bigger ... Also tell me if there is any bug please. Have fun !
At the top of our script there must be
pawn Код:
#include <a_samp>
pawn Код:
#include <a_samp>
pawn Код:
new isAFK[MAX_PLAYERS]; // We will edit this soon to tell the server whether a player is AFK or not, this is just a definition before telling so.
pawn Код:
#include <a_samp>
new isAFK[MAX_PLAYERS]; // We will edit this soon to tell the server whether a player is AFK or not, this is just a definition before telling so.
pawn Код:
new isAFK[MAX_PLAYERS];
pawn Код:
new string[128]; // This tells the script my text will be max. 128 bits, you can make it larger or lower for your needs...
pawn Код:
#include <a_samp>
new isAFK[MAX_PLAYERS]; // We will edit this soon to tell the server whether a player is AFK or not, this is just a definition before telling so.
new string[128]; // This tells the script my text will be max. 128 bits, you can make it larger or lower for your needs ...
pawn Код:
public OnPlayerConnect
pawn Код:
isAFK[playerid] = 0; // Setting player's AFK state to 0(false) to avoid bugs
pawn Код:
public OnPlayerConnect(blablabla)
{
isAFK[playerid] = 0; // Setting player's AFK state to 0(false) to avoid bugs on their connection period
return 1;
}
Search for
pawn Код:
public OnPlayerCommandText
pawn Код:
if(strcmp("/afk", cmdtext, true, 10) == 0)
{
pawn Код:
if(strcmp("/afk", cmdtext, true, 10) == 0)
{
new Name[MAX_PLAYER_NAME]; // Defining the Player's Name
GetPlayerName(playerid, Name, sizeof(Name));
if (isAFK[playerid] == 0) // if the player is NOT AFK
{
isAFK[playerid] = 1; // Turning his state to AFK mode
format( string, sizeof(string), "%s is AFK !", Name); // Formatting the message to be sended
SendClientMessageToAll(yourcolorhere , string); // Sends message to everyone to inform he is AFK, put a color in yourcolorhere part of this code to make it work.
}
else { // if the player is already AFK
isAFK[playerid] = 0; // Turning his state to NO-AFK mode
format( string, sizeof(string), "%s is back!", Name); // Formatting the message to be sended
SendClientMessageToAll(yourcolorhere, string); // Sends message to inform he is back , put a color in yourcolorhere part of this code to make it work.
}
return 1;
}
