Page 1 of 1

Monsters triggering buttons

Posted: Wed May 10, 2017 8:30 pm
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.

Re: Monsters triggering buttons

Posted: Wed May 10, 2017 10:13 pm
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.

Re: Monsters triggering buttons

Posted: Wed May 10, 2017 10:24 pm
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.

Re: Monsters triggering buttons

Posted: Thu May 11, 2017 4:17 pm
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.

Re: Monsters triggering buttons

Posted: Thu May 11, 2017 9:38 pm
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.

Re: Monsters triggering buttons

Posted: Thu May 11, 2017 10:59 pm
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.