Check if you are online, spawn character.
#1

Hello, I think I got to the point of not understanding my own code, how should it work? If the character has already been connected to the server with the same name, it will send a message to him saying that there is already a player that is using that same name, for example.

The function;
PHP код:
Account[i][pPersonagem1] = FirstName_SecondName 
This checks if he is already online with the character, in case he is sent the message saying that he can not use the character and the function below is stopped, with the return.

PHP код:
if(!IsPlayerConnected(idonline)) return SendClientMessage(playeridCOLOR_ERROR"ERROR: This character is already in the game."); 
What is going on? Simple, the player is connecting with the same name, "More like that Suk? There is no way" Not exactly with the same name, because there is no geito of gets two names in the game, but he gets the name he entered On the Onplayerconect.

PHP код:
    if(slot == 1) for(new 0MAX_PLAYERSi++) idonline GetPlayerID(Account[i][pPersonagem1]);
    if(
slot == 2) for(new 0MAX_PLAYERSi++) idonline GetPlayerID(Account[i][pPersonagem2]);
    if(
slot == 3) for(new 0MAX_PLAYERSi++) idonline GetPlayerID(Account[i][pPersonagem3]);
    if(!
IsPlayerConnected(idonline)) return SendClientMessage(playeridCOLOR_ERROR"ERRO: This character is already in the game."); 
Reply
#2

I'm not sure what exactly you are doing here:

PHP код:
if(!IsPlayerConnected(idonline)) 
IsPlayerConnected checks if there is a player with the ID you input. IDs don't equal to Player Names.

Not to mention since you put a "!" infront of it, you're basically saying: IF player is not connected, return client message saying "This character is already in the game."

EDIT: By the way, if there's a player with the name err "Test_Test" for example, online already and someone attempts to join with the same name; by default samp won't allow him to get in game so I don't know why you're doing this check. However, let's assume "Test_Test" isn't online and someone joins with that name. Don't you have a registration system? he'd have to login with the correct password.
Reply
#3

Just use strcmp and compare the player's name with others,
Go to OnPlayerConnect callback and do this:
PHP код:

new pname[MAX_PLAYER_NAME], oname[MAX_PLAYER_NAME];

GetPlayerName(playeridpnamesizeof(pname));

for(
i=0;i<MAX_PLAYERS;i++){

    
GetPlayerName(ionamesizeof(oname));
    if(
!= playerid && strcmp(pnameoname)){
        
SendClientMessage(playerid0xFF000088"[SERVER]: Sorry, this name is already in use");
        
Kick(playerid);
    }
}
Something a little bit like this 
Reply
#4

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
Just use strcmp and compare the player's name with others,
Go to OnPlayerConnect callback and do this:
[PHP]

new pname[MAX_PLAYER_NAME], oname[MAX_PLAYER_NAME];

GetPlayerName(playerid, pname, sizeof(pname));

for(i=0;i<MAX_PLAYERS;i++){

GetPlayerName(i, oname, sizeof(oname));
if(i != playerid && strcmp(pname, oname)){
SendClientMessage(playerid, 0xFF000088, "[SERVER]: Sorry, this name is already in use");
Kick(playerid);
}
}
Something a little bit like this
Resolved!
Reply
#5

Hello, good evening, does anyone know why my code does not work correctly? He can not do what I like to fiseze,

PHP код:
    for(new 0<MAX_PLAYERSi++)
    {
        
GetPlayerName(ionamesizeof(oname));
        if(
slot == 1) if(!= playerid && strcmp(Account[i][pPersonagem1], oname)) idonline 0;
        if(
slot == 2) if(!= playerid && strcmp(Account[i][pPersonagem2], oname)) idonline 0;
        if(
slot == 3) if(!= playerid && strcmp(Account[i][pPersonagem3], oname)) idonline 0;
    }
    if(
idonline == 1SendClientMessage(playeridCOLOR_WHITE2"ERRO: Esse personagem jб se encontra no jogo."); 
Reply
#6

Up?! I want when the player enters the name of his character verify if there is another character with this name online, if it does not exist it can spawn, otherwise if it exists it can not and will be returned a message to him saying, someone understood?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)