How would i go about finding out when a player is inside of a trigger?
I couldn't think of how to do it in hammer or lua.
That is, without doing something like "onStartTouch !activator addoutput 'Targetname ihitthetrigger'," then in lua do
[lua]
function CheckIfTheyHitTheTrigger(ent, k, v)
if(ent:IsPlayer() and string.lower(k) == "targetname" and string.lower(v) == "ihitthetrigger") then
//Do stuff
end
end
hook.Add("EntityKeyValue", "DoTheCheck", CheckIfTheyHitTheTrigger)
[/lua]
Bump.
[QUOTE=PortalGod;24186399]How would i go about finding out when a player is inside of a trigger?
I couldn't think of how to do it in hammer or lua.
That is, without doing something like "onStartTouch !activator addoutput 'Targetname ihitthetrigger'," then in lua do
"code"
[/QUOTE]
If it doesn't matter whether or not it's clientside then I think you can use this [b][url=wiki.garrysmod.com/?title=ENT.PassesTriggerFilters]ENT.PassesTriggerFilters [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] serverside hook to see if a player enters a trigger. Or if it has to be clientside I think you could use [b][url=http://wiki.garrysmod.com/?title=Ents.FindInBox]Ents.FindInBox [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] using opposite corner vectors of the trigger to do it, but I've never tried. I'm not sure if there's a simpler way or not. Then I think you would just use
[lua]
for k,v in pairs(ents.FindInBox(VectorMin,VectorMax)) do
if v:IsPlayer() then
//stuff
end
end
[/lua]
I've never tried either method though so it may not work.
Would it be possible to get the mins and maxs from the trigger?
That way i could do
[lua]
ents.FindInBox(Trigger:GetPos() - Trigger:KeyValue("mins"), Trigger:GetPos() + Trigger:KeyValue("maxs")
[/lua]
or something of the sort.
Bumping again for an answer
[QUOTE=PortalGod;24202564]Would it be possible to get the mins and maxs from the trigger?
That way i could do
[lua]
ents.FindInBox(Trigger:GetPos() - Trigger:KeyValue("mins"), Trigger:GetPos() + Trigger:KeyValue("maxs")
[/lua]
or something of the sort.[/QUOTE]
I'm not sure, I've never really used key values before. You could try searching for functions through here: [b][url]http://wiki.garrysmod.com/?title=Entity[/url][/b] and see if any of them can help you out with finding the min and max vectors. You could also just edit the map and put an info_target entity at opposite ends of the trigger and give them names. Then look them up with lua ingame and get their position.
It looks like [b][url=http://wiki.garrysmod.com/?title=Entity.OBBMaxs]Entity.OBBMaxs [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b], [b][url=http://wiki.garrysmod.com/?title=Entity.OBBMins]Entity.OBBMins [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b], and [b][url=http://wiki.garrysmod.com/?title=Entity.OBBCenter]Entity.OBBCenter [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] could work. Thanks.
No problem.
Yay, i got it.
Here's what i used:
[lua]
function GM:InitPostEntity()
Triggers = {}
for _,v in pairs(ents.GetAll()) do
if(string.find(v:GetClass(), "trigger")) then
table.insert(Triggers, v)
end
end
TriggerResults = {}
hook.Add("Think", "FindInTriggers", FindInTriggers)
end
function FindInTriggers()
for k,v in pairs(Triggers) do
Center = v:LocalToWorld(v:OBBCenter())
InBox = ents.FindInBox(Center + v:OBBMins(), Center + v:OBBMaxs())
table.remove(InBox, table.Count(InBox))
TriggerResults[k] = InBox
end
end
[/lua]
Thanks again.
Sorry, you need to Log In to post a reply to this thread.