-- LUA Script - precede every function and global member wit h lowercase name of script + '_main' local fp_rocket_assigned = {} local fp_rocket_timer = {} local sin = math.sin local cos = math.cos function fp_rocket_ammo_init(e) CollisionOff(e) Hide(e) SetEntityHealth(e, 10000) end function FP_RocketFire(e, ax, ay, az) fp_rocket_assigned[e] = {fired = true, smoke = false, xA = ax, yA = ay, zA = az} fp_rocket_timer[e] = 0 end 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 function fp_rocket_ammo_main(e) local timer = fp_rocket_timer[e] if timer == nil then fp_rocket_timer[e] = 0 return end if g_Time > timer and FP_AddRocket ~= nil then if fp_rocket_assigned[e] == nil then if FP_AddRocket(e) then fp_rocket_assigned[e] = {fired = false} timer = math.huge end end fp_rocket_timer[e] = g_Time + 3000 end local hr = fp_rocket_assigned[e] if hr == nil then return end if hr.fired then -- 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, hr.xA, hr.yA, hr.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 an object if nY < GetTerrainHeight(nX, nZ) or IntersectAll(Ent.x, Ent.y, Ent.z, nX, nY, nZ, Ent.obj) ~= 0 then SetEntityHealth(e, 0) hr.fired = false StopParticleEmitter(e) else if not hr.smoke then StartParticleEmitter(e) end -- move rocket CollisionOff(e) SetPosition(e, nX, nY, nZ) CollisionOn(e) end end end