I am having trouble with my helicopter after the last update (3.10.2017) .I am using Avram's helicopter code and library which would let it take off and fly around . All it want's to do is either slide around the ground or if it does take off it spins and does other crazy things . This code is somewhere here on the forum . This has nothing to do with the helicopter model .
I have put all the pointers to Avram's library in the GameLoopInit each time there is an update to Global in the script bank .
package.path = "scriptbank/?.lua;" --
aConfig = aConfig or { path = "Avram/" } --
require (aConfig.path .. "bootstrap")
_______________________________________________________
-- script by Avram, adapted for helicopter
-- save as helicopter.lua
-- the entity (helicopter) must be set as this: always active = on, physics = off
planes = planes or {}
SndPlaying = SndPlaying or {}
function helicopter_main(e)
planes[e] = planes[e] or {} --initialize plane data
planes[e]['speed'] = planes[e]['speed'] or 1600 + math.random(100,500) -- set plane speed (1600-2000)
planes[e]['turnspeed'] = planes[e]['turnspeed'] or 700 -- set turning speed
planes[e]['fallspeed'] = planes[e]['fallspeed'] or 1000 -- set falling speed
planes[e]['takeoffspeed'] = planes[e]['takeoffspeed'] or 700 -- set takeoff speed
local this = aEntity:new(e, "mustang") -- initialize entity obj
local state = this:attr("state") or "init" -- get current state [defaults to "init"]
local timer = aTimer:new(e) -- initialize timer
local dist = aPlayer:distance(this) -- get distance to player
this:watch_death() -- watch entity for it's death so we can respond to it
-- taking off
if state=="takeoff" and dist <= 4000 then -- GetPlayerDistance(e) >50
timer:start() -- start timer
GravityOff(e) -- turn off gravity
if timer:between(0,3) then
MoveUp(e, planes[e]['takeoffspeed'] - (planes[e]['takeoffspeed'] * 0.7) ) -- start slower (3 secs)
elseif timer:between(3,6) then
MoveUp(e, planes[e]['takeoffspeed']) -- go at takeoff speed (another 3 secs)
elseif timer:greater(6) then
if (g_Entity[e]['y'] <= g_PlayerPosY+500) then -- pull nose up and increase height (takeoff) while below player
SendMessageF("setrotationx",e,-5);
SendMessageF("setpositiony",e,g_Entity[e]['y']+5)
else -- push nose down and set state to fly when above player, also stop the timer
SendMessageF("setrotationx",e,0);
state = "fly"
timer:stop(
end
MoveForward(e, planes[e]['takeoffspeed'] + (planes[e]['takeoffspeed'] * 0.7)) -- move at increased speed while taking off
end
end
-- end -- added
-- turning
if state=="turn" then
MoveForward(e, planes[e]['turnspeed']) -- move at turning speed
timer:start() -- start timer
if timer:between(0,6) then -- rotate towards player for 6 seconds
RotateToPlayerSlowly(e, 2)
else -- after 6 seconds do this:
RotateToPlayerSlowly(e, 100) -- rotate to player
timer:stop() -- stop timer
state = "fly" -- set the plane into flying mode
end
end
-- falling down
if state=="fall" then
MoveForward(e, planes[e]['fallspeed']) -- move at falling speed
RotateX(e, 3) -- rotate a bit
RotateZ(e, 3)
RotateY(e, 3)
RotateX(e, 5) -- rotate a bit again
RotateZ(e, 5)
RotateY(e, 0)
RotateX(e, 7) -- rotate a bit again
RotateZ(e, 7)
RotateY(e, 0)
SendMessageF("setpositiony",e,g_Entity[e]['y']-1); -- move down
timer:start() -- start timer
-- 3 --
if timer:greater(6) or g_Entity[e]['y']<=650 then -- after 3 seconds of falling down or if hit the ground
state = "down" -- change state to down
timer:stop() -- stop the timer
StopParticleEmitter(e) -- stop smoke
SetEntityHealth(e, 0) -- destory (explode) the plane
end
end
-- flying straight
if state=="fly" then
MoveForward(e, planes[e]['speed']) -- move at defined speed
if (math.random(1, 10) == 2) then -- in 10% cases rotate plane a bit and change it's height
RotateX(e, math.random(-10, 10))
RotateZ(e, math.random(-10, 10))
SendMessageF("setpositiony",e,g_Entity[e]['y']+math.random(-10, 10));
end
end
-- initialization
if state=="init" -- and
-- GetPlayerDistance(e) < 1000 -- added this but didn't work
then
GravityOff(e) -- turn gravity off
state = "takeoff" -- take off
end
-- if too far from the player, set to turning state
if state=="fly" and dist > 9000 then
state = "turn"
end
if state=="fly" and dist < 9000 then
LoopSound(e, 0)
SetSoundVolume(80)
end
-- if flying and is shot to death (while keeping entity alive), set falling state and start smoke
if state=="fly" and this:is_dead(true) then
state = "fall"
StartParticleEmitter(e)
StopSound(e, 0)
end
this:attr('state', state) -- store the (modified) state
end
Lance
Joined 22nd Jul 2003