Checking if a player is within a certain zone

I have a ttt_traitor_button in my TTT map, but I only want it to be used if the traitor who presses it is inside the room. Obviously a ttt_traitor_button can be seen and used through walls, and I don’t want that to be possible in this instance.
I originally posted about this in the mapping section, but was told that it isn’t possible unless I used lua code run by a lua_run entity in my map. Unfortunately I’m a beginner with lua coding and am not sure where to start…

When the player presses the floating traitor button, how could I use a lua_run to test if the traitor who activated the button is inside the room and only fire the output if he is?

I appreciate any help given.

You can’t fix this with lua_run entity. You gotta either edit the ttt button entity or create your own entity.

[lua]function IsOnlyPlayerInRadius( _player, origin, radius )
for k,v in pairs( ents.FindInSphere(origin,radius) ) do
if ( v != _player ) then
return false;
end;
end;

return true;

end;[/lua]

yes i know this is a circle

It is seriously impossible to test if a person is inside a certain room when he presses a button?..

Because the creator of TTT himself said it is not possible to edit the ttt_traitor_button.

use the function i wrote to edit the button.

It is not doable with lua_run entity. You gotta edit ttt_traitor_button, or copy it and edit, this is very much possible.

Well he’s lying or dumb. Just edit the button.

[lua]function PointIsInBox(point, mins, maxs)
return point.x >= mins.x and point.x <= maxs.x and point.y >= mins.y and point.y <= maxs.y and point.z >= mins.z and point.z <= maxs.z
end[/lua]

If the entity wasn’t set up in such a crazy way ( it runs off console commands instead of actually using Entity:Use ) this would be trivial.

The simple solution is to not use the entity.

Do the following:

Create a func_button and set it up as desired.
Create a ttt_logic_role and set the Role keyvalue to be traitor.

On the logic’s OnPass output, hook all the inputs you want for traitors up.

In the button’s OnPress output, call the logic’s TestActivator input.

Same ( I think ) end result, no code required. You can even put a decoy button that does nothing there if you want it for appearances as well.

Edit: Snip. Ah, I didn’t realize it was the floating one. Change it in the TTT code so the distance they can press them / where they appear is less meaning they have to be closer / next to it for them to press it.

Okay, well you guys realize this is for a map, and I can only use the lua_run entity with one line of code. I’m getting some mixed reactions here, so is it actually possible to achieve what I’m trying to do, or do I need to give up?

I’m well aware of this, but I need to use a floating ttt_traitor_button, not a physical button

Gah if only TouchTest had a way to filter for the !activator instead of anything touching it…

i think ttt_rooftops_a2 has something like this in the collapsible building. just decompile that map and learn from it there.

It has physical button entity.

Rooftops uses the method that Kogitsune described, above. Don’t have to decompile anything the know that :v:

Anyways, I’m having a discussion with the creator of TTT about updating the ttt_traitor_button to allow mappers to set the usable distance from within Hammer. We’ll see what happens. I know it would make things loads easier for a lot of mappers.

I have done the (seemingly) impossible! And without the aid of Lua coding.

I created a trigger_multiple filtered for the name traitor_1 via the filter_activator_name entity. I moved the ttt_traitor_button’s output over to the trigger_multiple instead.
I then set up the ttt_traitor_button’s output like so:


OnPressed
!activator
AddOutput
targetname traitor_1
0.00

OnPressed
!activator
AddOutput
targetname none
0.25

What’s happening here is that the trigger_multiple is constantly looking for anything named “traitor_1” within it’s volume. The ttt_traitor_button changes the name of the player who activated it to “traitor_1” for a split second, effectively activating the output ONLY when the traitor is in the room. Otherwise nothing will happen. I also was able to display a message to the player if he isn’t in the room and tries to use the button. Perfect.
**

Edit:

**Furthermore, I talked to the creator of TTT and based on our discussion he has just released an update for TTT to let mappers set the useable distance for the ttt_traitor_button.