Issue with IsPlayerConnected and GetPlayerID
#1

Hello,
so i want to obtain the name of the player, but ONLY if the player is offline.
This doesn't work, and I have no idea why.
Can someone help me?
ty
PHP код:
/* ============================================================================= */
COMMAND:foff(playerid,params[])
{
    if(!
Player[playerid][Faction]) return SendClientError(playerid,"You are not in a faction.");
    new 
query[200];
    
format(query,sizeof(query),"SELECT * FROM accounts WHERE Faction='%i'",Player[playerid][Faction]);
    
mysql_tquery(connection,query,"foff","d",playerid);
    return 
1;
}
/* ============================================================================= */
forward foff(playerid);
public 
foff(playerid)
{
    new 
name[35];
    for(new 
i=0i<cache_get_row_count(); i++)
    {
        
cache_get_field_content(i,"Username",name);
        if(
IsPlayerConnected(GetPlayerID(name))) return 1;
        
SendClientMessage(playerid,-1,sprintf("%i",i));
    }
    return 
1;
}
/* ============================================================================= */
stock GetPlayerID(playername[])
{
  for(new 
0<= MAX_PLAYERSi++)
  {
    if(
IsPlayerConnected(i))
    {
      new 
playername2[MAX_PLAYER_NAME];
      
GetPlayerName(iplayername2sizeof(playername2));
      if(
strcmp(playername2playernametruestrlen(playername)) == 0)
      {
        return 
i;
      }
    }
  }
  return 
INVALID_PLAYER_ID;
}
/* ============================================================================= */ 
So, nothing gets send to the chat (sendclientmessage doesn't work.)
Reply
#2

What command is that to kick that player while the player is offline am i right ? because i did'nt understand what your saying you have bad english
Reply
#3

In other words you want to show the name of the offline players for that faction and skip the connected?

First of all, returning a value in a loop breaks it completely. Store the rows to a variable instead of keep calling cache_get_row_count in every iteration.

I don't get why you are trying to send the rowid as a client message and not the name of the player.

Use sscanf to check if a player is connected than GetPlayerID + IsPlayerConnected functions, much faster. If you insist on using your way, at least use GetPlayerPoolSize or even better foreach/y_iterate for the player-loops.

Last, if you want only to retrieve the name then don't select all the data in the query but this certain column:
"SELECT Username FROM ..."
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)