This kind of works:
It forces the initial load to be on the ground and stops the unload from flying off when done.
Code: Select all
local function forceland()
local x,y,z = Spring.GetUnitPosition(unitID)
local landy = Spring.GetGroundHeight(x,z)
local xsize = 32 --use hitbox
local zsize = 54 --use hitbox
local mcenter = 14 --model's center
Spring.MoveCtrl.Enable(unitID)
Spring.Echo ("start pos",y,landy)
if (math.floor(y) - math.floor(landy + mcenter) < 2) and (math.floor(y) - math.floor(landy + mcenter) >= 0) then
Spring.Echo ("already on ground")
landed = 1
return false
end
if (y > (landy + mcenter)) then
landed = 2 ---landing
local _,gny1,_ = Spring.GetGroundNormal ((x+(xsize*0.5)),(z+(zsize*0.5)))
local _,gny2,_ = Spring.GetGroundNormal ((x+(xsize*0.5)),(z-(zsize*0.5)))
local _,gny3,_ = Spring.GetGroundNormal ((x-(xsize*0.5)),(z+(zsize*0.5)))
local _,gny4,_ = Spring.GetGroundNormal ((x-(xsize*0.5)),(z-(zsize*0.5)))
if (gny1 < 0.98)or(gny2 < 0.98)or(gny3 < 0.98)or(gny4 < 0.98) then ---checks for flat landing 0.98 is ~ 11 degrees
Spring.Echo ("landing aborted")
landed = 3 --abort signal
return false
else
while (y > (20 + (landy + mcenter))) do
-- Spring.Echo ("drop at 2.5")
Spring.MoveCtrl.SetVelocity(unitID,0,-2.5,0)
x,y,z = Spring.GetUnitPosition(unitID)
landy = Spring.GetGroundHeight(x,z)
Sleep(100)
end
while (y > (landy + mcenter)) do
--- Spring.Echo ("drop at 1")
Spring.MoveCtrl.SetVelocity(unitID,0,-1,0)
x,y,z = Spring.GetUnitPosition(unitID)
landy = Spring.GetGroundHeight(x,z)
Sleep(100)
end
Spring.MoveCtrl.SetVelocity(unitID,0,0,0)
x,y,z = Spring.GetUnitPosition(unitID)
landy = Spring.GetGroundHeight(x,z)
Spring.MoveCtrl.SetPosition(unitID,x,(landy+mcenter),z)
landed = 1
end
else
Spring.MoveCtrl.SetPosition(unitID,x,landy,z)
landed = 1
end
end
function script.QueryTransport(passengerID)
return -1
end
function script.TransportPickup(passengerID)
Spring.Echo ("hey passenger Pickup",passengerID)
StartThread(forceland)
while landed ~= 1 do
sleep (500)
if landed ==3 then --aborted
Spring.MoveCtrl.Disable(unitID)
landed = 0
return false
end
end
if (landed == 1) then
Spring.UnitScript.AttachUnit (-1, passengerID)
Turn( canopy , x_axis, math.rad(0), math.rad(30) )
WaitForTurn(canopy, x_axis)
Sleep(500)
pilot = 1
Spring.Echo ("pilot",pilot,passengerID,"reporting")
end
end
function script.BeginTransport(passengerID)
Spring.Echo ("hey passenger Begin trans",passengerID)
StartThread(forceland)
while landed ~= 1 do
sleep (500)
if landed ==3 then --aborted
Spring.MoveCtrl.Disable(unitID)
landed = 0
return false
end
end
if (landed == 1) then
Spring.UnitScript.AttachUnit (-1, passengerID)
Turn( canopy , x_axis, math.rad(0), math.rad(30) )
WaitForTurn(canopy, x_axis)
Sleep(500)
pilot = 1
Spring.Echo ("pilot",pilot,passengerID,"reporting")
end
end
function script.StartUnload()
Spring.Echo ("bye passenger")
StartThread(forceland)
while landed ~= 1 do
sleep (500)
if landed ==3 then --aborted
Spring.Echo ("unload aborted")
Spring.MoveCtrl.Disable(unitID)
landed = 0
return false
end
end
end
function script.TransportDrop()
if (landed == 1) then
Turn( canopy , x_axis, math.rad(-60), math.rad(30) )
WaitForTurn(canopy, x_axis)
Sleep(500)
Spring.MoveCtrl.Enable(unitID)
Spring.MoveCtrl.SetVelocity(unitID,0,0,0)
local lx,ly,lz = Spring.GetUnitPosition(unitID)
Spring.MoveCtrl.SetPosition(unitID,lx,ly+14,lz)
UnitScript.DropUnit( passengerID, (lx + 30), ly, (lz + 30)) --offset as not to drop inside unit
pilot = 0
else
Spring.Echo ("unload aborted")
return false
end
end
After changing some things around, this however, lets the flight control be ignored after an unload and the aircraft takes off again to land near by... why?
Code: Select all
local function forceland()
local x,y,z = Spring.GetUnitPosition(unitID)
local landy = Spring.GetGroundHeight(x,z)
local xsize = 32 --use hitbox
local zsize = 54 --use hitbox
local mcenter = 14 --model's center
Spring.MoveCtrl.Enable(unitID)
Spring.Echo ("start pos",y,landy)
if (math.floor(y) - math.floor(landy + mcenter) < 2) and (math.floor(y) - math.floor(landy + mcenter) >= 0) then
Spring.Echo ("already on ground")
landed = 1
return true
end
if (y > (landy + mcenter)) then
landed = 2 ---landing
local _,gny1,_ = Spring.GetGroundNormal ((x+(xsize*0.5)),(z+(zsize*0.5)))
local _,gny2,_ = Spring.GetGroundNormal ((x+(xsize*0.5)),(z-(zsize*0.5)))
local _,gny3,_ = Spring.GetGroundNormal ((x-(xsize*0.5)),(z+(zsize*0.5)))
local _,gny4,_ = Spring.GetGroundNormal ((x-(xsize*0.5)),(z-(zsize*0.5)))
if (gny1 < 0.98)or(gny2 < 0.98)or(gny3 < 0.98)or(gny4 < 0.98) then ---checks for flat landing 0.98 is ~ 11 degrees
Spring.Echo ("landing aborted")
landed = 3 --abort signal
return false
else
while (y > (20 + (landy + mcenter))) do
-- Spring.Echo ("drop at 2.5")
Spring.MoveCtrl.SetVelocity(unitID,0,-2.5,0)
x,y,z = Spring.GetUnitPosition(unitID)
landy = Spring.GetGroundHeight(x,z)
Sleep(100)
end
while (y > (landy + mcenter)) do
--- Spring.Echo ("drop at 1")
Spring.MoveCtrl.SetVelocity(unitID,0,-1,0)
x,y,z = Spring.GetUnitPosition(unitID)
landy = Spring.GetGroundHeight(x,z)
Sleep(100)
end
Spring.MoveCtrl.SetVelocity(unitID,0,0,0)
x,y,z = Spring.GetUnitPosition(unitID)
landy = Spring.GetGroundHeight(x,z)
Spring.MoveCtrl.SetPosition(unitID,x,(landy+mcenter),z)
landed = 1
return true
end
else
Spring.MoveCtrl.SetPosition(unitID,x,(landy + mcenter),z)
landed = 1
return true
end
end
function script.QueryTransport(passengerID)
if landed == 1 then
return -1
else
return false
end
end
function script.TransportPickup(passengerID)
Spring.Echo ("hey passenger Pickup",passengerID)
StartThread(forceland)
while landed ~= 1 do
sleep (500)
if landed ==3 then --aborted
Spring.MoveCtrl.Disable(unitID)
landed = 0
return false
end
end
if (landed == 1) then
Spring.UnitScript.AttachUnit (-1, passengerID)
Turn( canopy , x_axis, math.rad(0), math.rad(30) )
WaitForTurn(canopy, x_axis)
Sleep(500)
pilot = 1
Spring.Echo ("pilot",pilot,passengerID,"reporting")
end
end
function script.BeginTransport(passengerID)
Spring.Echo ("hey passenger Begin trans",passengerID)
StartThread(forceland)
while landed ~= 1 do
sleep (500)
if landed ==3 then --aborted
Spring.MoveCtrl.Disable(unitID)
landed = 0
return false
end
end
if (landed == 1) then
Spring.UnitScript.AttachUnit (-1, passengerID)
Turn( canopy , x_axis, math.rad(0), math.rad(30) )
WaitForTurn(canopy, x_axis)
Sleep(500)
pilot = 1
Spring.Echo ("pilot",pilot,passengerID,"reporting")
end
end
function script.StartUnload()
Spring.Echo ("bye passenger")
StartThread(forceland)
while landed ~= 1 do
sleep (500)
if landed ==3 then --aborted
Spring.Echo ("unload aborted")
Spring.MoveCtrl.Disable(unitID)
return false
end
end
if landed == 1 then
return true
else
return false
end
end
function script.TransportDrop()
if landed ~= 1 then --aborted
Spring.Echo ("i said, unload aborted!")
Spring.MoveCtrl.Disable(unitID)
landed = 0
return false
end
if (landed == 1) then
Turn( canopy , x_axis, math.rad(-60), math.rad(30) )
WaitForTurn(canopy, x_axis)
Sleep(500)
Spring.MoveCtrl.Enable(unitID)
Spring.MoveCtrl.SetVelocity(unitID,0,0,0)
local lx,ly,lz = Spring.GetUnitPosition(unitID)
Spring.MoveCtrl.SetPosition(unitID,lx,ly+mcenter,lz)
UnitScript.DropUnit( passengerID, (lx + 30), ly, (lz - 30)) --offset as not to drop inside unit
pilot = 0
end
end