/afk and /back commands
#1

Hi people,

today I've encountered a bug in my script.

You can type as many /afk's as you want to and showing them.
Could someone make it like when you typed /afk once you can't type it again till you've done /back?

code:
pawn Код:
COMMAND:afk(playerid, params[])  
{  
    if (APlayerData[playerid][LoggedIn] == true)  
    {  
        SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}You are afk, when you come back, do /back");  
        TogglePlayerControllable(playerid,0);    

        new string3[160];  
        new name[MAX_PLAYER_NAME];  
        GetPlayerName(playerid, name, sizeof(name));  
   
        format(string3, sizeof(string3), "{FF6600}%s {FFFFFF}is now AFK - {FF6600}%s", name, params);  
        SendClientMessageToAll(0xFFFFFFFF, string3);  
    }  
    return 1;  
}
 
COMMAND:back(playerid, params[])  
{  
    if (APlayerData[playerid][LoggedIn] == true)  
    {  
        SendClientMessage(playerid, 0xFFFFFFFF, "Welcome Back!!");  
        TogglePlayerControllable(playerid,1);    
        SetPlayerFacingAngle(playerid, 180);  

        new string3[70];  
        new name[MAX_PLAYER_NAME];  
        GetPlayerName(playerid, name, sizeof(name));  
   
        format(string3, sizeof(string3), "{FF6600}%s {FFFFFF}is back from being afk!", name);  
        SendClientMessageToAll(0xFFFFFFFF, string3);  
    }  
    return 1;  
}
Thanks

-SomebodyAndMe
Reply
#2

Hey,

Sorry but how is this a bug? You will need to create a variable for when a player becomes AFK.

-Mike
Reply
#3

Untested:

EDIT: Like Mike said, it's not a bug, you need to create a variable.

pawn Код:
// top of script

new IsAFK[MAX_PLAYERS];

// new /afk command

COMMAND:afk(playerid, params[])
{
    if (APlayerData[playerid][LoggedIn] == true)
    {
        if(IsAFK[playerid] == 0)
        {
            SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}You are afk, when you come back, do /back");
            TogglePlayerControllable(playerid,0);

            new string3[160];
            new name[MAX_PLAYER_NAME];
            GetPlayerName(playerid, name, sizeof(name));

            format(string3, sizeof(string3), "{FF6600}%s {FFFFFF}is now AFK - {FF6600}%s", name, params);
            SendClientMessageToAll(0xFFFFFFFF, string3);
           
            IsAFK[playerid] = 1;
        } else return SendClientMessage(playerid,-1,"You Are Already Away From Keyboard.");
    }
    return 1;
}

// new /back command

COMMAND:back(playerid, params[])
{
    if (APlayerData[playerid][LoggedIn] == true)
    {
        if(IsAFK[playerid] == 1)
        {
            SendClientMessage(playerid, 0xFFFFFFFF, "Welcome Back!!");
            TogglePlayerControllable(playerid,1);
            SetPlayerFacingAngle(playerid, 180);

            new string3[70];
            new name[MAX_PLAYER_NAME];
            GetPlayerName(playerid, name, sizeof(name));

            format(string3, sizeof(string3), "{FF6600}%s {FFFFFF}is back from being afk!", name);
            SendClientMessageToAll(0xFFFFFFFF, string3);
           
            IsAFK[playerid] = 0;
        } else return SendClientMessage(playerid,-1,"You Are Not Away From Keyboard.");
    }
    return 1;
}
Reply
#4

Quote:
Originally Posted by grand.Theft.Otto
Посмотреть сообщение
Untested:

EDIT: Like Mike said, it's not a bug, you need to create a variable.

pawn Код:
// top of script

new IsAFK[MAX_PLAYERS];

// new /afk command

COMMAND:afk(playerid, params[])
{
    if (APlayerData[playerid][LoggedIn] == true)
    {
        if(IsAFK[playerid] == 0)
        {
            SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}You are afk, when you come back, do /back");
            TogglePlayerControllable(playerid,0);

            new string3[160];
            new name[MAX_PLAYER_NAME];
            GetPlayerName(playerid, name, sizeof(name));

            format(string3, sizeof(string3), "{FF6600}%s {FFFFFF}is now AFK - {FF6600}%s", name, params);
            SendClientMessageToAll(0xFFFFFFFF, string3);
           
            IsAFK[playerid] = 1;
        } else return SendClientMessage(playerid,-1,"You Are Already Away From Keyboard.");
    }
    return 1;
}

// new /back command

COMMAND:back(playerid, params[])
{
    if (APlayerData[playerid][LoggedIn] == true)
    {
        if(IsAFK[playerid] == 1)
        {
            SendClientMessage(playerid, 0xFFFFFFFF, "Welcome Back!!");
            TogglePlayerControllable(playerid,1);
            SetPlayerFacingAngle(playerid, 180);

            new string3[70];
            new name[MAX_PLAYER_NAME];
            GetPlayerName(playerid, name, sizeof(name));

            format(string3, sizeof(string3), "{FF6600}%s {FFFFFF}is back from being afk!", name);
            SendClientMessageToAll(0xFFFFFFFF, string3);
           
            IsAFK[playerid] = 0;
        } else return SendClientMessage(playerid,-1,"You Are Not Away From Keyboard.");
    }
    return 1;
}
Thanks, these errors i get:
Код:
C:\Users\Barbara\Desktop\SAMP Kevin\hoi\gamemodes\PPC_Trucking.pwn(22) : error 017: undefined symbol "MAX_PLAYERS"
C:\Users\Barbara\Desktop\SAMP Kevin\hoi\gamemodes\PPC_Trucking.pwn(22) : error 009: invalid array size (negative, zero or out of bounds)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
"new IsAFK[MAX_PLAYERS];"
Is on top of my script.
Reply
#5

Epic.

1. Make sure the new IsAFK[MAX_PLAYERS] is UNDER your defines / includes.

2. If it is already, urscrewed.
Reply
#6

Fixed it already thanks for the help.
Reply
#7

I know it's fixed, but you can also do this instead of using the default MAX_PLAYERS from a_samp:

pawn Код:
#define MAX_SLOTS 10 // max of 10 people aloud in your server for example
Then, instead of

pawn Код:
new IsAFK[MAX_PLAYERS];
You can do:

pawn Код:
new IsAFK[MAX_SLOTS];
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)