-- Spear trap -- Script assumes that origin of model is centred between spear points local U = require "scriptbank\\utillib" local rad = math.rad local width = 100 -- width of gap between spear points when open local distBetweenChecks = width / 5 local spearAnimating = {} local checkTimer = {} local checkTime = 100 -- milliseconds between checks function spear_trap_init(e) end function spear_trap_main(e) if checkTimer[ e ] == nil then checkTimer[ e ] = g_Time + checkTime end -- handle volume every frame if spearAnimating[ e ] then SetSound( e, 0 ) SetSoundVolume( 100 - ( GetPlayerDistance (e) / 100 ) ) end -- do the rest only every so often if g_Time < checkTimer[ e ] then return end checkTimer[ e ] = g_Time + checkTime local Ent = g_Entity[e] local cx, cy, cz = Ent.x, Ent.y, Ent.z -- first check if player is close by local px, py, pz = g_PlayerPosX, g_PlayerPosY-20, g_PlayerPosZ if not U.CloserThan( cx, cy, cz, px, py, pz, 300 ) then if spearAnimating[ e ] then SetAnimationFrame( e, 0 ) StopAnimation( e ) StopSound( e, 0 ) spearAnimating[ e ] = false end return end -- now check if player is close to axis of spear travel, start with centre -- as that is simplest if U.CloserThan( cx, cy, cz, px, py, pz, 30 ) then -- only take off a little health each time so he dies slowly(ish) HurtPlayer( e, 10) return end -- now check the other 4 points one by one -- get angle of trap local exa, eya, eza = rad( Ent.anglex ), rad( Ent.angley ), rad( Ent.anglez ) -- get vector representing 'sideways' for trap local vx, vy, vz = U.Rotate3D ( distBetweenChecks, 0, 0, exa, eya, eza ) if U.CloserThan( cx + vx, cy + vy, cz + vz, px, py, pz, 30 ) then HurtPlayer(e, 10) return end if U.CloserThan( cx - vx, cy - vy, cz - vz, px, py, pz, 30 ) then HurtPlayer(e, 10) return end if U.CloserThan( cx + vx*2, cy + vy*2, cz + vz*2, px, py, pz, 30 ) then HurtPlayer(e, 10) return end if U.CloserThan( cx - vx*2, cy - vy*2, cz - vz*2, px, py, pz, 30 ) then HurtPlayer(e, 10) return end -- now deal with animation bit if not spearAnimating[ e ] then SetAnimation( e ) LoopAnimation( e ) LoopSound( e, 0 ) ActivateIfUsed( e ) spearAnimating[ e ] = false end end