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

Entity Think / Timer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 03-29-2013 , 16:55   Entity Think / Timer
Reply With Quote #1

Hi All,

I have been slowly transitioning a mod from CS 1.6 to CS:GO and I have run into a road block.

The issue I am dealing with is creating an entity that needs to be hooked in changing intervals of time. Also, the entity needs to be able to touch and have a model assigned to it.

I have looked into using entity input/output using OnUser# and FireUser#, but from my understanding, I will not be able to change the interval time for these calls.

While I know that I can use timers to accomplish this, I would rather not clog up the SourceMod timers for the potential of having many of these entities.

Any insight and advice you can provide is much appreciated.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 03-29-2013 , 18:29   Re: Entity Think / Timer
Reply With Quote #2

I don't fully understand what exactly you want to hook, but maybe Sdk Hooks is what you are looking for.
It's included in the 1.5+ Snapshots of sourcemod.

Yours sincerely
Impact
__________________
Impact123 is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 03-29-2013 , 18:51   Re: Entity Think / Timer
Reply With Quote #3

if i got what you asked, you can use 2 onuser, one for working as a timer and the other one for calling the callback. but, i think there is no problem in using thousands of timers. or you could even make your own timer, using some think hook of sdkhooks.
the last 2 methods are quite easy, but if you want the onuser thing, try using this:
Code:
new ent = CreateEntityByName("fndsikaf");
HookSingleEntityOutput(ent, "OnUser1", EntThink);
new String:output[64] = "OnUser2 !self:FireUser1::1.0:-1"; //1.0 = 1 second of delay.
SetVariantString(output);
AcceptEntityInput(ent, "AddOutput");
AcceptEntityInput(ent, "FireUser2");

public EntThink(const String:output[], caller, activator, Float:delay){

    AcceptEntityInput(caller, "FireUser2");

}
Bimbo1 is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 03-29-2013 , 18:56   Re: Entity Think / Timer
Reply With Quote #4

i sounded arrogant. the last two methods might not be that easy to do.
Bimbo1 is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 03-29-2013 , 21:01   Re: Entity Think / Timer
Reply With Quote #5

@Impact123: I did look into using SDKHook_Think, but I do not know too much about the different entity classes in source. Is there an entity that I can use that "thinks", "touches", and can be assigned a model?

@Bimbo1: I am aware of that method that you provided, but like I said previously, I need to be able to change the interval time. Is there a way to clear an entity's I/O and then I can add the output again? If I add an additional output, I assume it would still call the original output and the new output (based on how I believe entity I/O works).

As for the idea of making my own timer, while that would be possible, it would require looping through the entities to check their times, and at that rate it would most likely be better to just use timers.

Here is a basic example for what I am trying to do:

Code:
public EntityThink( iEnt )
{
   //Do some stuff...

   new Float:fThinkTime = GetEntityTime( iEnt );
   //Set next think time for entity to fThinkTime
}
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 03-29-2013 , 21:35   Re: Entity Think / Timer
Reply With Quote #6

i guess i got it now. you don't want the timer to be a fixed value, you want it to be changed several times. try doing something like this:
Code:
new Float:Timer[2048];

new ent = CreateEntityByName("fndsikaf");
HookSingleEntityOutput(ent, "OnUser1", EntThink);
new String:output[64] = "OnUser2 !self:FireUser1::0.0:-1";
SetVariantString(output);
AcceptEntityInput(ent, "AddOutput");
AcceptEntityInput(ent, "FireUser2");
Timer[ent] = GetEngineTime()+10.0;

public EntThink(const String:output[], caller, activator, Float:delay){

    new Float:now = GetEngineTime();
    if(now >= Timer[caller]){

        //Do something
        Timer[caller] = now+GetRandomFloat(0.0, 30.0);

    }    
    AcceptEntityInput(caller, "FireUser2");

}
in this example, "do something" will happen in different intervals.

Last edited by Bimbo1; 03-29-2013 at 21:38. Reason: forgot a ;
Bimbo1 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-30-2013 , 08:31   Re: Entity Think / Timer
Reply With Quote #7

Since I haven't seen it mentioned yet, what kind of entity are you creating?

Most of the time, for an in-world object, you'll want a prop_physics or prop_physics_override; I've never been clear on the difference between these two, I just assumed the latter ignores physics rules.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 03-30-2013 , 12:11   Re: Entity Think / Timer
Reply With Quote #8

i dont know if it's related to the thread, but i think ive already read something regarding to that. prop_physics is meant for props compiled with physics data. though, if u have a prop which wasn't made to work physically, like dynamic props, prop_physics won't work, u would have to use the physics_override to make generically physical.
__________________
sie sind das essen und wir sind die jäger!
Bimbo1 is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 03-30-2013 , 20:39   Re: Entity Think / Timer
Reply With Quote #9

@Bimbo1: That method will result in way too many unnecessary calls.

@Powerlord: I will probably be using prop_physics_override (I don't really need any physics on the entities, other than gravity on some of them) unless there is a "better" class to use.

I will probably just use timers to accomplish this. Thanks for the help guys.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 03-31-2013 , 00:42   Re: Entity Think / Timer
Reply With Quote #10

Quote:
Originally Posted by Emp` View Post
@Bimbo1: That method will result in way too many unnecessary calls.

@Powerlord: I will probably be using prop_physics_override (I don't really need any physics on the entities, other than gravity on some of them) unless there is a "better" class to use.

I will probably just use timers to accomplish this. Thanks for the help guys.
yes, it's better creating timers. anyway, keep in mind that it's better not because a function being called every frame is wrong, but because sourcemod only check all the timers every 0.1 second, instead of checking them every frame. to do that timer of 0.1 second, sourcemod checks a variable every game frame like i did, which are not unnecessary calls. so, calling something every frame is going to happen either way, but sourcemod's timer is smarter because of that imprecision of 0.1 second, which is not big deal.
Bimbo1 is offline
Reply


Thread Tools
Display Modes

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 08:59.


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