-- LUA Script - precede every function and global member with lowercase name of script + '_main' -- forcefield_blue script has been adapted from the default gg door script -- modified by Reliquia -- Script Purpose: -- Player must have key if Force-Field is locked - specified by 'USE KEY' field -- Allow player to Raise\Lower Force-Field -- Force-Field model resources: -- Two animations stored in the model: 0=opening 1=closing -- audio slot 0 - Lower Force-Field -- audio slot 1 - Raise Force-Field -- audio slot 2 - Repel player -- scriptbank\reliquia\forcefiled_blue - This script to facilitate animations: -- variables used by this script local forcefield_pressed = 0 -- state to ensure user must release E key before can open/close again local zapPlayer = 0 -- state used to zap the player local Utils = require "scriptbank\\utillib" -- so we can determine if player is looking at Force-Field or not local Q = require "scriptbank\\quatlib" local hasDecal = 1 --set to 1 if you want to display a decal on screen when forcefield is hit local decalE = {} local decalShowTime = 1000 --time to display the decal for local showingDecal = {} local _name = {} function forcefield_blue_init_name(e,name) Include( "utillib.lua" ) _name[e] = name decalE[e] = nil showingDecal[e] = 0 end function forcefield_blue_main(e) if hasDecal == 1 then if decalE[e] == nil then for a,b in pairs (isDecal) do if b == _name[e].." decal" then decalE[e] = a break end end end if decalE[e] == nil then PromptLocal(e,"error - no decal found") return end end local PlayerDist = GetPlayerDistance(e) if (PlayerDist < 100 ) and g_PlayerHealth > 0 then -- If Force-Field not activated check if key required if g_Entity[e]['activated'] == 0 then if g_Entity[e]['haskey'] == -1 then -- key not required activate the Force-Field SetActivated(e,1) else -- key is required - check if player has one if g_Entity[e]['haskey'] == 1 then -- player has key - prompt to use it Prompt("(E) Enable Force-Field operation") if g_KeyPressE == 1 then -- player used key - activate Force-Field SetActivated(e,1) end else -- player has no key - promt to find one Prompt("Access denied - find key to enable the Force-Field") end end else -- Force-Field is active if g_Entity[e]['activated'] == 1 then -- Force-Field is closed -- display prompt if Force-Field is not currently animating -- not animating, prompt player to open if g_Entity[e]['animating'] == 0 then Prompt("(E) Lower Force Field") end -- player pressed e, open Force-Field if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and forcefield_pressed == 0 then SetAnimation(0) -- set opening animation PlayAnimation(e) -- play the animation g_Entity[e]['animating'] = 1 -- set flag so system knows it is animatng SetActivated(e,2) -- set activated state to 2 so system knows it is in open state ActivateIfUsed(e) PlaySound(e,0) -- play sound in slot 0 forcefield_pressed = 1 -- state to ensure user must release E key before can open\close again --CollisionOff(e) -- handled by end else if g_Entity[e]['activated'] == 2 then -- Force-Field is open -- display prompt if Force-Field is not currently animating -- not animating, prompt player to close if g_Entity[e]['animating'] == 0 then Prompt("(E) Raise Force Field") end -- player pressed e, close the Force-Field if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and forcefield_pressed == 0 then SetAnimation(1) -- set closing animation PlayAnimation(e) -- play the animation g_Entity[e]['animating'] = 1 -- set flag so system knows it is animatng SetActivated(e,1) -- set activated state to 2 so system knows it is in closed state PlaySound(e,1) -- play sound in slot 1 forcefield_pressed = 1 -- state to ensure user must release E key before can open\close again --CollisionOff(e) -- turn off collisions end end end end end if showingDecal[e] == 1 then Show(decalE[e]) if GetTimer(e) > decalShowTime or g_Entity[e]['activated'] == 2 then showingDecal[e] = 0 Hide(decalE[e]) end end if zapPlayer == 1 then zapPlayer = 0 end -- check if player has released the E key -- if so reset forcefield_pressed var so user can open/close again if g_KeyPressE == 0 then forcefield_pressed = 0 end -- Check Force-Field is OPEN -- check animation has finished if g_Entity[e]['activated'] == 2 and g_Entity[e]['animating'] == 0 then CollisionOff(e) -- turn collision off end -- Check Force-Field CLOSED -- Check if animation has finished if g_Entity[e]['activated'] == 1 and g_Entity[e]['animating'] == 0 then CollisionOn(e) -- turn collision on end if (g_Entity[e]['activated'] == 1 and g_PlayerHealth > 0) or g_Entity[e]['haskey'] == 0 then PlayerDist = GetPlayerDistance(e) local FA = 0 -- to hold Force-Field angle local PLAFF = 0 -- player looking at Force-Field -- make use of the Utillib by AmenMoses if Utils.PlayerLookingAt( e, 80 ) then -- PromptLocal ( e, "Don't touch the Force-Field!" ) PLAFF = 1 end if (PlayerDist < 80 ) and zapPlayer == 0 then -- if player too close push him back --\ Call DetermineForceAngle function local x1,y1,z1 = g_PlayerPosX,g_PlayerPosY,g_PlayerPosZ FA = GetAngleToPoint(e,x1,z1) if hasDecal == 1 then local x2,y2,z2,ax2,ay2,az2 = GetEntityPosAng(e) x1,z1 = (x1-x2)*0.35,(z1-z2)*0.35 SetRotation(decalE[e],ax2,ay2,az2) SetPosition(decalE[e],x1+x2,y1,z1+z2) showingDecal[e] = 1 end ForcePlayer(FA, 3) StartTimer(e) --\ zapPlayer = 1 PlaySound(e,2) -- play sound in slot 2 end end --PromptLocal (e, "Player Y =".. g_PlayerAngY ) --PromptLocal ( e, "activated=" .. g_Entity[e]['activated'] .. "PlayerDist=" .. PlayerDist ) --PromptLocal ( e, "activated=" .. g_Entity[e]['activated'] .. "PlayerDist=" .. PlayerDist .. " plrvisible=" .. g_Entity[e]['plrvisible'] .. " haskey=" .. g_Entity[e]['haskey'] ) --PromptLocal ( e, "is activated=" .. g_Entity[e]['activated'] .. " is anmimating = " .. g_Entity[e]['animating'] ) end function GetDistance(a,b) local x1,y1,z1 = GetEntityPosAng(a) local x2,y2,z2 = GetEntityPosAng(b) local dx, dy, dz = x1 - x2, y1 - y2, z1 - z2 return ( dx*dx+dy*dy+dz*dz ) end function GetAngleToPoint(e,x,z) if g_Entity[e] ~= nil and x > 0 and z > 0 then local destx = x - g_Entity[e]['x'] local destz = z - g_Entity[e]['z'] local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle < 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end --SetRotation(e,0,angle,0) return angle end end