Havoc86 Posted May 28, 2023 Share Posted May 28, 2023 Hello everyone! I've been searching for an answer to this for a while but I haven't found an exact one. I know that in 30 minutes time after engine shutdown (after landing) an AI unit (plane or heli) will dissapear (event "dead" and deactivated). I WANT THIS NOT TO HAPPEN. I want them to continue staying on their parking places for 1h, 2h etc. How to achieve this? Is there a way with scripts or with triggers? Please help. Link to comment Share on other sites More sharing options...
cfrag Posted May 28, 2023 Share Posted May 28, 2023 1 hour ago, Havoc86 said: How to achieve this? One possibility is to trap on their S_EVENT_ENGINE_SHUTDOWN, and simply replace these units with a static look-alike. Those won't go away. Link to comment Share on other sites More sharing options...
Havoc86 Posted May 28, 2023 Author Share Posted May 28, 2023 Can you elaborate on that a bit? How exactly can I replace an AI airplane with a static one? Link to comment Share on other sites More sharing options...
cfrag Posted May 28, 2023 Share Posted May 28, 2023 50 minutes ago, Havoc86 said: How exactly can I replace an AI airplane with a static one? It would require a Lua script. Access the unit that caused the shutdown event, an get it's type, heading and location. Then create a new unit descriptor for a static object with the same type, location and heading, destroy the AI unit, and spawn the static object in its place. If you have never done this kind of scripting before, you may run into some issues. If I have the time, maybe I can create a small proof of concept for you. Link to comment Share on other sites More sharing options...
cfrag Posted May 28, 2023 Share Posted May 28, 2023 Here's the "stayWithMe" Lua script that will replace any AI that successfully performs an engine shut-down with a static replica that stays in the mission until the cows come home. Add it to your mission as a DOSCRIPT action during MISSION START. Please refer to the demo mission attached. Sit in your Frogfoot and watch the Cobra and Hog land, then perform their shut-downs. Each time, when complete, they will be replaced by a static (the Cobra first, then the Hog). Show may take up to 10 minutes, so perhaps use time acceleration. Spoiler stayWithMe = {} stayWithMe.version = "1.0.0" stayWithMe.uuid = 0 function stayWithMe.getUUID() stayWithMe.uuid = stayWithMe.uuid + 1 return stayWithMe.uuid end function stayWithMe:onEvent(event) if not event then return end if not event.initiator then return end if event.id ~=19 then return end -- not 'shutdown' local theUnit = event.initiator if not theUnit then return end trigger.action.outText("Shutdown event trapped", 30) if theUnit.getPlayerName and theUnit:getPlayerName() then return end -- player unit, ignore local theGroup = theUnit:getGroup() local cat = theGroup:getCategory() if cat == Group.Category.GROUND then return end if cat == Group.Category.SHIP then return end if cat == Group.Category.TRAIN then return end -- when we get here, unit is aircraft or helo. Let's fake it local theType = theUnit:getTypeName() local theName = theUnit:getName() local cty = theUnit:getCountry() local pos = theUnit:getPosition() heading = math.atan2( pos.x.z, pos.x.x ) pos = theUnit:getPoint() -- I already got it, I know. MOre obvious, though local desc = theUnit:getDesc() local theStatic = {} theStatic.heading = heading theStatic.name = "stayWithMe-" .. stayWithMe.getUUID() theStatic.type = theType theStatic.x = pos.x theStatic.y = pos.z theStatic.livery_id = desc.livery_id -- destroy AI uint theUnit:destroy() -- spawn static coalition.addStaticObject(cty, theStatic) trigger.action.outText("replaced AI unit " .. theName .. " with static", 30) end -- -- start up -- world.addEventHandler(stayWithMe) stayWithMe.lua stayWithMe demo.miz Link to comment Share on other sites More sharing options...
Havoc86 Posted May 28, 2023 Author Share Posted May 28, 2023 Thanks, I'll give it a try and report ASAP. Link to comment Share on other sites More sharing options...
Havoc86 Posted May 28, 2023 Author Share Posted May 28, 2023 Works great! But I have 2 questions. 1) How to spawn the static plane/heli with the same livery of the one that landed (I think it is in the line "theStatic.livery_id = desc.livery_id" but I don't know how to change it to specific livery)? 2) I want to replace the plane/heli with a static one not right after engine shutdown but after some time, say those 30 minutes (just to see animations for some time - pilots on ground, doors open..). So something like "theUnit:destroy() + 30".. Link to comment Share on other sites More sharing options...
Solution cfrag Posted May 28, 2023 Solution Share Posted May 28, 2023 1 hour ago, Havoc86 said: How to spawn the static plane/heli with the same livery of the one that landed I was lazy - you'd have to trawl the mission data structure for the livery of the unit because (as it seems), the information is for - reasons unexplained - not in the desc structure that the script queries from the unit. Getting that information from the mission is tedious to code, but quite possible. 1 hour ago, Havoc86 said: I want to replace the plane/heli with a static one not right after engine shutdown but after some time That should be doable - make the replacement part into its own function, then use timer.scheduleFunction with the unit as argument and you should be all set. 1 Link to comment Share on other sites More sharing options...
Havoc86 Posted May 29, 2023 Author Share Posted May 29, 2023 OK, thanks! Link to comment Share on other sites More sharing options...
Recommended Posts