Raised This Month: $12 Target: $400
 3% 

get user name (HL log format)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Warthog
Junior Member
Join Date: Feb 2007
Old 03-10-2007 , 16:23   get user name (HL log format)
Reply With Quote #1

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 }

Last edited by Warthog; 03-14-2007 at 03:05.
Warthog is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-10-2007 , 21:46   Re: get user name (HL log format)
Reply With Quote #2

Definitely useful, I think it would be a good addition to amxmisc.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Warthog
Junior Member
Join Date: Feb 2007
Old 03-10-2007 , 22:05   Re: get user name (HL log format)
Reply With Quote #3

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
Warthog is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-12-2007 , 09:01   Re: get user name (HL log format)
Reply With Quote #4

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    }
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Warthog
Junior Member
Join Date: Feb 2007
Old 03-12-2007 , 12:24   Re: get user name (HL log format)
Reply With Quote #5

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 is offline
Warthog
Junior Member
Join Date: Feb 2007
Old 03-14-2007 , 03:06   Re: get user name (HL log format)
Reply With Quote #6

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.
Warthog is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:33.


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