Hey,
I'm making a map, and I would like to use a chat command to open a door.
Can someone make a script like this?
with like <text you want to use> where I've to put my sentence, and <other things> where I need to edit things, like entity name (?), and things like that.
But there is 1 tricky part, I want it for my steamID only, is that possible?
And I want to add this in my map, with a lua_run, is this possible?
[editline]27th November 2010[/editline]
To make it a little better for you:
I've a door, with a secret room behind it.
I want to use a chat command, which is /rubenisawesome (Yey, I've a too big ego), to toggle a door, which entity name is: secret_room_door
I'm mapping in hammer, and I want to use a lua_run entity to get this working, since I want to just make my map free2download at garrysmod.org.
[b][url=wiki.garrysmod.com/?title=Gamemode.PlayerSay]Gamemode.PlayerSay [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
then you would just use stuff like self:Fire( stuff )
I know absolute NO lua.
That's why I requested it here.
But.. Is it possible to let a lua_run, activate another lua script, since the lua.run is limited (?), and then pack the .lua file in the .bsp?
You cant use "packrat" to put lua into maps , and to autorun if oyu ned , but garry has put a part on the wiki about includding lua into maps :)
Yes, but the hard part is, I can map, but I can absolutely do 0,000 lua.
If someone shows me a code, I'd say: Oh, d'oh.
But, if you ask me to make one...
Well you could first of all give me some keyvalues of the ent you want to open/close/whatever and i will see what i can do
entity name= secret_room_door
entity action= toggle
chat-command= /rubenisawesome
Hurray for too big ego.
[editline]27th November 2010[/editline]
The ONLY steamID able to do this command: STEAM_0:1:20219592
i mean like values i can change to the door for it to open/close , i am talking mapping here
I don't get what you want? It's a door already, so the settings are set. I thought you only need to activate it, like toggle or something?
well is there a setting like IsOpen or whatever
A keyvalue i can change via lua to open/close
You mean at the outputs tab in the Hammer editor?
If you make a button it will be:
Action: OnPressed
Entity: secret_room_door
Action of the entity: Toggle
That's how you configure it in hammer.
Is that what you mean?
No , i mean like a keyvalue on he door i can change on the go in lua to open/close . isnt there a keyvalue like that?
Try getting on the map. Get in front of the door, Aiming at it and run this
lua_run_cl ent = util.QuickTrace( ply:GetShootPos(), ply:GetAimVector() * 10000, { ply } ) PrintTable(ent:GetTable())
] lua_run_cl ent = util.QuickTrace( ply:GetShootPos(), ply:GetAimVector() * 10000, { ply } ) PrintTable(ent:GetTable())
[LuaCmd:1] attempt to index global 'ply' (a nil value)
My fault. Replace ply: with LocalPlayer():
] lua_run_cl ent = util.QuickTrace( LocalPlayer():GetShootPos(), LocalPlayer():GetAimVector() * 10000, { ply } ) PrintTable(ent:GetTable())[
[LuaCmd:1] unexpected symbol near '<eof>'
The fuck?
400th post :O
Eh. Remove the [ in the end of it.
] lua_run_cl ent = util.QuickTrace( LocalPlayer():GetShootPos(), LocalPlayer():GetAimVector() * 10000, { ply } ) PrintTable(ent:GetTable())
[LuaCmd:1] attempt to call method 'GetTable' (a nil value)
I copied it wrong, that's why the [ was there.
I don't like the console ;x
But still not working.
Ehh. Why is GetTable() nil.. Try removing replacing the PrintTable(ent:GetTable()) with
print(ent)
] lua_run_cl ent = util.QuickTrace( LocalPlayer():GetShootPos(), LocalPlayer():GetAimVector() * 10000, { ply } ) print(ent)
table: 04295E18
That's what I get now.
[lua]
function SuperCmd( ply, text, team )
if (string.sub(text, 1, 5) == "/open") then--if the first 4 letters are /all continue
if ply:SteamID() == "STEAM_0:1:20219592" then
for _, ent in pairs(ents.GetAll()) do
if v:GetClass() == "func_door" then
if v:EntIndex() == 26 then
v:Fire("unlock", "", 0)
v:Fire("open", "", 0)
return "";
end
end
end
end
return;
end
end
hook.Add( "PlayerSay", "SuperCmd", SuperCmd );
[/lua]
[editline]28th November 2010[/editline]
Untested. It should work, I think.
Sorry for bothering you, but, can you just put this in a lua_run? Or do you need to use external data?
[QUOTE=Freze;26357386][lua]
function SuperCmd( ply, text, team )
if (string.sub(text, 1, 5) == "/open") then--if the first 4 letters are /all continue
if ply:SteamID() == "STEAM_0:1:20219592" then
for _, ent in pairs(ents.GetAll()) do
if v:GetClass() == "func_door" then
if v:EntIndex() == 26 then
v:Fire("unlock", "", 0)
v:Fire("open", "", 0)
return "";
end
end
end
end
return;
end
end
hook.Add( "PlayerSay", "SuperCmd", SuperCmd );
[/lua]
[editline]28th November 2010[/editline]
Untested. It should work, I think.[/QUOTE]
Dont think it will work , because the entindex isnt always the same (?).
I reloaded the map, but, it's the same entindex?
It still says 26.
But, the code is in a lua run, I had to put it all on 1 line, so remove the hard returns. Is that a problem?
But when I type /open nothing happens.
[QUOTE=dingusnin;26357629]Dont think it will work , because the entindex isnt always the same (?).[/QUOTE]
I've got no idea if it is ;) It's just a guess it's a map thing, And they get loaded in a fixed way. Like THIS ent first. etc etc.. but no. You're right, I've got no idea.
[editline]28th November 2010[/editline]
[QUOTE=Cyberuben;26357783]I reloaded the map, but, it's the same entindex?
It still says 26.
But, the code is in a lua run, I had to put it all on 1 line, so remove the hard returns. Is that a problem?
But when I type /open nothing happens.[/QUOTE]
Don't put it in lua_run save it to the gamemode. serverside.
I don't want it for a gamemode. That's what I told in my first post.
[lua]hook.Add("PlayerSay","OpenDoor",function(pl,text)
if text == "/open" and pl:SteamID() == "STEAM_0:1:20219592" then
local e = Entity(26);
if not IsValid(e) or e:GetName() != "secret_room_door" then
for _,ent in pairs(ents.GetAll()) do if ent:GetName() == "secret_room_door" then e = ent; break; end end
end
if not IsValid(e) then pl:ChatPrint("Door was not found."); return ""; end
e:Fire("unlock","",0);
e:Fire("open","",0);
return "";
end
end[/lua]
That solves the dilemma of using EntIndex or GetName. Place the file in a .lua file in your lua/autorun/server (don't put it in your addons folder, use root garrysmod).
Now the last question:
Is it possible to execute an external .lua file with a lua_run?
[editline]28th November 2010[/editline]
Like you have include("/?????.php") in PHP.
Sorry, you need to Log In to post a reply to this thread.