AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   what is faster? switch or an array? (https://forums.alliedmods.net/showthread.php?t=88984)

Speed! 03-31-2009 13:41

what is faster? switch or an array?
 
PHP Code:

damage *= weapon_damage[get_weapon_id.... 

or
PHP Code:

switch (get_weapon_id...
{
case 
CSW_DEAGLEdamage *= 

which is better? this would be called in ham_takedam

Arkshine 03-31-2009 13:46

Re: what is faster? switch or an array?
 
I guess the first.

Exolent[jNr] 03-31-2009 13:49

Re: what is faster? switch or an array?
 
I always use an array for something like that.

Speed! 03-31-2009 14:03

Re: what is faster? switch or an array?
 
I don't really know, coz 1 method requieres more functions to be called in order to obtain the weapon id, etc... Actually I don't really know how to make it work the first method, since this needs something like weapon_deagle instead of CSW_DEAGLE...
Could anyone help me?

hleV 03-31-2009 14:10

Re: what is faster? switch or an array?
 
Use switch.

ot_207 03-31-2009 14:14

Re: what is faster? switch or an array?
 
Array good to use because:
-> fast access
-> easy to write
Bad:
-> uses memory unfortunately

Switch:
Good:
-> doesn't use memory
Bad:
-> hard to write (sometimes)

In this case I would advise the first ...

Exolent[jNr] 03-31-2009 14:35

Re: what is faster? switch or an array?
 
Quote:

Originally Posted by Speed! (Post 794135)
I don't really know, coz 1 method requieres more functions to be called in order to obtain the weapon id, etc... Actually I don't really know how to make it work the first method, since this needs something like weapon_deagle instead of CSW_DEAGLE...
Could anyone help me?

http://www.amxmodx.org/funcwiki.php?go=func&id=1081

ConnorMcLeod 03-31-2009 16:24

Re: what is faster? switch or an array?
 
Where do you get the weapon name ?
You should be able to retrieve directly weapon id. (if attacker = inflictor, use get_user_weapon )


All times are GMT -4. The time now is 02:20.

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