-- LUA Script - precede every function and global member wit h lowercase name of script + '_main' local helicopter_rocket_assigned = {} local helicopter_rocket_timer = {} local sin = math.sin local cos = math.cos function helicopter_rocket_init(e) CollisionOff(e) end function hrFire(e, quat) helicopter_rocket_assigned[e] = {fired = true, smoke = false, quat = quat} helicopter_rocket_timer[e] = 0 end local Q = require "scriptbank\\quatlib" local function Rotate3D (x, y, z, xrot, yrot, zrot) function RotatePoint2D (x, y, Ang) -- Ang in radians local Sa, Ca = sin(Ang), cos(Ang) return x*Ca - y*Sa, x*Sa + y*Ca end local NX, NY, NZ = x, y, z -- X NZ, NY = RotatePoint2D (NZ, NY, -xrot) -- Y NX, NZ = RotatePoint2D (NX, NZ, -yrot) -- Z NY, NX = RotatePoint2D (NY, NX, -zrot) return NX, NY, NZ end local function WillHitObject(sx,sy,sz,ex,ey,ez,ro) local obj = IntersectAll(sx, sy, sz, ex, ey, ez, ro) return obj and obj ~= 0 end function helicopter_rocket_main(e) local timer = helicopter_rocket_timer[e] if timer == nil then helicopter_rocket_timer[e] = 0 return end if g_Time > timer and HeliAddRocket ~= nil then if helicopter_rocket_assigned[e] == nil then if HeliAddRocket(e) then helicopter_rocket_assigned[e] = {fired = false} timer = math.huge end end -- only try to assign rocket once per second timer = g_Time + 1000 end local hr = helicopter_rocket_assigned[e] if hr == nil then return end if hr.fired then -- calculate new position local xA, yA, zA = Q.ToEuler(hr.quat) -- change the vector to match 'forward' for the model, i.e. pointing up is 0,0,1 left would be 1,0,0 etc local vX, vY, vZ = Rotate3D (0, 0, 1, xA, yA, zA) local Ent = g_Entity[e] local nX = Ent.x + vX * 50 local nY = Ent.y + vY * 50 local nZ = Ent.z + vZ * 50 -- check collision with terrain or object if nY < GetTerrainHeight(nX, nZ) or WillHitObject(Ent.x, Ent.y, Ent.z, nX, nY, nZ, Ent.obj) then SetEntityHealth(e, 0) hr.fired = false StopParticleEmitter(e) return end if not hr.smoke then StartParticleEmitter(e) end -- move rocket ResetPosition(e, nX, nY, nZ) end end