[Tutorial] /report command.
#4

Quote:
Originally Posted by DobbysGamertag
View Post
Not a bad tutorial


Off topic now. Why don't people stock the GetPlayerName function instead of having to get the player name each time.

pawn Code:
stock Name(playerid)
{
    new n[MAX_PLAYER_NAME];
    GetPlayerName(playerid,n,sizeof(n));
    return n;
}
Then it'll become:
pawn Code:
CMD:report(playerid,params[])
{
    new pid,reason[60],string[124];
    if(sscanf(params,"us[60]",pid,reason))return SendClientMessage(playerid,COLOR_ORANGE,"[SERVER] - USAGE /report [id][reason]");
    format(string,124,"[ADMIN] %s (%d) has reported %s (%d)",Name(playerid),playerid,Name(pid),pid);
    SendMessageToAdmins(string);
    format(string,124,"[ADMIN]  - Reason: %s",reason);
    SendMessageToAdmin(string);
    SendClientMessage(playerid,COLOR_ORANGE,"Your report has been sent");
    return 1;
}
Wrote it quick so im not sure if it'll compile without errors. But you get the idea?
Honestly, your method is worse. Do you want to know why?

Let's say in a command you need to show 4 messages with the playerid's name. By using his method, he would call GetPlayerName only 1 time and your stock would call GetPlayerName 4 times. I hope you get what I mean.

The best way is to get the name ONLY 1 time on connect and use it later on.

pawn Code:
new
    Name[ MAX_PLAYERS ][ MAX_PLAYER_NAME ]
;

// OnPlayerConnect:
GetPlayerName( playerid, Name[ playerid ], MAX_PLAYER_NAME );

// Everywhere else:
format(string,124,"[ADMIN] %s (%d) has reported %s (%d)",Name[playerid],playerid,Name[pid],pid);
Reply


Messages In This Thread
/report command. - by Kyance - 10.10.2013, 10:05
Re: /report command. - by DobbysGamertag - 10.10.2013, 10:31
Re: /report command. - by qazwsx - 10.10.2013, 10:37
Re: /report command. - by Konstantinos - 10.10.2013, 10:37
Re: /report command. - by efrim123 - 10.10.2013, 19:55
Re: /report command. - by Kyance - 11.10.2013, 14:40

Forum Jump:


Users browsing this thread: 1 Guest(s)