AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   get user name (HL log format) (https://forums.alliedmods.net/showthread.php?t=52437)

Warthog 03-10-2007 16:23

get user name (HL log format)
 
I work heavily with HL log files, so I wanted a function to return a player's name in HL log format, rather than just their name in-game. For instead, instead, instead of "Warthog" I would want to return "Warthog<1><0:0:12345><CT>"

So below is the function for this - it is based off of get_user_name() in that you pass the ID, string to copy the data into, and the length. It also returns 0 or 1 based on if the user was found.

Code:
// similar to the stock get_user_name, but return the log name for the player: name<userid><authid><team> stock get_log_user_name(id, log_user_name[], length) {     // if not a valid player, return that the function failed    if(id < 1 || id > 32)    {       log_user_name[0] = 0       return 0    }       // if a valid player, set the log user name    else    {       static name[32], userid, authid[32], team[16]         // get the player name, userid, authid, and team       get_user_name(id, name, 31)       userid = get_user_userid(id)       get_user_authid(id, authid, 31)       get_user_team(id, team, 15)         // concatenate the values together into the user name log format       formatex(log_user_name, length, "%s<%d><%s><%s>", name, userid, authid, team)    }      // return success    return 1 }

Hawk552 03-10-2007 21:46

Re: get user name (HL log format)
 
Definitely useful, I think it would be a good addition to amxmisc.

Warthog 03-10-2007 22:05

Re: get user name (HL log format)
 
thanks. actually i modified the first part so you don't have to declare an extra variable for the player...i just put the find_player() check right in the first if() statement

Hawk552 03-12-2007 09:01

Re: get user name (HL log format)
 
You can also avoid a native call by doing:

Code:
if(!find_player("k", id))    {         log_user_name[0] = 0         return 0    }

Rather than:
Code:
if(!find_player("k", id))    {         copy(log_user_name,length,"")       return 0    }

Warthog 03-12-2007 12:24

Re: get user name (HL log format)
 
That's kind of spiffy. I'm not used to being able to clear out strings that way. I modifed my original post to include your improvement. Thanks Hawk.

Warthog 03-14-2007 03:06

Re: get user name (HL log format)
 
oops, made one more change and hopefully it's the last edit. get_user_name() that i based this off of passes the player index into the function, but i was treating it like the player userid instead. so i changed find_player() to just check if the index is within the 1-32 range.


All times are GMT -4. The time now is 04:11.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.