SA-MP Forums Archive
Isplayeroffline - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Isplayeroffline (/showthread.php?tid=538638)



Isplayeroffline - Bondage - 22.09.2014

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


Re: Isplayeroffline - DaTa[X] - 22.09.2014

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


Re: Isplayeroffline - Jaxson - 22.09.2014

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


Re: Isplayeroffline - WooPz - 22.09.2014

Код:
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!


Re: Isplayeroffline - SickAttack - 22.09.2014

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.