SA-MP Forums Archive
Detecting name wont work :/ - 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: Detecting name wont work :/ (/showthread.php?tid=472348)



Detecting name wont work :/ - Alex_Obando - 28.10.2013

pawn Код:
public OnPlayerConnect(playerid)
{
    PlayerSpawned[playerid] = 1;
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    PlayerSpawned[playerid] = 0;
    return 1;
}

public OnPlayerSpawn(playerid)
{
   new name[256];
   new string[128];
   GetPlayerName(playerid, name, sizeof(name));
   if(PlayerSpawned[playerid] == 1)
   {
       if(!strcmp(name,"[COD]Alex", true))
       {
           format(string, sizeof(string), "~r~Owner~w~ %s~b~(%d)~r~ has joined the server.", name,playerid);
           GameTextForAll(string, 4000, 6);
       }
 
    }
    return 1;
}



Re : Detecting name wont work :/ - Matnix - 28.10.2013

• It's not a good idea to place your code when he spawn, that mean each time he dead then spawn, the message will be sent.
• Why you use GameText, you can simply use SendClientMessageToAll.


Re: Detecting name wont work :/ - SAMProductions - 28.10.2013

SendClientMessageToAll would be better,

if it is GameTextForAll it will disturb another Player, so try using SendClientMessageToAll,

and it must be in OnPlayerConnect not OnPlayerSpawn because if it is OnPlayerSpawn,

the Message will send after you Spawned,


pawn Код:
public OnPlayerConnect(playerid)
{
   new name[MAX_PLAYER_NAME];
   new string[1200];
   GetPlayerName(playerid, name, sizeof(name));
   if(PlayerLogged[playerid] == 1)
   {
       if(!strcmp(name,"[COD]Alex", true))
       {
           format(string, sizeof(string), "{FF0000}Owner {EEEEEE}%s (ID: {FF0000}%d{EEEEEE}) has joined the server.", name, playerid);
           SendClientMessageToAll(-1, string);
       }
 
    }
    return 1;
}



Respuesta: Detecting name wont work :/ - Alex_Obando - 28.10.2013

Thats why i have a variable, under on player connect, so everytime i spawn it doesnt come up.....


Re: Detecting name wont work :/ - SAMProductions - 28.10.2013

But it would be better if it is on OnPlayerConnect, because it will show the Message(s) when you joined.

and if it is on OnPlayerSpawn, it will show the Message(s) when you got spawned.



Re : Detecting name wont work :/ - Matnix - 28.10.2013

I saw your variable but I've never saw when you turn it to 0 when he died but when he disconnect you add it.


Respuesta: Detecting name wont work :/ - Alex_Obando - 28.10.2013

Either way, wont appear the message :/


Re: Detecting name wont work :/ - EiresJason - 28.10.2013

Are you sure you are actually connecting with [COD]Alex? (Sounds stupid to ask but it happens xD)

Doesn't look like theres anything wrong with your code (besides the fact that the name variable is 256 instead of 24/MAX_PLAYER_NAME :P).

I threw it into my script and it worked perfectly. Are you lagging or anything when you spawn, and you actually don't see it in time?


Re : Detecting name wont work :/ - Matnix - 28.10.2013

pawn Код:
if(!strcmp(name(playerid),"[COD]Alex",true)) // for me it's :
// if he logging to the server and he don't have [COD]Alex (because of !strcmp)
{ //
    // send the message
    SendClientMessageToAll(COLOR,"blabla"); //
    return 1; //
} //

// try like this

if(strcmp(name,"[COD]Alex",true)) // for me it's :
// if he logging to the server and he have [COD]Alex (because of strcmp)
{ //
    // send the message
    SendClientMessageToAll(COLOR,"blabla"); //
    return 1; //
}
else // is name is not [COD]Alex
{ //
    SendClientMessageToAll(COLOR, "blabla"); //
    return 1; //
}//
correct me If I am wrong


Re: Re : Detecting name wont work :/ - cessil - 28.10.2013

Quote:
Originally Posted by Matnix
Посмотреть сообщение
pawn Код:
if(!strcmp(name(playerid),"[COD]Alex",true)) // for me it's :
// if he logging to the server and he don't have [COD]Alex (because of !strcmp)
{ //
    // send the message
    SendClientMessageToAll(COLOR,"blabla"); //
    return 1; //
} //

// try like this

if(strcmp(name,"[COD]Alex",true)) // for me it's :
// if he logging to the server and he have [COD]Alex (because of strcmp)
{ //
    // send the message
    SendClientMessageToAll(COLOR,"blabla"); //
    return 1; //
}
else // is name is not [COD]Alex
{ //
    SendClientMessageToAll(COLOR, "blabla"); //
    return 1; //
}//
correct me If I am wrong
you are wrong, if you can't compare two things then they are the same and strcmp will return 0

Quote:
Originally Posted by Alex_Obando
Посмотреть сообщение
pawn Код:
public OnPlayerSpawn(playerid)
{
   printf("OPS called %d",playerid);
   new name[256];
   new string[128];
   GetPlayerName(playerid, name, sizeof(name));
   if(PlayerSpawned[playerid] == 1)
   {
           printf("PlayerSpawned is equal to 1 %s",name);
       if(!strcmp(name,"[COD]Alex", true))
       {
           format(string, sizeof(string), "~r~Owner~w~ %s~b~(%d)~r~ has joined the server.", name,playerid);
               printf("strcmp check passed %s",string);
           GameTextForAll(string, 4000, 6);
       }
 
    }
    return 1;
}
you should add some print messages so you know exactly where it's failing