Raised This Month: $32 Target: $400
 8% 

Replacing Player-Specific Task with Think on Player's Entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 04-29-2012 , 05:41   Replacing Player-Specific Task with Think on Player's Entity
Reply With Quote #1

So I just wrote this and it apparently works.
Code:
#include <amxmodx> #include <engine> public plugin_init() {     register_clcmd("say /test", "OnSayTest");         register_think("player", "OnThink"); } public OnSayTest(id)     entity_set_float(id, EV_FL_nextthink, get_gametime() + 1.0); // This gets called 1 second after writing "/test" public OnThink(id)     client_print(id, print_chat, "* Think.");
However I didn't notice anyone else doing this instead of
Code:
set_task(1.0, "OnSayTest", id);
So I'm wondering if it's safe to hook player's Think? This should be much better than settings tasks for player's individually and we also avoid creating a new entity for hooking its think, if seeking performance over setting tasks.

Of course, there could only be one task per player per all the plugins at a time.

Last edited by hleV; 04-29-2012 at 05:44.
hleV is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 05-02-2012 , 16:50   Re: Replacing Player-Specific Task with Think on Player's Entity
Reply With Quote #2

Quote:
Originally Posted by KCE View Post
Is it okay to hook a think function to a player?
Code:
register_think( "player", "think_player" )


Quote:
Originally Posted by XxAvalanchexX View Post
Yes, that's fine
SpeeDeeR is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-02-2012 , 16:51   Re: Replacing Player-Specific Task with Think on Player's Entity
Reply With Quote #3

You do realize that hooking a player's think is the same as using PreThink, right?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-03-2012 , 00:39   Re: Replacing Player-Specific Task with Think on Player's Entity
Reply With Quote #4

Because pfnThink will call CBasePlayer :: PlayerDeathThink, you can use it only for alive players, as following :

- If user is alive, set nextthink to what you want.
- When Think is called, check if player is still alive.
- If player is dead, do nothing, return PLUGIN_CONTINUE
- If player is still alive, execute your code and block the function returning PLUGIN_HANDLED
- In that case, (alive player), if you want to execute something again, set nextthink to the wanted value, ELSE and that is important, set nextthink to -1.

Also, for players, i guess it's better to hook with Ham than with engine.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 05-03-2012 at 00:56.
ConnorMcLeod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-03-2012 , 05:08   Re: Replacing Player-Specific Task with Think on Player's Entity
Reply With Quote #5

I would not recommend to play with player's think ; it's way more simple here to use a new entity.
__________________

Last edited by Arkshine; 05-03-2012 at 05:08.
Arkshine is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 05-03-2012 , 07:05   Re: Replacing Player-Specific Task with Think on Player's Entity
Reply With Quote #6

I see. I've always thought that Think on player's entity would be called every player's frame, but once I found out it wasn't the case, wanted to check if it's safe. Apparently it's not worth it.
Quote:
Originally Posted by Exolent[jNr] View Post
You do realize that hooking a player's think is the same as using PreThink, right?
What about getting your facts straight instead of making yourself look like a fool?

Last edited by hleV; 05-03-2012 at 07:06.
hleV 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 20:47.


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