Code:
-- Lua based Door controle with Chat Commands v 1.1
-- Script by aVoN - www.avon.fneuweiler.de
-- Feel free to use any part of this script for your own usage. You can modify and/or distribute it as long as you give credits to me.
-- Usable doors - Working with chatcommands. Protected by PropProtector! (Just the owner can open/close them!)
-- This needs additionally to PropProtector the GMX library! I'm using GMX 1.31, but i think, it will even work with versions before!
-- Example function found on FP in a Lua help thread. Made me to think about "how to do" this - written everything by my own
-- Usage : Look at a door an say "!door <doorname comes here>" without the < and >
-- Then, look any Prop, and say "!button <dooname>". You can bind multi doors to one button. Just lookt at the button/pro prop again and bind it with saying "!button <dooname 2>" or multibind
-- them with "!door <door1>;<door2>;<door3>"
--Doors
function s_eventPlayerSay( userid, strText, bTeam )
-- Ignore the console
if(userid ~= 0) then
_TraceLine(_PlayerGetShootPos(userid),_PlayerGetShootAng(userid),4096,userid)
local username,uname_pos = string.find(string.lower(strText), string.lower(_PlayerInfo(userid,"name")..": "), 1, true);
strText = string.sub(strText, uname_pos + 1)
local splitted = gmx.explode(strText," ");
if (splitted[1] == "!open") then
if(splitted[2] == nil) then
if _TraceHitNonWorld() then
if(prop_protection (userid,_TraceGetEnt())) then
_EntFire(_TraceGetEnt(),"setanimation","open",0)
end
end
else
if(prop_protection (userid,_EntGetByName(splitted[2]))) then
_EntFire(_EntGetByName("door_"..splitted[2]),"setanimation","open",0)
end
end
end
if (splitted[1] == "!close") then
if(splitted[2] == nil) then
if _TraceHitNonWorld() then
if(prop_protection (userid,_TraceGetEnt())) then
_EntFire(_TraceGetEnt(),"setanimation","close",0)
end
end
else
if(prop_protection (userid,_EntGetByName(splitted[2]))) then
_EntFire(_EntGetByName("door_"..splitted[2]),"setanimation","close",0)
end
end
end
if(splitted[1] == "!door" and splitted[2] ~= nil) then
if(prop_protection (userid,_TraceGetEnt())) then
make_door(_TraceGetEnt(),splitted[2])
end
end
if(splitted[1] == "!button" and splitted[2] ~= nil) then
if(prop_protection (userid,_TraceGetEnt())) then
make_button(userid,_TraceGetEnt(),splitted[2])
end
end
end
end
function make_button(userid,entity,name)
local ent_name = "";
-- Check first, if the person is the owner of the door. Otherwise, dont allow him, to make it a button for it!
if(_EntGetByName(door) ~= "" and _EntGetByName(door) ~= nil and _EntGetByName(door) ~= 0) then
if(prop_protection (userid,_EntGetByName(door)) == false) then
return;
end
end
local door_table = gmx.explode(name,";")-- Multi doors!
for k,door in door_table do
ent_name = _EntGetName(entity);
_EntFire(entity, "addoutput", "spawnflags 256" , 0);
_EntFire(entity, "addoutput", "onplayeruse door_"..door..",setanimation,open" , 0);
_EntFire(entity, "addoutput", "onplayeruse door_"..door..",setanimation,close,3" , 0);
if(string.find(tostring(ent_name),"button") == nil) then
_EntSetName(entity,"button_"..door);
else
-- Multi Button
_EntSetName(entity,ent_name..";"..door);
end
end
end
function make_door(entity,name)
local make_door = gmx.explode(name,";");
-- Dont add a ; to a doors name!
_EntSetName(entity,"door_"..make_door[1]);
end
HookEvent("eventPlayerSay", s_eventPlayerSay)