I don\'t know if anyone has created a script to open a door automatically so I made one.
No key needed - when player gets close enough - the door will open and close when player
moves away from the door.
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Created by: Terry Ingalls aka: Tingalls 7/26/2014
-- Opens door automatically and closes it when player is away from door
function doorauto_init(e)
end
function doorauto_main(e)
PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));
if PlayerDist < 150 then
if g_Entity[e]['activated'] == 0 then
-- door is closed
if g_Entity[e]['animating'] == 0 then
SetAnimation(0);
PlayAnimation(e);
g_Entity[e]['animating'] = 1;
g_Entity[e]['activated'] = 1;
PlaySound(e,0);
StartTimer(e);
end
else
if g_Entity[e]['activated'] == 1 then
-- door collision off after 1 second
if GetTimer(e)>1000 then
CollisionOff(e);
end
end
end
end
-- door is open
if PlayerDist > 150 then
if g_Entity[e]['activated'] == 1 then
if g_Entity[e]['animating'] == 0 then
SetAnimation(1);
PlayAnimation(e);
PlaySound(e,1);
g_Entity[e]['animating'] = 1;
g_Entity[e]['activated'] = 0;
CollisionOn(e);
end
end
end
end
Copy the code to a text editor such as Notepad and then save the file as
doorauto.lua and place it in your
scriptbank folder.
In your door .fpe file, change the aimain = door.lua to aimain = doorauto.lua
enjoy - let me know if you have any problems
Experiencing a cool Game --> Tingalls
Win 7 Home Premium, 64bit(srvPack 1),AMD FX 4100 Quad-core 3.8Ghz @ 8Gb Ram - NVIDIA GeForce GT 610 @ 1GB Ram