by Sajt » Wed Feb 10, 2010 6:01 pm
The proper thing is to create a new function pointer called "th_activate" or something.
.void() th_activate;
And set it for every entity that is supposed to be interacted with.
Then the player has an impulse command which traces forward, and if it hits something:
local entity oldself;
...
if (trace_ent.th_activate)
{
oldself = self;
other = self;
self = trace_ent;
self.th_activate();
self = oldself;
}
Note the setting of 'other' which lets the th_activate function do something differently based on who activates it. (If you need that.) You could also use 'activator', or even a function argument to th_activate. But using other will make a certain something easier to do for lazy programming helpers like me... (see later)
Note: Picking up weapons with this will be a little more difficult because weapons are SOLID_TRIGGER. Traces won't hit SOLID_TRIGGER items. If they were SOLID_CORPSE (a common extension not in vanilla Quake) it would be easier. If you need to support all engines though, say so and I'll tell you how to "hack" it for SOLID_TRIGGER items...
So if you want to make a door use this, simply go to the func_door function in doors.qc, and replace "self.touch = door_touch" with "self.th_activate = door_touch". That SHOULD do it. Since we set "other" when calling th_activate, everything should already be taken care of.
I haven't tested any of this though, I may have forgotten something...
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.