-- LUA Script - precede every function and global member with lowercase name of script + '_main' local U = require "scriptbank\\utillib" local switcher_list = {} function switcher_init_name( e, name ) Include("utillib.lua") local object, id = string.match( name, "(%w+)_(%w+)" ) switcher_list[ e ] = { objName = object, objId = id, state = 'init' } end local function HideObject( name, id ) for k, v in pairs( switcher_list ) do if v.objName == name and v.objId == id then Hide( k ) CollisionOff( k ) end end end local function ShowObject( name, id ) for k, v in pairs( switcher_list ) do if v.objName == name and v.objId == id then Show( k ) CollisionOn( k ) end end end function switcher_main( e ) local sw = switcher_list[ e ] if sw == nil then return end PromptLocal( e, sw.state .. "," .. sw.objName .. "," .. sw.objId ) if sw.state == 'idle' then return elseif sw.state == 'init' then if sw.objId == 'trigger' then sw.state = 'off' HideObject( sw.objName, 'alt' ) ShowObject( sw.objName, 'main' ) else sw.state = 'idle' end elseif sw.state == 'off' then if U.PlayerCloserThan( e, 100 ) then sw.state = 'trigOn' HideObject( sw.objName, 'main' ) ShowObject( sw.objName, 'alt' ) end elseif sw.state == 'on' then if U.PlayerCloserThan( e, 100 ) then sw.state = 'trigOff' HideObject( sw.objName, 'alt' ) ShowObject( sw.objName, 'main' ) end elseif not U.PlayerCloserThan( e, 100 ) then if sw.state == 'trigOn' then sw.state = 'on' elseif sw.state == 'trigOff' then sw.state = 'off' end end end