Jump to content

Function setAltitude() doesn't work: How to set group's spawn altitude in script?


Go to solution Solved by Grimes,

Recommended Posts

Posted (edited)

I'm editing a BFM mission that require both sides to spawn at random altitude in order to simulate different situation. I found setAltitude() function from hoggitworld. However, the aircrafts keep on spawning at the altitude I set when placing them. It seems that I fail to use setAltitude() in the right way. 

The script is as follows and it shall activate once the mission start.

 image.png

So where am I wrong? And is there a better way to spawn objects at random altitude?

By the way, I just name the groups after the countries they're from. Not intended.

Edited by JedimasterLu
Posted

It doesn't change where they spawn at, it changes the altitude a "live" aircraft is flying at. If the group was spawned in they will be flying their route at whatever altitude was set to, then upon being given the task the AI will ascend or descend as needed. 

If you want to change the altitude a group spawns at then its best to use the group as a template of sorts, modify the properties as needed, and then spawn it. Using mist this can be done with something like the following: 

local gp = mist.getGroupTable("USAF")
gp.clone = true
local rndAlt = math.random(4, 10) * 1000
for i = 1, #gp.route.points do
  gp.route.points[i].alt = rndAlt
end
mist.dynAdd(gp)

 

Also the units of measurement are in meters. You'd tell the aircraft to go to a random altitude between 49,000 feet and 98,000 feet. 

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

Posted
local gp = mist.getGroupTable("USAF")
gp.clone = true
local rndAlt = math.random(4, 10) * 1000
for i = 1, #gp.route.points do
  gp.route.points[i].alt = rndAlt
end
mist.dynAdd(gp)

Thank you for your help. But I tried the script and it still didn't work. The game run without error message but the objects just keep on spawning at their original altitude. This is my settings in the trigger.

Digital Combat Simulator  Black Shark Screenshot 2023.02.16 - 22.34.15.12.png

The items in activation column are: do script file (mist_4_5_107.lua), do script file (a file of the code you offered), message to all (mark the begin of test), activate group ("USAF") and ("RUSAF").

At first I assume that 'activate group' is not needed since in the instruction of MIST, dynAdd() can directly spawn the group. But no group is spawned after I delete 'activate group'.

  • Solution
Posted

Slight omission on my part. It is copying the group as defined in the editor, which means the group still has the "late activation" value applied to it. So it is spawning a group, but the group isn't activated. You have to remove that value. 

local gp = mist.getGroupTable("USAF")
gp.clone = true
gp.lateActivation = nil
local rndAlt = math.random(4, 10) * 1000
for i = 1, #gp.route.points do
  gp.route.points[i].alt = rndAlt
end
mist.dynAdd(gp)

 

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

  • Recently Browsing   0 members

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