Isplayeroffline
#1

Hey!

Here is a stock function of IsPlayerNameOnline

pawn Код:
stock IsPlayerNameOnline(compname[]){
    new playername[MAX_PLAYER_NAME];
    for(new i=0;i<=MAX_PLAYERS;i++) {
        if(IsPlayerConnected(i)) {
            GetPlayerName(i, playername, sizeof(playername));
            if(strcmp(playername,compname,false) == 0) {
                return i;}}}
    return 1000;}
But i want to make it vice versa "IsPlayerNameOffline"

What would be the code, please help
Reply
#2

pawn Код:
stock IsPlayerNameOnline(compname[]){
    new playername[MAX_PLAYER_NAME];
    for(new i=0;i<=MAX_PLAYERS;i++) {
        if(IsPlayerConnected(i)) {
            GetPlayerName(i, playername, sizeof(playername));
            if(!strcmp(playername,compname,false) == 0) {
                return i;}}}
    return 1000;}
try
Reply
#3

I'm not sure if I understand the question but if this code returns 1000, this means the player is offline.
Reply
#4

Код:
stock IsPlayerNameOffline(compname[]) {
	new playername[MAX_PLAYER_NAME];

	for(new i=0; i<MAX_PLAYERS; i++) {
		GetPlayerName(i, playername, MAX_PLAYER_NAME);
		if(!strcmp(playername, compname, false)) return 0
	}
	return 1;
}
I created this function that returns 1 if player is offline and 0 otherwise. I didn't test it!
Reply
#5

Function:
pawn Код:
bool:IsPlayerNameOffline(name[])
{    
    new pname[MAX_PLAYER_NAME];    
    foreach(new i: Player)
    {                  
        GetPlayerName(i, pname, sizeof(pname));            
        if(strcmp(pname, name, false) == 0) return false;
    }    
    return true;
}
Usage:
pawn Код:
if(IsPlayerNameOffline("SickAttack") == true) // SickAttack is offline.
if(IsPlayerNameOffline("SickAttack") == false) // SickAttack is online.
As I didn't like your function because it's not optimized nor good looking, here you go:
pawn Код:
bool:IsPlayerNameOnline(name[])
{    
    new pname[MAX_PLAYER_NAME];    
    foreach(new i: Player)
    {                  
        GetPlayerName(i, pname, sizeof(pname));            
        if(strcmp(pname, name, false) == 0) return true;
    }    
    return false;
}
Usage:
pawn Код:
if(IsPlayerNameOnline("SickAttack") == false) // SickAttack is offline.
if(IsPlayerNameOnline("SickAttack") == true) // SickAttack is online.
Please note, you'll need the include 'foreach' for this function to work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)