Raised This Month: $ Target: $400
 0% 

question get_user_name


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 07-16-2013 , 07:57   question get_user_name
Reply With Quote #1

for information like getting players name, steamid would it more efficient to get them one time on client_putinserver and use i.e. zName where ever u need them through out a large plugin?
or to get the information only where u need them?

PHP Code:
#include <amxmodx> 
#include <amxmisc>
#include <engine>

new zhostname[64], zmapname[64], zName[32], zCID[32], zTimedata[27], zIP[30];

public 
client_putinserver(id
{
    
get_user_name(idzName31);
    
get_cvar_string("hostname"zhostname,63);
    
get_mapname(zmapname,63);
    
get_time "%A %d %b %Y %H:%M"zTimedata26 );
    
get_user_authididzCID31 );
    
get_user_ipidzIP29);
  }

what about mapname, hostname and time where would it best to get them?

i.e. = In example

Last edited by vamppa; 07-16-2013 at 07:59. Reason: edited title.
vamppa is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 07-16-2013 , 08:26   Re: question get_user_name
Reply With Quote #2

with player name its best to use in local functions as a players name could change during gameplay.
__________________
Blizzard_87 is offline
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 07-16-2013 , 12:21   Re: question get_user_name
Reply With Quote #3

ah I see in terms of having it working properly.
how about just plugin/CPU resource efficiency?
vamppa is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-17-2013 , 17:10   Re: question get_user_name
Reply With Quote #4

There is no reason to cache the information unless you use it often or need to loop through all of them quickly. Also, your example will only work correctly for mapname and hostname (assuming the hostname doesn't change).
__________________
fysiks is offline
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 07-18-2013 , 14:14   Re: question get_user_name
Reply With Quote #5

yeah I will be using name and steamid often. maybe IP as well.
so in this case in terms of plugin/CPU resource efficiency these would be best fetched on client_putinserver ?
it wont matter if someone changes name during game and thus not displaying the correct name after fetching it.
as long as the steamid shows up correctly.
vamppa is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-18-2013 , 15:23   Re: question get_user_name
Reply With Quote #6

It is best to get the name each time you need to use it. A player's SteamID will never change though, so that can be cached if you need it to be.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 07-24-2013 , 13:49   Re: question get_user_name
Reply With Quote #7

what about replacing new with static ?
will that use less CPU ?
http://forums.alliedmods.net/showthread.php?t=40340

to Yamkikaitoe, I dont follow why it would be most resource friendly to get name each time I need it.
since that is what im asking, I dont mind if the nick gets changed.
rather get it one time and use memory, saving CPU usage.
or could it show up someone else his name due to player indexing over time?
how exactly is caching an user steamid done?
vamppa is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2013 , 14:13   Re: question get_user_name
Reply With Quote #8

Quote:
Originally Posted by vamppa View Post
what about replacing new with static ?
will that use less CPU ?
Regarding static variable and CPU usage, it's more important to understand the context of the variable in question. Static variables are most often used in functions that are called really often so you don't take the time to reallocate the memory for it. If you are using it in a chat command or admin command, you don't need it.

Most of the time, you can get a way with using a plain global.


Quote:
Originally Posted by vamppa View Post
to Yamkikaitoe, I dont follow why it would be most resource friendly to get name each time I need it.
since that is what im asking, I dont mind if the nick gets changed.
rather get it one time and use memory, saving CPU usage.
or could it show up someone else his name due to player indexing over time?
Getting the name when you need it is usually done because it makes sense. If, for some odd reason, you don't care if the name is correct then you can cache it (if you don't care about the accurateness of the name then you should just get rid of it entirely, IMO). Also, depending on how you use the name, it might not work if it's not up-to-date.

There are ways to cache and keep names up-to-date but I would not recommend them for you.


Quote:
Originally Posted by vamppa View Post
how exactly is caching an user steamid done?
SteamID is a string.
__________________

Last edited by fysiks; 07-24-2013 at 14:14.
fysiks is offline
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 07-24-2013 , 14:49   Re: question get_user_name
Reply With Quote #9

thanks, so I can use static for getting steamid?
PHP Code:
static sCID[32];

public 
client_putinserver(id
{
    
get_user_authididsCID31 );

is it good to use on variables that dont get changed often? (mapname,hostname)
do statics get refreshed on map change?

Quote:
Getting the name when you need it is usually done because it makes sense. If, for some odd reason, you don't care if the name is correct then you can cache it (if you don't care about the accurateness of the name then you should just get rid of it entirely, IMO). Also, depending on how you use the name, it might not work if it's not up-to-date.
yeah your right about getting rid of the name but believe it or not for this mod its mainly used for easy reference to know who the person is. we are a small community that know eachother by their registered names. just putting an easy face behind the steamid if the name is correct.
otherwise we look up their steamid in our database, it saves a lot of time if we dont always have to do this. I do have concerns about it not working propperly on One idea I have in mind but not yet started working on, so will see : )
Quote:
There are ways to cache and keep names up-to-date but I would not recommend them for you.
ok I'll take your word for it but am curious as to why? is it an cpu consuming method ?
which wouldn't make sense as it sounds like thats what the method is trying to avoid.

could you give me an example of how to cache getting steamid ?
am pretty new to this and want to learn.
vamppa is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-24-2013 , 15:48   Re: question get_user_name
Reply With Quote #10

You are digging way to much into this "optimization" thing. Don't optimize because you can, optimize because it should be. There are some things that you should not optimize as it ends up hurting the usability or readability of the plugin
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Reply



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 06:22.


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