Jump to content

Script for Tanker Setting Speed and Altitude


Recommended Posts

Hi there,

Hope someone can help me with this. I need to set up an F10 menu, with the options of +2000 FT or -2000 FT, and +20 KTS or -20 KTS (in m/s) to change tanker race track.

But I can't even make the setAltitude and setSpeed to work with constant values...

 

Ignoring the fact that I have some code for activation and deactivation of enemy units, what am I doing wrong here?

 

Also, if someone can explain me how I can do the +/- 2000 FT and +/- 20 KTS would be glad. Thank you. Regards

local function setFlag(val)
trigger.action.setUserFlag(val.flag, true)
end

local function pushTask(tanker)
trigger.action.pushAITask(Group.getByName(tanker.group), tanker.index)
end

local function setSpd(tanker)
trigger.action.deactivateGroup(Group.getByName(tanker.group))
end

local function setAlt(tanker)
Group.getByName(tanker.group):getController():setAltitude(2000, true, "BARO")
trigger.action.outText("Altitude Set 2000" , 20 , true)
end

local function activateEnemy(enemy)
trigger.action.activateGroup(Group.getByName(enemy.group))
trigger.action.outText(enemy.txt , 20 , true)
end

local mission_options = missionCommands.addSubMenu('Mission Options')
local ground_options = missionCommands.addSubMenu('Ground Options', mission_options)
local fighter_options = missionCommands.addSubMenu('Fighter Options', mission_options)
local fighter_options_first = missionCommands.addCommand('First Wave', fighter_options, setFlag, {flag= 1})
local fighter_options_second = missionCommands.addCommand('Second Wave', fighter_options, setFlag, {flag= 2})
local fighter_options_second_1 = missionCommands.addCommand('First Wave Alt', fighter_options, activateEnemy, {group= 'RED WAVE 1',txt= "First Wave Alternative"})
local fighter_options_second_2 = missionCommands.addCommand('Second Wave Alt', fighter_options, activateEnemy, {group= 'RED WAVE 2'})
local fighter_options_second_1_alt = missionCommands.addCommand('Second Wave 1 Altitude', fighter_options, setAlt, {group= 'RED WAVE 1'})

local tanker_options = missionCommands.addSubMenu('Tanker Options')
local tanker_F18 = missionCommands.addSubMenu('F18 Options', tanker_options)
local tanker_F16 = missionCommands.addSubMenu('F16 Options', tanker_options)
local tanker_F16_20000 = missionCommands.addCommand('20000 FT and M 0.8', tanker_F16, pushTask, {group= "tanker",index= 2})
local tanker_F18_MPRS = missionCommands.addSubMenu('F18 MPRS', tanker_F18)
local tanker_F18_MPRS_6500 = missionCommands.addCommand('Request 6562 FT', tanker_F18_MPRS, pushTask, {group= 'tanker',index= 1})
local tanker_F18_MPRS_11500 = missionCommands.addCommand('Request 11483 FT', tanker_F18_MPRS, pushTask, {group= 'tanker',index= 2})
local tanker_F18_MPRS_speed = missionCommands.addCommand('Set speed 264', tanker_F18_MPRS, setSpd, {group= 'tanker'})
local tanker_F18_MPRS_alt = missionCommands.addCommand('Set atl 2000', tanker_F18_MPRS, setAlt, {group= 'tanker'})

 

ASUS N552VX | i7-6700HQ @ 2.59GHz | 16 GB DDR3 | NVIDIA GF GTX 950M 4 Gb | 250 Gb SSD | 1 Tb HD SATA II Backup | TIR4 | Microsoft S. FF 2+X52 Throttle+Saitek Pedals | Win 10 64 bits

Link to comment
Share on other sites

No one dares? I still didn't manage to get the tanker to change speed... or altitude... relative to the speed/alt it has, while holding (race-track).


Edited by Focha
lack of info

ASUS N552VX | i7-6700HQ @ 2.59GHz | 16 GB DDR3 | NVIDIA GF GTX 950M 4 Gb | 250 Gb SSD | 1 Tb HD SATA II Backup | TIR4 | Microsoft S. FF 2+X52 Throttle+Saitek Pedals | Win 10 64 bits

Link to comment
Share on other sites

It is definitely possible because I wrote the exact functionality into Grayflag. 

From your code and the the MRPS submenu I was able to set the altitude just fine. 

Relative altitude requires you to just do Unit.getPoint() on the aircraft, then add or subtract the desired relative change from that value, and pass that to setAltitude. Speed is the same thing but you need to use getVelocity then some math on the unit vector returned to get the speed in m/s. Basically:

local tanker = Unit.getByName("tankerUnit")
local vec = tanker:getVelocity()
local speed = (vec.x^2 + vec.y^2 + vec.z^2)^0.5

 

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

  • 8 months later...
On 2/14/2023 at 2:01 AM, Grimes said:

Relative altitude requires you to just do Unit.getPoint() on the aircraft, then add or subtract the desired relative change from that value, and pass that to setAltitude. Speed is the same thing but you need to use getVelocity then some math on the unit vector returned to get the speed in m/s. Basically:

Hi Grimes,

Is it possible to share your script part where you set this ?

I'm struggeling to find the solution to set altitude and speed of tankers ?

Thanks

Link to comment
Share on other sites

On 11/11/2023 at 10:55 AM, boyington2 said:

I'm struggeling to find the solution to set altitude and speed of tankers ?

https://wiki.hoggitworld.com/view/DCS_func_setSpeed

https://wiki.hoggitworld.com/view/DCS_func_setAltitude

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

  • 1 month later...

If someone stumbles over this topic, because `setSpeed` or `setAltitude` doesn't seem to work:

I found out, that all calls to those functions in scripts that are executed at mission start are ignored or overridden. You need to call them once the mission is already running.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...