AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How properly count/use cycles of ent think (https://forums.alliedmods.net/showthread.php?t=250422)

avril-lavigne 10-24-2014 13:33

How properly count/use cycles of ent think
 
This is my maybe third try to use entity think
it works
I just want to know how to count each think and do something in it in correct way

PHP Code:


new wtf

public ctfthink(ent)
{
  if(!
is_valid_ent(ent)) return      
  
set_pev(ent,pev_nextthinkhalflife_time() + 5.0)
   
wtf++    
   if(
wtf 5
   {
     
// do something on 5th think
    
}


is there another way to do so?

HamletEagle 10-24-2014 14:02

Re: How properly count/use cycles of ent think
 
This may be stupid, to do something different on each think. This sound like an XY problem, you should explain what are you trying to do. You can increase the wtf variable and create a switch, but this is still a bad way. Again, explain what are you actually trying to do.

claudiuhks 10-24-2014 14:41

Re: How properly count/use cycles of ent think
 
PHP Code:

var = 0

think
()
{
  switch (++var)
  {
    case 
1:
    {

    }

    case 
2:
    {

    }

    default:
    {
       
// this will execute when var is > 2
       // ensure var will never exceed 2147483647
    
}
  }


Ref

avril-lavigne 10-24-2014 19:23

Re: How properly count/use cycles of ent think
 
I want to check ent state if its == 3 return it to base

PHP Code:



    set_pev
(ent,pev_nextthinkget_gametime() + 25.0 //  will this count 25 sec only on NEXT think not now?   
    
set_pev(ent,pev_originbase

so it moves ent immediately. I need 30sec delay ... thats why I tried wtf 5sec* 5 cycles

Nextra 10-24-2014 22:10

Re: How properly count/use cycles of ent think
 
Without more detail this looks like it would be way better suited for a task. Also why do you want to have 5 steps of 5 seconds instead of just one of 25? Please tell us what you actually want to achieve.

klippy 10-25-2014 08:51

Re: How properly count/use cycles of ent think
 
Well, if you really need to count cycles, I would prefer static local variable to do so.
But, however, I agree with Nextra - you should provide more information of what you are trying to achieve.

avril-lavigne 10-25-2014 14:33

Re: How properly count/use cycles of ent think
 
PHP Code:

public ctfthink(ent)
{
         if(!
is_valid_ent(ent)) return      
         
set_pev(ent,pev_nextthinkhalflife_time() + 5.0//check ent status each 5 sec

         
if(getstatus(ent) == 3// dropped state. 
         
{
              
dd++    
              if(
dd 5)   // got 30 sec delay. 6*5 times
              
{
                              
                               
set_pev(ent,pev_originoct)  // go to base
                           
status(ent,1)  // on base
                           
dd 0      
              
}             
        }
         else 
dd // ent status 3 was interrupted by a player , clear counter


If put nextthink 30 sec right after needed state (3). It wont count delay NOW . Also if it sleeps 30 sec - what if someone picked up ent in that period and entity state was changed? so I cant wait 30sec at once. So I need to check ent state each few seconds to make sure it was dropped and stay in the same state 30sec before going to base.

claudiuhks 10-26-2014 04:47

Re: How properly count/use cycles of ent think
 
I can't get a word from what you say. What do you mean "after needed state (3)", "delay NOW"? What these references are?

NiHiLaNTh 10-26-2014 06:13

Re: How properly count/use cycles of ent think
 
Just tell what you want to do, because I cant understand what you want.


All times are GMT -4. The time now is 17:38.

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