AFK System - String problem
#1

Hii there.
I've a problem :
PHP код:
//new GODAFK;
new PlayerAfkName[MAX_PLAYERS][MAX_PLAYER_NAME+1];
CMD:afk(playerid, params[])
{
    if(
afk[playerid] == 1 && PlayerInfo[playerid][pAdminlvl] == 5)
    {
        if(
ZDM[playerid] != 2 && Dming[playerid] != 2)
        {
            new 
Float:x, Float:y, Float:z;
            
GetPlayerName(playerid, PlayerAfkName[playerid][MAX_PLAYER_NAME], sizeof(PlayerAfkName[playerid][MAX_PLAYER_NAME])); // THIS LINE GET A ERROR
            
TogglePlayerControllable(playerid, 0);
            
GetPlayerHealth(playerid, afkHealth[playerid]);
            
SetPlayerHealth(playerid, 9999999.0);
            
//GODAFK = SetTimerEx("GodMode", 100, true, "i", playerid);
            
GameTextForPlayer(playerid, "AFK", 4000, 3);
            
GetPlayerPos(playerid, x, y, z);
            new 
Text3D:afk3D = Create3DTextLabel("[AFK]",red1, x, y, z, 40, 0, 0);
            
Attach3DTextLabelToPlayer(afk3D, playerid, 0.0, 0.0, 0.0);
            
afk[playerid] = 2;
            
afkDraw = TextDrawCreate(285.000000, 18.000000,"~r~AFK");
            
TextDrawShowForPlayer(playerid, afkDraw);
            return 
1;
        }
        return 
1;
    }
    else if(
afk[playerid] == 2 && ZDM[playerid] != 2 && Dming[playerid] != 2)
    {
        
TogglePlayerControllable(playerid, 1);
        
//DeletePlayer3DTextLabel(playerid,
        
SetPlayerHealth(playerid, afkHealth[playerid]);
        
//KillTimer(GODAFK);
        
TextDrawHideForPlayer(playerid, afkDraw);
        
afk[playerid] = 1;
        return 
1;
    }
    else return 
1;
} 
I have an error. I don't know how to resolve it.

PHP код:
C:\--(5807) : error 001: expected token: "]", but found "-identifier-"
C:\--(5807) : warning 215: expression has no effect
C
:\--(5807) : error 001: expected token: ";", but found "]"
C:\--(5807) : error 029: invalid expression, assumed zero
C
:\--(5807) : fatal error 107: too many error messages on one line
Compilation aborted
.Pawn compiler 3.2.3664              Copyright (c) 1997-2006, ITB CompuPhase
4 Errors
. 
Reply
#2

Код:
GetPlayerName(playerid, PlayerAfkName[playerid], MAX_PLAYER_NAME);
And what's the +1 for? The name limit is 24 characters.
Код:
new PlayerAfkName[MAX_PLAYERS][MAX_PLAYER_NAME+1];
Reply
#3

To prevent the error :
pawn Код:
032 - array index out of bounds
The array index is larger than the highest valid entry of the array.
Reply
#4

PHP код:
new PlayerAfkName[MAX_PLAYER_NAME+1]; 
PHP код:
GetPlayerName(playerid, PlayerAfkName, MAX_PLAYER_NAME); 
Reply
#5

working - sizeof(PlayerAfkName)

BUT, the value sizeof is 500. (Get MAX_PLAYERS value, not recommended)
Reply
#6

Quote:
Originally Posted by luke49
Посмотреть сообщение
PHP код:
new PlayerAfkName[MAX_PLAYER_NAME+1]; 
PHP код:
GetPlayerName(playerid, PlayerAfkName, MAX_PLAYER_NAME); 
Not at all. The variable PlayerAfkName will take the name of the last player typed the command.

Quote:
Originally Posted by F1N4L
Посмотреть сообщение
working - sizeof(PlayerAfkName)

BUT, the value sizeof is 500. (Get MAX_PLAYERS value, not recommended)
Alright, I get the problem thanks by you. +rep

PHP код:
new PlayerAfkName[MAX_PLAYERS][MAX_PLAYER_NAME+1];  » new PlayerAfkName[MAX_PLAYER_NAME+1][MAX_PLAYERS]; 
But now, I have an another weird problem. The Gametext is showing the name of the player.
PHP код:
GameTextForPlayer(playerid, "AFK", 4000, 3); 
If I delete this line, the problem comes here
PHP код:
afkDraw = TextDrawCreate(285.000000, 18.000000,"~r~AFK"); 
Reply
#7

Код:
new PlayerAfkName[MAX_PLAYER_NAME+1][MAX_PLAYERS];
That is not the correct thing to use.

I already gave the correct solution to the name problem.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)