IsPlayerConnected(playerid) returns 0 everytime
#1

Hello, i have a big problem...
Everytime when i use a command like this /pm <id> or /goto <id> or another with <id>, IsPlayerConnected returns 0 (player not connected).

Here is a example cmd:
pawn Код:
CMD:disarm(playerid,params[])
{
      if(pInfo[playerid][pLevel] == 0) return SendClientMessage(playerid,red,"{5CAD5C}Error: You're not an admin.");
      if(pInfo[playerid][pLevel] >= 1)
      {
           new id;
           if(sscanf(params, "u", id)) return SendClientMessage(playerid, yellow, "{B8DBFF}Syntax: /disarm <playerID>");
           if(!IsPlayerConnected(id)) return //SendClientMessage with player not connected here.
           format(Lstr,sizeof(Lstr),"{F45E43}AdmCmd: You have disarmed %s.",TakeName(id));
           SendClientMessage(playerid,yellow,Lstr);
           format(Lstr,sizeof(Lstr),"{F45E43}AdmCmd: Admin %s has disarmed you.",TakeName(playerid));
           SendClientMessage(id,yellow,Lstr);
           ResetPlayerWeapons(id);
           return 1;
      }
      else return 0;
}
Everyone know how to solve this? The player is shown on TAB as connected, but cmds doesn't work.

Sorry for my bad english.
Reply
#2

Always return 1 in zcmd.

And instead of checking the player's admin level twice, just use:
pawn Код:
if(pInfo[playerid][pLevel] >= 1)
{
    // ...
}
else
{
   return SendClientMessage(playerid, 0xFF0000FF, "You need to be a higher admin to use this command.");
}
return 1; // ALWAYS return 1 in ZCMD
Reply
#3

I always used i for player id, perhaps that may work?
if(sscanf(params, "i", id)) //...
Reply
#4

Quote:
Originally Posted by yugecin
Посмотреть сообщение
I always used i for player id, perhaps that may work?
if(sscanf(params, "i", id)) //...
"i" / "d" is for integers, "u" is for player ids / player names.
Reply
#5

The bug appear only sometimes, not everytime.

yugecin i will try use 'i' in sscand for id.

Stinged, if i will return 1; all of myc ZCMD cmds, you think that the bug will be solved?

I really don't understand how this function (IsPlayerConnected) became bugged...

edit:
I'm sure that my commands aren't the problem.
The problem is something of IsPlayerConnected...or maybe plugins?
I made a test now:

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(IsPlayerConnected(killerid) && killerid != INVALID_PLAYER_ID)
    {
        SendClientMessageToAll(-1,"IsPlayerConnected returned 1");
    }
}
I killed someone and...i havn't seen the message, so IsPlayerConnected(killerid) returned 0 but i was connected.
Please...some help?
Reply
#6

BUMP sorry
Reply
#7

The u specifier bugs sometimes with sscanf.
Reply
#8

Quote:
Originally Posted by Pottus
Посмотреть сообщение
The u specifier bugs sometimes with sscanf.
I think not sscanf is my problem.
Reply
#9

I tried this:
pawn Код:
CMD:debug(playerid,params[])
{
   
            new id;
            if(sscanf(params, "i",id)) return SendClientMessage(playerid, -1, "{B8DBFF}Syntax: /debug <playerID>");
            if (IsPlayerConnected(id)){
           
            new ver[256];
            format(ver,sizeof(ver),"DEBUG: Sscanf ID: %d, nickname %s",id,TakeName(id));
            SendClientMessage(playerid,-1,ver);
            }
            else SendClientMessage(playerid,-1,"Error");
            return 1;
}
Everytime it says "error" ...
Reply
#10

Hello!

Try this for an test. What is printing in your chat?
PHP код:
CMD:debug(playerid,params[])
{
    for(new 
i;i<MAX_PLAYERS;i++)
    {
        if(
IsPlayerConnected(i) && !IsPlayerNPC(i))
        {
            new 
ver[145];
            
format(ver,sizeof ver,"ID: %d - Nickname: %s",i,TakeName(i));
            
SendClientMessage(playerid,-1,ver);
        }
        else 
SendClientMessage(playerid,-1,"Error");
    }
    return 
1;

Mencent
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)