Inside3D!
     

Universal "Action" Command
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
Ghost_Fang



Joined: 12 Nov 2009
Posts: 162

PostPosted: Tue Feb 09, 2010 3:47 am    Post subject: Universal "Action" Command Reply with quote

is it possible to add a function (bound to an impulse command) that will give a simple command action = 1 in a certain distance from the player view? Something i can implement on anything? such as a door, or weapon pickup, or a button? Like i said the action the player gives off will be universal, just everything interactive i will change accordingly.
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Tue Feb 09, 2010 3:58 am    Post subject: Reply with quote

yes. a traceline in your impulse handler that traces a fixed distance forward to find interactable entities is easy, so long as your entities can be hit by tracelines.
Weapon pickups probably can't be found that way (they'd need to be solid!). You'd need to do a findradius for those, presumably, which isn't too awkward.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Dr. Shadowborg
Inside3D Staff


Joined: 16 Oct 2004
Posts: 726

PostPosted: Tue Feb 09, 2010 4:11 am    Post subject: Reply with quote

Some good starting material to look at for this:

http://forums.inside3d.com/viewtopic.php?t=1831
_________________
"Roboto suggests Plasma Bazooka."
Back to top
View user's profile Send private message
Ghost_Fang



Joined: 12 Nov 2009
Posts: 162

PostPosted: Tue Feb 09, 2010 4:26 am    Post subject: Reply with quote

would it work if i derived it from the axe weapon, and have the traceline do action() instead of attack or something? (minus the models and anims etc)
Back to top
View user's profile Send private message
Dr. Shadowborg
Inside3D Staff


Joined: 16 Oct 2004
Posts: 726

PostPosted: Tue Feb 09, 2010 5:06 am    Post subject: Reply with quote

It should, that's what I did for the interaction in that NPC code. Note however that you may have to do different things to get the same result on different objects. e.g. doors and buttons vs. NPCs
_________________
"Roboto suggests Plasma Bazooka."
Back to top
View user's profile Send private message
Ghost_Fang



Joined: 12 Nov 2009
Posts: 162

PostPosted: Tue Feb 09, 2010 5:55 am    Post subject: Reply with quote

well my idea is to have the action send out a generic "action = 1" command, and each interactive entity will have a simple:
if (self.action == 1)
{
do all the stuff i want etc.
}

But i really have no idea how to SEND a command to another entity within a given range. And editing the axe didnt work.
Here is my work of fail:

Code:
/*
======
Action
======
*/

void(entity targ) Action =
{
targ.action = 1;
};

void() ActionCommand =
{
   local   vector   source;
   local   vector   org;

   makevectors (self.v_angle);
   source = self.origin + '0 0 16';
   traceline (source, source + v_forward*64, FALSE, self);
   if (trace_fraction == 1.0)
      return;
   
   org = trace_endpos - v_forward*4;

   if (trace_ent.takedamage)
   {
      trace_ent.axhitme = 1;
      Action (trace_ent);
   }
};
Back to top
View user's profile Send private message
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Tue Feb 09, 2010 6:04 am    Post subject: Reply with quote

org has no purpose and axehitme just makes the player yelp.
Back to top
View user's profile Send private message
Dr. Shadowborg
Inside3D Staff


Joined: 16 Oct 2004
Posts: 726

PostPosted: Tue Feb 09, 2010 4:19 pm    Post subject: Reply with quote

Ghost_Fang wrote:

But i really have no idea how to SEND a command to another entity within a given range. And editing the axe didnt work.
Here is my work of fail:

Code:
/*
======
Action
======
*/

void(entity targ) Action =
{
targ.action = 1;
};

void() ActionCommand =
{
   local   vector   source;
   local   vector   org;

   makevectors (self.v_angle);
   source = self.origin + '0 0 16';
   traceline (source, source + v_forward*64, FALSE, self);
   if (trace_fraction == 1.0)
      return;
   
   org = trace_endpos - v_forward*4;

   if (trace_ent.takedamage)
   {
      trace_ent.axhitme = 1;
      Action (trace_ent);
   }
};


This won't work because most doors and buttons aren't damagable.

Change it so that it's like this or something:

Code:
/*
======
Action
======
*/

void(entity targ) Action =
{
targ.action = 1;
};

void() ActionCommand =
{
   local   vector   source;

   makevectors (self.v_angle);
   source = self.origin + '0 0 16';
   traceline (source, source + v_forward*64, FALSE, self);
   if (trace_fraction == 1.0)
      return;
   
                 if (trace_ent != world)
                   Action (trace_ent);
};


That should work I think.
_________________
"Roboto suggests Plasma Bazooka."
Back to top
View user's profile Send private message
frag.machine



Joined: 25 Nov 2006
Posts: 728

PostPosted: Wed Feb 10, 2010 2:30 am    Post subject: Reply with quote

As is, this code can call Action() even for dead entities. Dunno if it's desirable, if not a simple "&& (trace_ent.health > 0)" fixes the issue.
_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/
Back to top
View user's profile Send private message Visit poster's website
Ghost_Fang



Joined: 12 Nov 2009
Posts: 162

PostPosted: Wed Feb 10, 2010 3:37 am    Post subject: Reply with quote

I understand how you said how somethings arent damageable, but i tested on a enemy, i made the enemy code, if (self.action == 1) self.health == 0 and it didnt do anything. So im doing something else wrong i think ... :\
Back to top
View user's profile Send private message
ceriux



Joined: 06 Sep 2008
Posts: 969
Location: Florida, USA

PostPosted: Wed Feb 10, 2010 3:52 am    Post subject: Reply with quote

in the entite code did you set self.action = 0; ?
_________________
QuakeDB - Quake ModDB Group
Back to top
View user's profile Send private message Yahoo Messenger
Dr. Shadowborg
Inside3D Staff


Joined: 16 Oct 2004
Posts: 726

PostPosted: Wed Feb 10, 2010 5:21 am    Post subject: Reply with quote

Ghost_Fang wrote:
I understand how you said how somethings arent damageable, but i tested on a enemy, i made the enemy code, if (self.action == 1) self.health == 0 and it didnt do anything. So im doing something else wrong i think ... :\


That's because enemies (monsters) don't function normally enough for that to work. (unless you're calling that every stand, walk, attack, etc. frame) Also, if that's the case, and you were expecting it to die, you should know that if you want it to die you need to use T_Damage to do all that. (they don't check to see if they are supposed to die otherwise...)

Someday I am going to have to make a tutorial that will help to alleviate this issue so that you can add an all-in-one monster_subthink where you can do stuff like this... (I've already done partial monster_subthink stuff for Hellsmash and RemakeQuake's Enforcer Overwatch ability. Unless they've taken that stuff out after I'd left...)

Needless to say the proper procedure for getting a door or button to do the same thing is going to be different.


frag.machine wrote:
As is, this code can call Action() even for dead entities. Dunno if it's desirable, if not a simple "&& (trace_ent.health > 0)" fixes the issue.


That defeats the whole purpose of using this for doors and buttons that aren't damagable normally.

Also, most (assuming that he's following standard quake style) fully dead entities won't be touchable with this because most dead entities are by this point SOLID_NOT. Even if this wasn't the case though, the way Ghost_Fang is implimenting this it would only work if he added code for interaction.
_________________
"Roboto suggests Plasma Bazooka."
Back to top
View user's profile Send private message
Ghost_Fang



Joined: 12 Nov 2009
Posts: 162

PostPosted: Wed Feb 10, 2010 5:26 pm    Post subject: Reply with quote

So how would i "send" commands through a trace? All it would be for is for helping a player up from being incapped, weapon pickup, and MAYBE opening doors if its possible.
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Wed Feb 10, 2010 5:59 pm    Post subject: Reply with quote

You can "send" commands the same way pain or death is "sent", or the same way as regular triggers.
The bottom part of SUB_UseTargets might give you a hint.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Wed Feb 10, 2010 6:01 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group