What way is better for that?
#1

Guys, what is better? I do not know if is better to create in each public for example this:

pawn Код:
Name[MAX_PLAYER_NAME];
GetPlayerName (playerid, Name, sizeof (Name));
Or is better to create new stock function

pawn Код:
stock GetName(playerid)use this function
{
    new Name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, Name, sizeof(Name));
    return Name
}
And then just put this stock function to format? Thanks.
Reply
#2

The second way is bad.

Use either the first one or this (http://forum.sa-mp.com/showpost.php?...8&postcount=25).
Reply
#3

And when I use this, like you said

pawn Код:
new playersName[MAX_PLAYERS][MAX_PLAYER_NAME];

public OnPlayerDisconnect(playerid)
{
    playersName[playerid][0] = '\0';
    return 1;
}

GetPlayersName(playerid)
{
    if(isnull(playersName))
    {
        GetPlayerName(playerid, playersName, MAX_PLAYER_NAME);
    }

    return playersName;
}
Then I need to put into format just GetPlayersName(playerid)?
Reply
#4

I meant the code at the bottom, not from the quote.

And yes, all you need to do is to pass GetName(playerid) as an argument in the format function.
Reply
#5

Okay, and what I need to put to format for example format(string, sizeof(string), "Player name is %s", And what do I put here?

From this:

pawn Код:
#define GetName(%0) Player_Name[%0]

static
    Player_Name[MAX_PLAYERS][MAX_PLAYER_NAME];

public OnPlayerConnect(playerid)
{
    GetPlayerName(playerid, Player_Name[playerid], MAX_PLAYER_NAME);
    return 1;
}
Reply
#6

Konstantinos was right. I did not look properly.
Reply
#7

An example:
pawn Код:
#define GetName(%0) Player_Name[%0]

static
    Player_Name[MAX_PLAYERS][MAX_PLAYER_NAME];

public OnPlayerConnect(playerid)
{
    GetPlayerName(playerid, Player_Name[playerid], MAX_PLAYER_NAME);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new
        string[38];

    format(string, sizeof (string), "%s disconnected", GetName(playerid));
    return 1;
}
Reply
#8

Heh, okay thanks guys for responses!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)