• Sending an input to an entity in a map
    11 replies, posted
I'm struggling to figure out how to send an input to a specific entity in my map via lua script. I recently [URL="http://facepunch.com/showthread.php?t=1321120"]figured out the usage[/URL] of the lua_run entity. [U]What I'm trying to accomplish:[/U] I have a logic_relay in my map named "relay_1". I also have a button that triggers a lua_run entity to run it's one line of code. I want that code to check the ACTIVATOR's steam ID and if a match is found, I want it to "Trigger" the logic_relay so that the logic_relay will carry out its task. Here's what I have working so far: [CODE]if ACTIVATOR:SteamID() == 'STEAM_0:1:12345678' then print('Hello World') end[/CODE] This simply prints 'Hello World' to the console if the ACTIVATOR's steam ID checks out. Instead of printing 'Hello World' to the console, I want it to trigger the logic_relay (named "relay_1") in the map. Could someone please help with how to do this? I've been looking into using [URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index43b2.html"]Entity.Fire[/URL] but have not had success. I would greatly appreciate the help.
[lua] for _, x in pairs(ents.FindByClass("logic_relay")) do if x:GetName() == "relay_1" then x:Fire( your parameters here ) end end [/lua] Try this.
[QUOTE=arcaneex;42753556] for _, x in pairs(ents.FindByClass("logic_relay")) do if x:GetName() == "relay_1" then x:Fire( your parameters here ) endend Try this.[/QUOTE] I'll give it a shot. It has to be one line of code though for the lua_run entity. Is combining it to one line as simple as: [CODE]for _, x in pairs(ents.FindByClass("logic_relay")) do if x:GetName() == "relay_1" then x:Fire( your parameters here ) end end [/CODE]
It can be a single line, it doesn't matter.
I think I got it working! Thank you so much! Could someone please check this over just to make sure? [CODE]if ACTIVATOR:SteamID() == 'STEAM_0:1:12345678' then for _, x in pairs(ents.FindByClass('logic_relay')) do if x:GetName() == 'relay_1' then x:Fire('Trigger') end end end[/CODE] It fired the logic_relay's output only when it matched my Steam ID, so I hope it is coded correctly.
You might want to change it to: [lua] if ACTIVATOR:IsPlayer() and ACTIVATOR:SteamID() == 'STEAM_0:1:12345678' then for _, x in pairs(ents.FindByClass('logic_relay')) do if x:GetName() == 'relay_1' then x:Fire('Trigger') end end end[/lua] Just to avoid future errors, if somehow the activator will be a entity rather than a player it will error saying invalid method, hence the IsPlayer().
Awesome, thank you! I've [URL="http://facepunch.com/showthread.php?t=988918"]read somewhere[/URL] that restricting a button to someone's steam ID can still be bypassed somehow? Is this true, or at least anything to worry about if it is? I only have one more question. Say I wanted to have a button linked to a lua_run entity that would kill a player with a specific Steam ID if they are present and alive in the server. Obviously I would never actually implement this unless it's in a test map, because that's just a cruel thing to do. :v: But I want to know how, and it's helpful now that I am learning how lua works. Is this possible?
[lua] if ACTIVATOR:SteamID() == 'STEAM_0:1:12345678' then ACTIVATOR:Kill() end [/lua] To kill the one who presses [lua] if ACTIVATOR:SteamID() == 'STEAM_0:1:12345678' then for _, x in pairs(player.GetAll()) do if x:SteamID() == 'STEAM_0:1:87654321' then x:Kill() end end end [/lua] To kill someone with the steamid STEAM_0:1:87654321
[QUOTE=Matt2468rv;42755303]Awesome, thank you! I've [URL="http://facepunch.com/showthread.php?t=988918"]read somewhere[/URL] that restricting a button to someone's steam ID can still be bypassed somehow? Is this true, or at least anything to worry about if it is?[/QUOTE] This depends purely on if the person has control over the server that is running the map, if they do then yes it can be bypassed if not then no it can't
[QUOTE=arcaneex;42755692] if ACTIVATOR:SteamID() == 'STEAM_0:1:12345678' then ACTIVATOR:Kill() end To kill the one who presses if ACTIVATOR:SteamID() == 'STEAM_0:1:12345678' then for _, x in pairs(player.GetAll()) do if x:SteamID() == 'STEAM_0:1:87654321' then x:Kill() end end end To kill someone with the steamid STEAM_0:1:87654321[/QUOTE] Awesome, I'll give this a shot! [QUOTE=King Penisless;42755890]This depends purely on if the person has control over the server that is running the map, if they do then yes it can be bypassed if not then no it can't[/QUOTE] So for the average TTT server, it shouldn't be an issue I would think.
If the user has access to console then obviously he would be able to bypass it, unsure (probably not) about bypassing it without access to the server console.
[QUOTE=arcaneex;42756124]If the user has access to console then obviously he would be able to bypass it, unsure (probably not) about bypassing it without access to the server console.[/QUOTE] Right so basically only if they have the rcon password? The killing script worked beautifully by the way, thanks again :) This gives me a lot of insight into how things are handled in lua scripting.
Sorry, you need to Log In to post a reply to this thread.