Hi everyone! So I was wondering, how would I go about making a lua script that can control inputs and outputs of an entity in a map. For example, if I had a Light entity, could I make a lua script that fires it's "Toggle" input? If so I'd love to know the syntax to do such a thing. Thanks for the help in advance!
Edit: Sorry if this seems like a mapping question, I posted this here because it's mainly about scripting, just working with map elements, and I felt like there would be more people here who could help.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/Fire]Entity:Fire[/url]
??????
I don't really know what you mean by map entity
[QUOTE=Kevlon;49369590][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/Fire]Entity:Fire[/url]
??????
I don't really know what you mean by map entity[/QUOTE]
Just the type of entity that you put in a map with hammer, like a point light. Thanks though, I think that MAY be exactly what I was looking for!
[editline]22nd December 2015[/editline]
Well, there is a little bit of a problem with that though, in the example code it gives:
[CODE]local tr = LocalPlayer():GetEyeTrace()
local ent = tr.Entity
if IsValid( ent ) then
ent:Fire( "lock" )
end[/CODE]
That defines "ent" as whatever entity that the player is looking at, but how would I target a specific entity that's compiled into a map, such as a light, or maybe a door, anything really?
sent:GetClass()
[QUOTE=NiandraLades;49369774]sent:GetClass()[/QUOTE]
Alright, cool. So how would I use that to target my light entity? This is the main goal:
[CODE]local ent = --<My light entity in map named "togglelight">
if IsValid( ent ) then
ent:Fire( "Toggle" ) -- I want the script to fire the "Toggle" input on the light.
end[/CODE]
[QUOTE=DonnieLewis;49369832]:snip:[/QUOTE]
I'm not exactly a mapper but from my knowledge you've "named" it "togglelight"? So that should mean you could do this:
[CODE]for _,v in pairs(ents.GetAll()) do
if (v:GetName() == "togglelight") then
v:Fire("Toggle")
break
end
end[/CODE]
[QUOTE=BillyOnWiiU;49370070]I'm not exactly a mapper but from my knowledge you've "named" it "togglelight"? So that should mean you could do this:
[CODE]for _,v in pairs(ents.GetAll()) do
if (v:GetName() == "togglelight") then
v:Fire("Toggle")
break
end
end[/CODE][/QUOTE]
Thanks so much! I will try that!
[editline]22nd December 2015[/editline]
[QUOTE=BillyOnWiiU;49370070]I'm not exactly a mapper but from my knowledge you've "named" it "togglelight"? So that should mean you could do this:
[CODE]for _,v in pairs(ents.GetAll()) do
if (v:GetName() == "togglelight") then
v:Fire("Toggle")
break
end
end[/CODE][/QUOTE]
OMG Thank you so much! It totally worked!!!
Sorry, you need to Log In to post a reply to this thread.