Help in AFK System
#1

Hello Guys!
I want to make AFK(Away From Keyboard) System but if player have wanted level then he dont go AFK this system I want but when I compile it it shows these errors
Код:
C:\Users\XGamerZ\Desktop\afk.pwn(15) : error 010: invalid function or declaration
C:\Users\XGamerZ\Desktop\afk.pwn(21) : error 028: invalid subscript (not an array or too many subscripts): "playerid"
C:\Users\XGamerZ\Desktop\afk.pwn(21) : warning 215: expression has no effect
C:\Users\XGamerZ\Desktop\afk.pwn(21) : error 001: expected token: ";", but found "]"
C:\Users\XGamerZ\Desktop\afk.pwn(21) : error 029: invalid expression, assumed zero
C:\Users\XGamerZ\Desktop\afk.pwn(21) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Errors.
Please help me!
I will be very thankful to you
Here is my AFK System
Код:
#include a_samp
#include zcmd

#define COLOR_BLUE 0x375FFFFF
#define COLOR_WHITE 0xFFFFFFAA



#define afkdialog 1165

new afk[MAX_PLAYERS];

new Text3D:label[MAX_PLAYERS];
new wantedlevel;
wantedlevel = GetPlayerWantedLevel(playerid);

CMD:afk(playerid,params[])
{
    if(afk[playerid] == 0)
    {
       if(playerid[wantedlevel] > 0)
       {
    	 ShowPlayerDialog(playerid, afkdialog, DIALOG_STYLE_INPUT, "{FF0000}Reason:", "{FFFF00}Please Type Reason of going AFK Below.", "Done", "Cancel");
       }
       else
       {
          SendClientMessage(playerid, COLOR_WHITE, "{FF0000}[ERROR]{FFFFFF} You cannot go AFK(Away From Keyboard) with wanted level.");
       }
     else
     {
         SendClientMessage(playerid, COLOR_WHITE, "{FF0000}[ERROR]{FFFFFF} You are already AFK(Away From Keyboard).");
     }

     return 1;
}
CMD:back(playerid,params[])
{
    if(afk[playerid] == 0) return SendClientMessage(playerid,COLOR_WHITE, "{FF0000}[ERROR]{FFFFFF}  You are not AFK(Away From Keyboard).");
    new string[128],pname[32];
    GetPlayerName(playerid,pname,sizeof(pname));
	format(string,sizeof(string),"%s {FFFF00}Is now Back to the keyboard.",pname);
	SendClientMessageToAll(COLOR_WHITE, string);
	Delete3DTextLabel(label[playerid]);
	TogglePlayerControllable(playerid,1);
	afk[playerid] = 0;
	return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if(dialogid == afkdialog) {
		if(response == 0) {
			new string[128],pname[32];
			GetPlayerName(playerid,pname,sizeof(pname));
			format(string,sizeof(string),"%s {FFFF00}Is now AFK(Away from Keyboard).",pname);
			SendClientMessageToAll(COLOR_WHITE, string);
			label[playerid] = Create3DTextLabel(" ",0xAA3333AA,30.0,40.0,50.0,15.0,0);
			Update3DTextLabelText(label[playerid], 0xAA3333AA, "AFK(Away From Keyboard)");
	        Attach3DTextLabelToPlayer(label[playerid], playerid, 0.0, 0.0, 0.4);
	        SendClientMessage(playerid, COLOR_WHITE, "{FFFF00}Type /back when you back :)");
	        TogglePlayerControllable(playerid,0);
	        afk[playerid] = 1;
	        return 1;
		}
		else if(response == 1) {
		if(!strlen(inputtext)) {
		new string[128],pname[32];
		GetPlayerName(playerid,pname,sizeof(pname));
		format(string,sizeof(string),"%s {FFFF00}Is now AFK(Away from Keyboard).",pname);
		SendClientMessageToAll(COLOR_WHITE, string);
		label[playerid] = Create3DTextLabel(" ",0xAA3333AA,30.0,40.0,50.0,15.0,0);
		Update3DTextLabelText(label[playerid], 0xAA3333AA, "AFK(Away From Keyboard)");
	    Attach3DTextLabelToPlayer(label[playerid], playerid, 0.0, 0.0, 0.4);
	    SendClientMessage(playerid, COLOR_WHITE, "{FFFF00}Type /back when you back :)");
	    TogglePlayerControllable(playerid,0);
	    afk[playerid] = 1;
        } else if(strlen(inputtext))
		     {
	         new string[128],pname[32];
	         GetPlayerName(playerid,pname,sizeof(pname));
	         format(string,sizeof(string),"%s {FFFF00}Is now Away from Keyboard. {FF0000}|-Reason: %s -|",pname,inputtext);
	         SendClientMessageToAll(COLOR_WHITE, string);
             label[playerid] = Create3DTextLabel(" ",0xAA3333AA,30.0,40.0,50.0,15.0,0);
             format(string,sizeof(string),"AFK.|-Reason: %s -|",inputtext);
             Update3DTextLabelText(label[playerid], 0xAA3333AA, string);
             Attach3DTextLabelToPlayer(label[playerid], playerid, 0.0, 0.0, 0.4);
             SendClientMessage(playerid, COLOR_WHITE, "{FFFF00}Type /back when you back :)");
             TogglePlayerControllable(playerid,0);
             afk[playerid] = 1;
             return 1;
		 }
	  }
	}
	return 1;
}
public OnPlayerConnect(playerid)
{
 afk[playerid] = 0;
 return 1;
}
public OnPlayerDisconnect(playerid)
{
 afk[playerid] = 0;
 return 1;
}
Reply
#2

You are trying to use playerid outside of all callbacks, functions, etc. It is not defined there.
After that you are trying to use playerid as an array, which it is not.

Place GetPlayerWantedLevel inside of the function and then instead of using playerid[..] just get the wanted level, no point in saving the data as you don't use it anywhere else.
Also, GetPlayerWantedLevel(playerid) should be equal to 0 since you want the player not to have a wanted level, currently you are doing the opposite.

Like this:
PHP код:
#define afkdialog 1165
new afk[MAX_PLAYERS];
new 
Text3D:label[MAX_PLAYERS];
CMD:afk(playerid,params[])
{
    if(
afk[playerid] == 0)
    {
       if(
GetPlayerWantedLevel(playerid) == 0)
       {
         
ShowPlayerDialog(playeridafkdialogDIALOG_STYLE_INPUT"{FF0000}Reason:""{FFFF00}Please Type Reason of going AFK Below.""Done""Cancel");
       }
       else
       {
          
SendClientMessage(playeridCOLOR_WHITE"{FF0000}[ERROR]{FFFFFF} You cannot go AFK(Away From Keyboard) with wanted level.");
       }
     else
     {
         
SendClientMessage(playeridCOLOR_WHITE"{FF0000}[ERROR]{FFFFFF} You are already AFK(Away From Keyboard).");
     }
     return 
1;

Reply
#3

C:\Users\XGamerZ\Desktop\afk.pwn(2 : warning 217: loose indentation
C:\Users\XGamerZ\Desktop\afk.pwn(2 : error 029: invalid expression, assumed zero
C:\Users\XGamerZ\Desktop\afk.pwn(36) : warning 217: loose indentation
C:\Users\XGamerZ\Desktop\afk.pwn(36) : error 029: invalid expression, assumed zero
C:\Users\XGamerZ\Desktop\afk.pwn(36) : error 017: undefined symbol "cmd_back"
C:\Users\XGamerZ\Desktop\afk.pwn(36) : error 029: invalid expression, assumed zero
C:\Users\XGamerZ\Desktop\afk.pwn(36) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


5 Errors.

Still having Error.
Please Someone Help!
Reply
#4

Please help guys!
Reply
#5

Looked over the code, it appears that you are missing a closing bracket } inside the afk command after the first if code block. This should help you.
PHP код:
#define afkdialog 1165 
new afk[MAX_PLAYERS]; 
new 
Text3D:label[MAX_PLAYERS]; 
CMD:afk(playerid,params[]) 

    if(
afk[playerid] == 0
    { 
       if(
GetPlayerWantedLevel(playerid) == 0
       { 
         
ShowPlayerDialog(playeridafkdialogDIALOG_STYLE_INPUT"{FF0000}Reason:""{FFFF00}Please Type Reason of going AFK Below.""Done""Cancel"); 
       } 
       else 
       { 
          
SendClientMessage(playeridCOLOR_WHITE"{FF0000}[ERROR]{FFFFFF} You cannot go AFK(Away From Keyboard) with wanted level."); 
       } 
    }
    else 
     { 
         
SendClientMessage(playeridCOLOR_WHITE"{FF0000}[ERROR]{FFFFFF} You are already AFK(Away From Keyboard)."); 
     } 
     return 
1

Reply
#6

Thank you so much!
Help Archived
Reply
#7

Create function for getting name, it will make this long code shorter.
PHP код:
GetName(pid){
    new 
s[24]
    
GetPlayerName(pid,s,24);
    return 
s;
}
new 
string[128],pname[32];
            
GetPlayerName(playerid,pname,sizeof(pname));
            
format(string,sizeof(string),"%s {FFFF00}Is now AFK(Away from Keyboard).",pname);
            
SendClientMessageToAll(COLOR_WHITEstring);
to 
format
(string,sizeof(string),"%s {FFFF00}Is now AFK(Away from Keyboard).",GetName(pid));
SendClientMessageToAll(COLOR_WHITEstring); 
Reply
#8

Actually help not archieved ... Please someone help I want system that people cant go AFK with wanted stars but when I was in-game I had 6-7 stars but still I was going AFK, (/afk) but without wanted I want that :/ plz someone help!
Reply
#9

You have to make a detection of the wanted level when processing the command in-order to make it work the way you want.
Reply
#10

Код:
CMD:afk(playerid,params[])
{
   new wantedlevel = GetPlayerWantedLevel(playerid);
   if(playerid[wantedlevel] > 0)
		 return SendClientMessage(playerid, COLOR_WHITE, "{FF0000}[ERROR]{FFFFFF} You cannot go AFK(Away From Keyboard) with wanted level.");

    if(afk[playerid] == 0)
    {
         ShowPlayerDialog(playerid, afkdialog, DIALOG_STYLE_INPUT, "{FF0000}Reason:", "{FFFF00}Please Type Reason of going AFK Below.", "Done", "Cancel");
    }
    else
    {
         SendClientMessage(playerid, COLOR_WHITE, "{FF0000}[ERROR]{FFFFFF} You are already AFK(Away From Keyboard).");
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)