SA-MP Forums Archive
Command problem - 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: Command problem (/showthread.php?tid=475437)



Command problem - Tuntun - 13.11.2013

I made a afk system but when we use /afk we can type /again again... but it should be show : "You're already afk."
So will never can type /afk more than 1 time. or /back. for an example:
my script:
Код:
CMD:back(playerid, params [])
{
    new string[129], pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pName,MAX_PLAYER_NAME);
    SendClientMessage(playerid, COLOR_MATI, "You are no longer AFK.");
    format(string,sizeof string, "%s is back from AFK!",pName);
    SendClientMessageToAll(0xFF0000AA,string);
    TogglePlayerControllable(playerid, 1);
    return 1;
}
CMD:afk(playerid, params[], help)
{
        new reason[64];
        if(sscanf(params,"s[64]", reason)) return SendClientMessage(playerid, COLOR_MATI, "USAGE: /afk [reason]");
        TogglePlayerControllable(playerid, 0);
        new string[64], pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
        format(string, sizeof(string), "%s is now AFK Reason: %s.",pName, reason);
        SendClientMessageToAll(0xFF0000AA,string);
        return 1;
}





Re: Command problem - DobbysGamertag - 13.11.2013

I guess you don't know what variables are?


Re: Command problem - PakistaniBaba - 13.11.2013

Код:
CMD:back(playerid, params [])
{
    new string[129], pName[MAX_PLAYER_NAME];
    SendClientMessage(playerid, COLOR_MATI, "You are no longer AFK.");
    GetPlayerName(playerid,pName,MAX_PLAYER_NAME);
    format(string,sizeof string, "%s is back from AFK!",pName);
    SendClientMessageToAll(0xFF0000AA,string);
    TogglePlayerControllable(playerid, 1);
    return 1;
}
CMD:afk(playerid, params[], help)
{
        if(AFK[playerid] == 1)
        {
        return SendClientMessage(playerid,COLOR_RED,"You're Already In AFK");
        }
        new reason[64];
        if(sscanf(params,"s[64]", reason)) return SendClientMessage(playerid, COLOR_MATI, "USAGE: /afk [reason]");
        TogglePlayerControllable(playerid, 0);
        new string[64], pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
        format(string, sizeof(string), "%s is now AFK Reason: %s.",pName, reason);
        SendClientMessageToAll(0xFF0000AA,string);
        return 1;
}
Check This!!!!


Re: Command problem - iFiras - 13.11.2013

On top of your script:
pawn Код:
new IsAfk[MAX_PLAYERS];
OnPlayerConnect:
pawn Код:
public OnPlayerConnect(playerid)
{
IsAfk[playerid]=0;
return 1;
}
OnPlayerDisconnect:
pawn Код:
public OnPlayerDisconnect(playerid)
{
IsAfk[playerid] =0;
}
In the /afk & /back cmds:
pawn Код:
CMD:back(playerid, params [])
{
    new string[129], pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pName,MAX_PLAYER_NAME);
    if(IsAfk[playerid] == 0) return SendClientMessage(playerid,COLOR_RED,"ERROR: You are not AFK.");
    SendClientMessage(playerid, COLOR_MATI, "You are no longer AFK.");
    format(string,sizeof string, "%s is back from AFK!",pName);
    SendClientMessageToAll(0xFF0000AA,string);
    TogglePlayerControllable(playerid, 1);
     IsAfk[playerid] =0;
    return 1;
}
CMD:afk(playerid, params[], help)
{
        new reason[64];
        if(IsAfk[playerid] == 1) return SendClientMessage(playerid,COLOR_RED,"ERROR: You're already AFK.");
        if(sscanf(params,"s[64]", reason)) return SendClientMessage(playerid, COLOR_MATI, "USAGE: /afk [reason]");
        TogglePlayerControllable(playerid, 0);
        new string[64], pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
        format(string, sizeof(string), "%s is now AFK Reason: %s.",pName, reason);
        SendClientMessageToAll(0xFF0000AA,string);
        IsAfk[playerid] =1;
        return 1;
}



Re: Command problem - PakistaniBaba - 13.11.2013

Quote:
Originally Posted by iFiras
Посмотреть сообщение
On top of your script:
pawn Код:
new IsAfk[MAX_PLAYERS];
OnPlayerConnect:
pawn Код:
public OnPlayerConnect(playerid)
{
IsAfk[playerid]=0;
return 1;
}
OnPlayerDisconnect:
pawn Код:
public OnPlayerDisconnect(playerid)
{
IsAfk[playerid] =0;
}
In the /afk & /back cmds:
pawn Код:
CMD:back(playerid, params [])
{
    new string[129], pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pName,MAX_PLAYER_NAME);
    if(IsAfk[playerid] == 0) return SendClientMessage(playerid,COLOR_RED,"ERROR: You are not AFK.");
    SendClientMessage(playerid, COLOR_MATI, "You are no longer AFK.");
    format(string,sizeof string, "%s is back from AFK!",pName);
    SendClientMessageToAll(0xFF0000AA,string);
    TogglePlayerControllable(playerid, 1);
     IsAfk[playerid] =0;
    return 1;
}
CMD:afk(playerid, params[], help)
{
        new reason[64];
        if(IsAfk[playerid] == 1) return SendClientMessage(playerid,COLOR_RED,"ERROR: You're already AFK.");
        if(sscanf(params,"s[64]", reason)) return SendClientMessage(playerid, COLOR_MATI, "USAGE: /afk [reason]");
        TogglePlayerControllable(playerid, 0);
        new string[64], pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
        format(string, sizeof(string), "%s is now AFK Reason: %s.",pName, reason);
        SendClientMessageToAll(0xFF0000AA,string);
        IsAfk[playerid] =1;
        return 1;
}
Full Stuff!!!
Good


Re: Command problem - Tuntun - 13.11.2013

Код:
E:\Current server\18WoS\gamemodes\18WoS.pwn(327) : error 017: undefined symbol "IsAfk"
E:\Current server\18WoS\gamemodes\18WoS.pwn(433) : error 017: undefined symbol "IsAfk"
E:\Current server\18WoS\gamemodes\18WoS.pwn(1697) : error 017: undefined symbol "COLOR_RED"
E:\Current server\18WoS\gamemodes\18WoS.pwn(1702) : warning 217: loose indentation
E:\Current server\18WoS\gamemodes\18WoS.pwn(1703) : warning 217: loose indentation
E:\Current server\18WoS\gamemodes\18WoS.pwn(1708) : error 017: undefined symbol "COLOR_RED"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.



Re: Command problem - iFiras - 13.11.2013

Put this:
pawn Код:
#define COLOR_RED 0xFF0000AA
Then this:
pawn Код:
#pragma tabsize 0
Did you put
pawn Код:
new IsAfk[MAX_PLAYERS];
??


Re: Command problem - DobbysGamertag - 13.11.2013

@iFiras never ever ever ever use pragma tabsize 0 it hides obvious errors.

@Tuntun here use this, compiles fine.

pawn Код:
#include a_samp
#include zcmd

new AFK[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    AFK[playerid]=0;
    return 1;
}

CMD:afk(playerid,params[])
{
    if(AFK[playerid]==1)return SendClientMessage(playerid,-1,"ERROR: You are already AFK");
    AFK[playerid]=1;
    new name[24],string[124];
    GetPlayerName(playerid,name,24);
    format(string,124,"%s is AFK %s");
    SendClientMessageToAll(-1,string);
    return 1;
}
CMD:back(playerid,params[])
{
    if(AFK[playerid]==0)return SendClientMessage(playerid,-1,"ERROR: You arent AFK");
    AFK[playerid]=0;
    new name[24],string[124];
    GetPlayerName(playerid,name,24);
    format(string,124,"%s is back",name);
    SendClientMessageToAll(-1,string);
    return 1;
}
It should work unless i've derped.


Re: Command problem - iFiras - 13.11.2013

Quote:
Originally Posted by DobbysGamertag
Посмотреть сообщение
@iFiras never ever ever ever use pragma tabsize 0 it hides obvious errors.
No, it removes loose indenation warnings...I use it in my script.


Re: Command problem - DobbysGamertag - 13.11.2013

Quote:
Originally Posted by iFiras
Посмотреть сообщение
No, it removes loose indenation warnings...I use it in my script.
Sorry to sound harsh, but you must be one hell of a sh*t coder if you can't indent properly. It will and does throw warnings for loose indentation, remove the pragma, you'll be amazed at how amazing and neat your code looks.