AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   question get_user_name (https://forums.alliedmods.net/showthread.php?t=220944)

vamppa 07-16-2013 07:57

question get_user_name
 
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

Blizzard_87 07-16-2013 08:26

Re: question get_user_name
 
with player name its best to use in local functions as a players name could change during gameplay.

vamppa 07-16-2013 12:21

Re: question get_user_name
 
ah I see in terms of having it working properly.
how about just plugin/CPU resource efficiency?

fysiks 07-17-2013 17:10

Re: question get_user_name
 
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).

vamppa 07-18-2013 14:14

Re: question get_user_name
 
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.

YamiKaitou 07-18-2013 15:23

Re: question get_user_name
 
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.

vamppa 07-24-2013 13:49

Re: question get_user_name
 
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?

fysiks 07-24-2013 14:13

Re: question get_user_name
 
Quote:

Originally Posted by vamppa (Post 1997881)
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 (Post 1997881)
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 (Post 1997881)
how exactly is caching an user steamid done?

SteamID is a string.

vamppa 07-24-2013 14:49

Re: question get_user_name
 
:) 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.

YamiKaitou 07-24-2013 15:48

Re: question get_user_name
 
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


All times are GMT -4. The time now is 06:22.

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