PDA

View Full Version : Command problem


Tuntun
13/11/2013, 06:22 AM
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;
}
http://i.imgur.com/bZGaSRc.png
http://i.imgur.com/U10gUc1.png
http://i.imgur.com/rOepD0V.png

DobbysGamertag
13/11/2013, 06:25 AM
I guess you don't know what variables are?

PakistaniBaba
13/11/2013, 06:26 AM
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!!!!

iFiras
13/11/2013, 06:29 AM
On top of your script:
new IsAfk[MAX_PLAYERS];
OnPlayerConnect:
public OnPlayerConnect(playerid)
{
IsAfk[playerid]=0;
return 1;
}
OnPlayerDisconnect:
public OnPlayerDisconnect(playerid)
{
IsAfk[playerid] =0;
}
In the /afk & /back cmds:
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;
}

PakistaniBaba
13/11/2013, 06:32 AM
On top of your script:
new IsAfk[MAX_PLAYERS];
OnPlayerConnect:
public OnPlayerConnect(playerid)
{
IsAfk[playerid]=0;
return 1;
}
OnPlayerDisconnect:
public OnPlayerDisconnect(playerid)
{
IsAfk[playerid] =0;
}
In the /afk & /back cmds:
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 :)

Tuntun
13/11/2013, 06:34 AM
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 (c) 1997-2006, ITB CompuPhase


4 Errors.

iFiras
13/11/2013, 06:37 AM
Put this:
#define COLOR_RED 0xFF0000AA
Then this:
#pragma tabsize 0
Did you put
new IsAfk[MAX_PLAYERS];??

DobbysGamertag
13/11/2013, 06:40 AM
@iFiras never ever ever ever use pragma tabsize 0 it hides obvious errors.

@Tuntun here use this, compiles fine.


#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.

iFiras
13/11/2013, 06:42 AM
@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.

DobbysGamertag
13/11/2013, 06:52 AM
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.

Tuntun
13/11/2013, 06:52 AM
Dobby your script:

E:\Current server\18WoS\pawno\include\PPC_DefLocations.inc(16 1) : error 029: invalid expression, assumed zero
E:\Current server\18WoS\pawno\include\PPC_DefLocations.inc(16 1) : error 008: must be a constant expression; assumed zero
E:\Current server\18WoS\gamemodes\18WoS.pwn(327) : error 017: undefined symbol "AFK"
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


3 Errors.

DobbysGamertag
13/11/2013, 06:58 AM
Oh god >_< PPC Trucking. Just add it to each part as it is shown in the code. Should work. But if i remember rightly, PPC is a mess of includes. Add it to a filterscript and just load it o_o make your job easier.

Chasm
13/11/2013, 09:04 AM
God guys. Use this, I just made it. Works perfectly.

CMD:afk(playerid, params[])
{
if(IsPlayerAFK[playerid] == 1) return SendClientMessage(playerid, 0xFFFFFFFF, "{F20051}ERROR{FFFFFF}: You are already AFK. Use /back to play again.");
new PlayersName[MAX_PLAYER_NAME], Reason[24], String[64];
if(sscanf(params, "s[64]", Reason)) return SendClientMessage(playerid, 0xFFFFFFFF, "{F20051}USAGE{FFFFFF}: /afk [reason]");
GetPlayerName(playerid, PlayersName, sizeof(PlayersName));
format(String, sizeof(String), "{66D41E}%s is now in AFK mode. Reason: %s.", PlayersName, Reason);
TogglePlayerControllable(playerid, 0);
SetPlayerVirtualWorld(playerid, 1);
SetPlayerHealth(playerid, 9999);
SendClientMessageToAll(-1, String);
IsPlayerAFK[playerid] = 1;
return 1;
}

CMD:back(playerid, params[])
{
if(IsPlayerAFK[playerid] == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "{F20051}ERROR{FFFFFF}: You are not currently AFK.");
new PlayersName[MAX_PLAYER_NAME], String[32];
GetPlayerName(playerid, PlayersName, sizeof(PlayersName));
format(String, sizeof(String), "{14BAA7}%s is now back.", PlayersName);
TogglePlayerControllable(playerid, 1);
SetPlayerVirtualWorld(playerid, 0);
SetPlayerHealth(playerid, 100);
SendClientMessageToAll(-1, String);
IsPlayerAFK[playerid] = 0;
return 1;
}

Oh yeah, add this top of your script.

new IsPlayerAFK[MAX_PLAYERS];

Define these 3 colours.

0xF20051FF
0x66D41EFF
0x14BAA7FF