Raised This Month: $ Target: $400
 0% 

Automaton or native to disable forward & OT discussion about detecting ground touch


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Astro
Member
Join Date: Jul 2011
Old 04-16-2013 , 18:07   Automaton or native to disable forward & OT discussion about detecting ground touch
Reply With Quote #1

Hello, I came across an interesting question that I'm having a hard time trying to answer. Which of the following snippets contains more efficient code? Is there a better way to enable / disable the hook?

Code:
Function() {     if(something)     {         state PreThink:enabled;     } } public client_PreThink(id) <PreThink:enabled> {     if(something)     {         state PreThink:disabled;         // some code     } } public client_PreThink(id) <PreThink:disabled> {} public client_PreThink(id) <> {}

Code:
new forward_PreThink; Function() {     if(!forward_PreThink && something)     {         forward_PreThink = register_forward(FM_PlayerPreThink, "OnPreThink");     } } public OnPreThink(id) {     if(something)     {         unregister_forward(FM_PlayerPreThink, forward_PreThink);         forward_PreThink = 0;         // some code     } }

Code:
new HamHook:hook_Player_PreThink; public plugin_init() {     hook_Player_PreThink = RegisterHam(Ham_Player_PreThink, "player", "OnPlayer_PreThink"); } Function() {     if(something)     {         EnableHamForward(hook_Player_PreThink);     } } public OnPreThink(id) {     if(something)     {         DisableHamForward(hook_Player_PreThink);         // some code     } }

Last edited by Astro; 04-17-2013 at 18:20. Reason: Added Ham version
Astro is offline
 



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 10:45.


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