[Include] PlayerName
#1

Hi.
I just made an include (mostly for myself), but I'm gonna share it .

What is it
Very simple. It has an new 'SetPlayerName'. Example:
Old SetPlayerName:
I have the name 'kwarde'. I want 'Kwarde'. So I use SetPlayerName. It doesn't work!! (Because of the capitals, the name is the same, the server returns :P).
My new SetPlayerName:
I have the name 'kwarde'. I want 'Kwarde'. So I use SetPlayerName. It works!!!
And it has an 'PlayerName(playerid)' to get someone's name. You can either use that, or 'playerName[playerid]'. Your choise.
So it's just simple, but quite usefull, because it's easier to use. Example scripts:

Normal way
pawn Код:
new pName[MAX_PLAYER_NAME], str[128]; //Overused cells
GetPlayerName(playerid, pName, sizeof(pName));
format(str, 128, "Hi %s!", pName);
SendClientMessage(playerid, 0xFFFFFFAA, str);
New way
pawn Код:
new str[128]; //Overused cells :P
format(str, 128, "Hi %s!", playerName[playerid]); //Or instead of 'playerName[playerid]' PlayerName(playerid)
SendClientMessage(playerid, 0xFFFFFFAA, str);
It's not special, EXCEPT that this scripts uses a global variable:
new playerName[MAX_SLOTS][MAX_PLAYER_NAME];
The most people makes all the time a new 'pName', but this script doesn't .

Download
Version 1.0: Pastebin

Changelog
Код:
Version 1.0:
    - Initial release
Instructions
1) Copy the script from pastebin into PAWNO
2) (Optional) Change 'MAX_PLAYERS' to the max slots of your server (if it wasn't done already!)
3) Save the file in your pawno/include folder
4) Add #include <{name}> to your gamemode/filterscript. NOTE: Change {name} for the name of the .inc file. TIP: Use PlayerName

That's it. Kinda simple, but also quite usefull (My opinion !!)

- Kevin

p.s.
I know I wouldn't release scripts anymore, seems like I changed my mind :P
Reply
#2

Thank dude.
Reply
#3

Good work,will be usefull for lazy people
Reply
#4

Quote:
Originally Posted by Forbidden
Посмотреть сообщение
Good work,will be usefull for lazy people
Actually also for those who wants to save their time.
Thanks Kwarde. +rep
Reply
#5

Don't forget this part! :P
Quote:
Old SetPlayerName:
I have the name 'kwarde'. I want 'Kwarde'. So I use SetPlayerName. It doesn't work!! (Because of the capitals, the name is the same, the server returns :P).
My new SetPlayerName:
I have the name 'kwarde'. I want 'Kwarde'. So I use SetPlayerName. It works!!!

And thanks everyone :P. Or should I say: "You're welcome"?
Reply
#6

So basicly a SetPlayerName fix?
Good idea
Reply
#7

Yes, and just -very old- a PlayerName(playerid); function (or just use: playerName[playerid] (var). The most PlayerName functions looks like this:
pawn Код:
stock PlayerName(playerid)
{
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName)); //Or instead of 'sizeof(pName)' just 'MAX_PLAYER_NAME' (my style)
    return pName;
}
My script has the global variable "playerName[playerid]". (new playerName[MAX_PLAYERS][MAX_PLAYER_NAME];). When a player connects, the script automatic gets the name, store it into playerName[playerid] so you can safe it later (yes it's being changed when you use SetPlayerName).
And so, the PlayerName function of mine looks like this:
pawn Код:
stock PlayerName(playerid)
    return playerName[playerid];
:P
Reply
#8

most funnctions can be made out of definnes, improves speed of script. jjust a hint
other than that, quite useful
Reply
#9

Quote:
Originally Posted by legodude
Посмотреть сообщение
most funnctions can be made out of definnes, improves speed of script. jjust a hint
other than that, quite useful
Where are you talking about? There are only 2 functions, one of it can be used as a macro (it actually can, but it's quite big and that doesn't really fit to macro's) and the other one, well, that's not "most functions".
pawn Код:
stock NewName(playerid, const name[])
{
    new str[MAX_PLAYER_NAME];
    format(str, MAX_PLAYER_NAME, "x_%03d_", playerid);
    SetPlayerName(playerid, str); //Eg. if you have the name 'kwarde' and you want 'Kwarde', normal SetPlayerName won't work. This'll fix it
    SetPlayerName(playerid, name);
    GetPlayerName(playerid, playerName[playerid], MAX_PLAYER_NAME);
    return 1;
}
#define SetPlayerName NewName

stock PlayerName(playerid)
    return playerName[playerid];
#define Name PlayerName
Do you see what I mean?
Reply
#10

First is good idea . Second it's nice job
Reply
#11

I Do Not Need to Use?
pawn Code:
new pName[MAX_PLAYER_NAME], str[128]; //Overused cells
GetPlayerName(playerid, pName, sizeof(pName));
Reply
#12

As old as time.
Reply
#13

This would still mean a shitload of 'overused' cells. What would be more efficient? To create one string with 24 cells ONLY when you need to retrieve a name OR having x* strings with 24 cells ALL the time, meaning they're 99.9% of the time useless?

* Whatever MAX_PLAYERS is defined as.
Reply
#14

Quote:
Originally Posted by Hiddos
View Post
This would still mean a shitload of 'overused' cells. What would be more efficient? To create one string with 24 cells ONLY when you need to retrieve a name OR having x* strings with 24 cells ALL the time, meaning they're 99.9% of the time useless?

* Whatever MAX_PLAYERS is defined as.
do not create extra lines!
pawn Code:
new str[128]; //Overused cells
GetPlayerName(playerid, str, MAX_PLAYER_NAME);
format(str, 128, "Hi %s!", str);
SendClientMessage(playerid, 0xFFFFFFAA, str);
Reply
#15

Quote:
Originally Posted by Stepashka
View Post
do not create extra lines!
pawn Code:
new str[128]; //Overused cells
GetPlayerName(playerid, str, MAX_PLAYER_NAME);
format(str, 128, "Hi %s!", str);
SendClientMessage(playerid, 0xFFFFFFAA, str);
+1, best solution around ^^
Reply
#16

I don't under stand why this if you have GetName function by Y_Less?

anyway nice
Reply
#17

In audio plugin 0.5 redefine of setplayername, you must know it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)