AlliedModders

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

Drak 05-21-2007 22:23

Optimizations?
 
I was looking through a few of my plugins, and noticed I use a lot of functions/natives over again. (get_user_name,authid,time, etc, etc)

Would it be better to make a global variable for this? So i can just retrieve the players name/authid or whatever, without having to re-use that function over again.

And, let's say I went with this. And I have a array like so:
"g_playerName[33][64]"

and place the users name, and player index into it. How would i zero this out, so when the next player connects, it wont cause problems?
Would this be correct? "g_playerName[id][id] = 0"

pRED* 05-21-2007 22:48

Re: Optimizations?
 
Are you saving g_playerName[id] as a string of length 64? And reading from it as a string?

If so you can do g_playerName[id][0]='^0'

If you are using 64 integers then you will need to loop and erase them individually

http://wiki.amxmodx.org/Optimizing_P...ables_in_Loops explains this particular way of erasing strings efficiently (rest of the page is definately worth reading too)

Drak 05-21-2007 23:03

Re: Optimizations?
 
Quote:

Originally Posted by pRED* | NZ
Are you saving g_playerName[id] as a string of length 64? And reading from it as a string?

If so you can do g_playerName[id][0]='^0'

Yeah, a string a length of 64. Thanks for the answer.

Now just back to my first question :P
Unless i totally missed something on that wiki page.

pRED* 05-21-2007 23:10

Re: Optimizations?
 
I guess it would depend on what the exact it was (and how variable it is).

Caching the users authid on connect would definately be good if you are going to use it multiple times later on. Authid is constant so theres no point getting it lots of times.
Exceptions to this would be a ban command because theres a 90 something percent change that a specifc user wouldn't get banned that map so caching the authid on connect would be a waste.

Users name: depends... Yes it would be more efficient but you might want to hook the command "name" so you can update it if they change their name. Or just call it when it's needed.. Your choice I guess.

Time??

Drak 05-22-2007 00:12

Re: Optimizations?
 
I was referring to "get_user_time". Which....doesn't make much sense now that i think about it..
But yeah, thanks for the info.

pRED* 05-22-2007 02:06

Re: Optimizations?
 
For the get user time you could use get_systime or get_gametime and cache the result on connect and then recheck it when you want to know a players connection time and find the difference in the numbers (they are seconds as an integer). Probably less efficient tho..


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

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