AlliedModders

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

drekes 12-03-2010 13:06

Optimizing question.
 
I have to hook the use of a single func_button, depending on the targetname.
It is possible that the button doesn't exist though.
So i was wondering what's the best way to hook it.

1. Hook Ham_Use and check if it's the right button there.
2. Loop through all entities at plugin_init() and use RegisterHamFromEntity.


Ofcourse you can post another method if it's better then my 2 idea's. :3


EDIT: And if i hook the button in pre and return HAM_SUPERCEDE, will that block the button to activate the stuff that it's supposed to do ?

ConnorMcLeod 12-03-2010 13:13

Re: Optimizing question.
 
RegisterHamFromEntity registers the function for a class, so it will register for all fun_button.
So, loop through all func_button, if the button is found, cache its index in a global var and register Ham_Use, "func_button", and in the callback compare the entity index.

drekes 12-03-2010 13:16

Re: Optimizing question.
 
Cool, thanks ConnorMcLeod.
What about SUPERCEDE, will it block the button from being used ?

TheKidz 12-03-2010 21:32

Re: Optimizing question.
 
returning HAM_SUPERCEDE here
PHP Code:

RegisterHamHam_Use"func_button""Button_Push_Pre" 

should be fine. i got a plugin doing this and no problem ;)

drekes 12-04-2010 14:58

Re: Optimizing question.
 
Okay, Thanks for your help.


All times are GMT -4. The time now is 11:18.

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