Entity that executes a function when touched.

Discuss programming in the QuakeC language.
Post Reply
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Entity that executes a function when touched.

Post by DusterdooSmock »

How would i go about creating an entity, sort of like a weapon spawn, except the player doesn't pick up the item, that can be placed on a map, and when the player touches the entity, if an impulse is entered, then a function is executed.

Thanks.
Last edited by DusterdooSmock on Tue Nov 16, 2010 5:58 am, edited 1 time in total.
something
Posts: 27
Joined: Tue Apr 20, 2010 2:02 pm
Location: Melbourne,Au

Re: Entity that executes a function when touched.

Post by something »

like a pickup system..?

i used a traceline with a constant of PLAYER_PICKUP_DISTANCE.

then you can just make a pickup impulse check the trace_ent if its a pickup(i created a field item_type)
if it is.. you run a function or something.

that way you have to be looking at the entity for it to work.
probably slower with a traceline though
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post by frag.machine »

Code: Select all

float FOOBAR_IMPULSE = 99;

void () foobar_touch =
{
    if (other.impulse == FOOBAR_IMPULSE)
    {
      // does something
        other.impulse = 0;
    }
};

void () foobar_trigger =
{
    (...)
    self.touch = foobar_touch;
    (...)
};
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Post by DusterdooSmock »

Thanks, but how would i get it to remove the spawned model when the impulse is entered? :?

Is it just remove(self); ?
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post by frag.machine »

remove (self) will wipe out the entity for good. If what you want is something like deathmatch/coop item respawn you should take a careful look in items.qc.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Mexicouger
Posts: 514
Joined: Sat May 01, 2010 10:12 pm
Contact:

Post by Mexicouger »

Yea, you would make the just have to make it inactive or something/
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Post by DusterdooSmock »

I just need it to remove the model. The entity needs to respawn.
Arkage
Posts: 66
Joined: Thu Nov 19, 2009 4:17 pm

Post by Arkage »

setmodel(self, "");
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Post by DusterdooSmock »

Arkage wrote:setmodel(self, "");
Why did that have to be so easy? :o I'm surprised i didn't think of that before..

Thanks to all of you. ;)
Post Reply