Raised This Month: $ Target: $400
 0% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
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
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 04-16-2013 , 18:10   Re: Automaton or fakemeta?
Reply With Quote #2

Automaton will always be more or equally efficient. If you have a good reason to use it (such as yours), do it.
Backstabnoob is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-17-2013 , 02:41   Re: Automaton or fakemeta?
Reply With Quote #3

It could depend on what you want to do.

Also, pay attention to if(!forward_PreThink & something), should be && ;)
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 04-17-2013 at 02:42.
ConnorMcLeod is offline
Astro
Member
Join Date: Jul 2011
Old 04-17-2013 , 16:00   Re: Automaton or fakemeta?
Reply With Quote #4

Thank you for your answers. :) You're right about the &&, I don't know what happend there. :D
Anyway, in which case is fakemeta way more efficient than the first one? I would like to know whether changing state and calling empty client_PreThink(id) <> {} has any negative impact on performance.

Last edited by Astro; 04-17-2013 at 16:39.
Astro is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-17-2013 , 16:42   Re: Automaton or fakemeta?
Reply With Quote #5

I'm not familiar with automatons, just feel better to disable such a forward when you don't need, would use Ham_Player_PreThink.
About pure theory, i don't know if someone can answer you.

Can see http://forums.alliedmods.net/showthread.php?p=958497.

Anyway, what are you hooking PreThink for ?
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 04-17-2013 at 16:45.
ConnorMcLeod is offline
Astro
Member
Join Date: Jul 2011
Old 04-17-2013 , 17:09   Re: Automaton or fakemeta?
Reply With Quote #6

I'm mostly interested in automatons as I don't know much about them and I'd like to learn new stuff, so this was a general example but hey, I've found use for this in one of my plugins. I'm blocking any damage dealt to player before they touch ground after spawn (for example maps where players spawn in air and fall down to start with less than 100hp but I don't want to block damage after then).
  1. Spawn
  2. Disable damage
  3. Enable prethink hook
  4. Check for flags like FL_ONGROUND
  5. Disable prethink hook
  6. Enable damage
Edit: Ad Ham_Player_PreThink, I'm actually using this one instead FM, but the question stands still. I'm not much familiar with them either so I'm trying to solve a question about the actual usefulness of the DisableHamForward() and unregister_forward() functions. I believe that the difference would not be significant but I'm just curious. ;)

Last edited by Astro; 04-17-2013 at 17:27.
Astro is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-17-2013 , 17:48   Re: Automaton or fakemeta?
Reply With Quote #7

There are often alternative to PreThink hook.

In the example you gave it is not even an alternative, because PreThink shouldn't be hooked for that.
All you have to do is to hook Ham_TakeDamage and to check if last bit param contains bit DMG_FALL.

So before to worry about what it the best between automaton with prethink and disabling prethink forward, you should first ask yourself if there could be better ways to achieve what you want to do.
You can also ask on forum when you have such a question and you don't find an answer by yourself ;)
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Astro
Member
Join Date: Jul 2011
Old 04-17-2013 , 17:56   Re: Automaton or fakemeta?
Reply With Quote #8

I'm sorry but I don't really see the way how do it your way. If hooked Ham_TakeDamage and the player had fallen from just a few units after spawn Ham_TakeDamage would not be called and if they had fallen from some high place afterwards the damage would be blocked then which in many cases could mess things up. Say I have three maps: first one with spawnpoints high up in the air, second one with trigger_hurt or whatever is it called with spawnpoints nearly on the ground and third one with none of these. I would like do enable damage right after the player touches ground in every of these maps. I don't want to customize my plugin for each map I add to my server.

Edit: I don't mean to be offensive, I'm sorry if it looks like that, my English is terrible.

Last edited by Astro; 04-17-2013 at 18:06.
Astro is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-18-2013 , 02:43   Re: Automaton or fakemeta?
Reply With Quote #9

Quote:
Originally Posted by Astro View Post
I'm sorry but I don't really see the way how do it your way. If hooked Ham_TakeDamage and the player had fallen from just a few units after spawn Ham_TakeDamage would not be called and if they had fallen from some high place afterwards the damage would be blocked then which in many cases could mess things up. Say I have three maps: first one with spawnpoints high up in the air, second one with trigger_hurt or whatever is it called with spawnpoints nearly on the ground and third one with none of these. I would like do enable damage right after the player touches ground in every of these maps. I don't want to customize my plugin for each map I add to my server.

Edit: I don't mean to be offensive, I'm sorry if it looks like that, my English is terrible.
You are not offensive at all, it is nice to be able to discuss things

If you also want to detect when player touchs ground when he doesn't take any damage, then there might be no other way, can't see any other way right now.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
guipatinador
SourceMod Donner Party
Join Date: Oct 2009
Location: Poortugal
Old 04-17-2013 , 18:01   Re: Automaton or fakemeta?
Reply With Quote #10

Hook Ham_TakeDamage at new round and disable it at start round.
guipatinador is offline
Reply



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