Monsters triggering buttons

Discuss programming in the QuakeC language.
Post Reply
silverjoel
Posts: 52
Joined: Thu Sep 30, 2010 6:46 am

Monsters triggering buttons

Post by silverjoel »

I'm trying to figure out a good way to allow monsters to trigger buttons (open certain doors, use certain plats...). The big problem is that entities with MOVETYPE_STEP don't actually come in contact with the "touch" of the button (I have changed the button touch function to include specific monsters), so that doesn't seem to be the way to go. I don't really want to change to MOVETYPE_WALK, unless I have to. It seems I can't treat a func_button as an entity, which would open up a lot of possibilities. So, I'm kinda at a loss.

I'm sure someone has this all figured out. Any help would be appreciated.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Monsters triggering buttons

Post by Spike »

rewrite movetogoal and walkmove to use traceboxes forward, and as part of that check the ents that they come in contact with.
or just add a tracebox/traceline after those calls to do it for you.

frankly the biggest issue is getting the monster to walk towards the button instead of the doorway.
Dr. Shadowborg
InsideQC Staff
Posts: 1120
Joined: Sat Oct 16, 2004 3:34 pm

Re: Monsters triggering buttons

Post by Dr. Shadowborg »

func_button should still count as an entity but since they use a brush for a model you can't use .origin on them. Use something like:

Code: Select all

self.realorigin = (self.mins + self.maxs)*0.5;
First get your monster to find the button you want it to press, then have it get the actual origin of the func_button. After that, do a vlen to determine whether the button is within pushing distance and if so, have them trigger the button. Note that by default, buttons are designed to ignore anything that isn't a player, so you'll need to do some modifications to make the code not crash because its trying to print button messages to a monster.
silverjoel
Posts: 52
Joined: Thu Sep 30, 2010 6:46 am

Re: Monsters triggering buttons

Post by silverjoel »

Thanks for the replies. I'm using waypoints with built-in functions, so traceline/tracebox on every walkmove call is not needed.

The origin trick is what I used. I already had realorigin in my functions, but didn't think to use it there for whatever reason. It's working now though, and here's the code in case anyone needs something like this.

Code: Select all

.vector func_origin;

void() waypoint_button =
{
	local entity butt, temps;

	butt = find(world, classname, "func_button");
	while(butt)
	{
		butt.func_origin = realorigin(butt);
		
		if (vlen(self.origin - butt.func_origin) <= 80)
		{
			temps = self;
			other = self;
			self = butt;
			button_touch();
			self = temps;
		}

		butt = find(butt, classname, "func_button");
	}

};
I could probably take out the temps, but I don't want to impact anything I haven't foreseen yet.

edit: one would also have to add the monster classname to the button_touch function.
Dr. Shadowborg
InsideQC Staff
Posts: 1120
Joined: Sat Oct 16, 2004 3:34 pm

Re: Monsters triggering buttons

Post by Dr. Shadowborg »

silverjoel wrote: edit: one would also have to add the monster classname to the button_touch function.
Another, better trick you can use instead of classname checks is to use a .flags & FL_MONSTER check.
silverjoel
Posts: 52
Joined: Thu Sep 30, 2010 6:46 am

Re: Monsters triggering buttons

Post by silverjoel »

Dr. Shadowborg wrote:
silverjoel wrote: edit: one would also have to add the monster classname to the button_touch function.
Another, better trick you can use instead of classname checks is to use a .flags & FL_MONSTER check.
That works, too. I only want certain monsters to be able to use buttons though, so classnames for me. I'll probably add a "can use buttons" check later, but for now, classnames.
Post Reply