AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Not Working] Thinking Entity as Timer (https://forums.alliedmods.net/showthread.php?t=281714)

gabuch2 04-18-2016 15:04

[Not Working] Thinking Entity as Timer
 
Hello

I found this snippet in this forum, however it doesn't work.
Can someone tell me what's wrong or what am I missing?

PHP Code:

[...]
   new 
Ent engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
   
set_pev(Ent,pev_classname,g_Classname)
   
set_pev(Ent,pev_nextthink,1.0)
   
register_forward(FM_Think,"ForwardThink")
}

public 
ForwardThink(Ent)
{
   if(
get_pcvar_num([enabled]) || !b_DamagedRecently || GetPlayerCount(2) == 0)
      return 
FMRES_IGNORED

   
static Classname[33]
   
pev(Ent,pev_classname,Classname,32)
   if(!
equal(Classname,g_Classname))
      return 
FMRES_IGNORED   
      
   
[integer]--
   
set_pev(Ent,pev_nextthink,1.0)

   return 
FMRES_HANDLED


Thanks in advance

SkumTomteN 04-18-2016 15:46

Re: [Not Working] Thinking Entity as Timer
 
what do u want it to do?

Bugsy 04-18-2016 17:10

Re: [Not Working] Thinking Entity as Timer
 
PHP Code:

new g_Entity;

g_Entity create_entity"info_target" );
entity_set_stringg_Entity EV_SZ_classname "MyThinkingEntity" );
register_think"MyThinkingEntity" "EntityThink" );

public 
EntityThinkiEntity )
{
    if( 
iEntity == g_Entity 
    {
        
//Do stuff here

        
entity_set_floatg_Entity EV_FL_nextthink , ( get_gametime() + 1.0 ) );
    }



gabuch2 04-18-2016 17:13

Re: [Not Working] Thinking Entity as Timer
 
Quote:

Originally Posted by Bugsy (Post 2412173)
PHP Code:

new g_Entity;

g_Entity create_entity"info_target" );
entity_set_stringg_Entity EV_SZ_classname "MyThinkingEntity" );
register_think"MyThinkingEntity" "EntityThink" );

public 
EntityThinkiEntity )
{
    if( 
iEntity == g_Entity 
    {
        
//Do stuff here

        
entity_set_floatg_Entity EV_FL_nextthink , ( get_gametime() + 1.0 ) );
    }



Does nextthink requires the exact time to execute the next think cycle? Makes sense why my code wasn't working.

Black Rose 04-19-2016 10:33

Re: [Not Working] Thinking Entity as Timer
 
Yes.
Both functions do basically the same things AFAIK, just in different ways.


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

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