10.11.2008, 21:34
You need this:
Useful for roleplay scripts, will only work in "Firstname_Lastname" format.
Example of usage:
GetPlayerFirstName(playerid);
GetPlayerLastName(playerid);
Enjoy.
pawn Code:
forward split(const strsrc[], strdest[][], delimiter);
public split(const strsrc[], strdest[][], delimiter)
{
new i, li;
new aNum;
new len;
while(i <= strlen(strsrc)){
if(strsrc[i]==delimiter || i==strlen(strsrc)){
len = strmid(strdest[aNum], strsrc, li, i, 128);
strdest[aNum][len] = 0;
li = i+1;
aNum++;
}
i++;
}
return 1;
}
Useful for roleplay scripts, will only work in "Firstname_Lastname" format.
Example of usage:
pawn Code:
if(strcmp(cmd, "/firstname", true) == 0)
{
new wstring[128];
format(wstring, sizeof(wstring), "Hello, %s.", GetPlayerFirstName(playerid));
SendClientMessage(playerid,0xFFFFFFAA, wstring);
return 1;
}
pawn Code:
if(strcmp(cmd, "/lastname", true) == 0)
{
new wstring[128];
format(wstring, sizeof(wstring), "Hello, Mr %s.", GetPlayerLastName(playerid));
SendClientMessage(playerid,0xFFFFFFAA, wstring);
return 1;
}
GetPlayerFirstName(playerid);
GetPlayerLastName(playerid);
pawn Code:
stock GetPlayerFirstName(playerid)
{
new namestring[2][MAX_PLAYER_NAME];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,MAX_PLAYER_NAME);
split(name, namestring, '_');
return namestring[0];
}
pawn Code:
stock GetPlayerLastName(playerid)
{
new namestring[2][MAX_PLAYER_NAME];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,MAX_PLAYER_NAME);
split(name, namestring, '_');
return namestring[1];
}