AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Replacing Player-Specific Task with Think on Player's Entity (https://forums.alliedmods.net/showthread.php?t=183971)

hleV 04-29-2012 05:41

Replacing Player-Specific Task with Think on Player's Entity
 
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.

SpeeDeeR 05-02-2012 16:50

Re: Replacing Player-Specific Task with Think on Player's Entity
 
Quote:

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



Quote:

Originally Posted by XxAvalanchexX (Post 150753)
Yes, that's fine


Exolent[jNr] 05-02-2012 16:51

Re: Replacing Player-Specific Task with Think on Player's Entity
 
You do realize that hooking a player's think is the same as using PreThink, right?

ConnorMcLeod 05-03-2012 00:39

Re: Replacing Player-Specific Task with Think on Player's Entity
 
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.

Arkshine 05-03-2012 05:08

Re: Replacing Player-Specific Task with Think on Player's Entity
 
I would not recommend to play with player's think ; it's way more simple here to use a new entity.

hleV 05-03-2012 07:05

Re: Replacing Player-Specific Task with Think on Player's Entity
 
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] (Post 1700692)
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?


All times are GMT -4. The time now is 07:51.

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