[HELP] check if player is online when using offline command
#1

Hello. So I have offline command /offcheck and what I want is that if admin use that command on online player then I want to send him a message you cannot use this command on online player. I use sscanf like


if(sscanf(params,"s[128]",offnick))

Thanks.
Reply
#2

Hello!

Do you mean it like that?
PHP код:
CMD:offcheck(playerid,params[])
{
    new 
pID;
    if(
sscanf(params,"u",pID))return SendClientMessage(playerid,-1,"Use /offcheck [playerid]");
    if(
IsPlayerConnected(pID))
    {
        
SendClientMessage(playerid,-1,"you cannot use this command on online player");
        return 
1;
    }
    
//If the player isn't connected
    
return 1;

Reply
#3

Untested but should work
PHP код:
CMD:offcheck(playerid,params[])
{
    new 
offnick[MAX_PLAYER_NAME];
    if(
sscanf(params,"s[128]",offnick)) return SendClientMessage(playerid, -1"Usage: /offcheck [full name]");
    if(
IsPlayerConnected(GetPlayerIdFromName(offnick)) return SendClientMessage(playerid, -1"You cannot use this command on online players.");
    
// Code
    
return 1;
}
stock GetPlayerIdFromName(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;

Reply
#4

Quote:
Originally Posted by Mencent
Посмотреть сообщение
Hello!

Do you mean it like that?
PHP код:
CMD:offcheck(playerid,params[])
{
    new 
pID;
    if(
sscanf(params,"u",pID))return SendClientMessage(playerid,-1,"Use /offcheck [playerid]");
    if(
IsPlayerConnected(pID))
    {
        
SendClientMessage(playerid,-1,"you cannot use this command on online player");
        return 
1;
    }
    
//If the player isn't connected
    
return 1;

Thank you mencent work perfect
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)