Trigger on Hostilities Commence

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
patpatpowercat
Posts: 15
Joined: Tue Nov 19, 2019 11:51 am

Trigger on Hostilities Commence

Post by patpatpowercat »

I am trying to figure out how to activate a list of missions once two sides commence hostilities. I understand how to activate the missions using lua ScenEdit_SetMission {isactive=true}, but I am trying to figure how to best trigger this action. Originally I was going to do it with a unit destroyed, but I don't want a 3rd side to commence hostilities between the two sides prematurely. So I was looking into firing a once a second trigger and using ScenEdit_GetSidePosture, have if it returns hostile than activate the missions. However, my lua knowledge isn't that great and I'm not sure how to take the return of the GetSidePosture and turn it into a variable for us in an if/then argument, or if this would be the optimal way of doing so.

Any suggestions?
Rory Noonan
Posts: 2418
Joined: Thu Dec 18, 2014 1:53 am
Location: Brooklyn, NY

RE: Trigger on Hostilities Commence

Post by Rory Noonan »

If it's important that the only variable that is counted is the side postures (i.e. you don't want to use a surrogate like a unit destroyed or a weapon fired) then I'd use a regular time trigger of whatever suits, 1s would be fine because this will be light performance wise until triggered, and have an if statement at the start of the script that checks if the sides are hostile and then activates the missions if that condition is true.
local sidePosture = ScenEdit_GetSidePosture('Side A','Side B')

if sidePosture == 'H' then

--your code here

end
Image
patpatpowercat
Posts: 15
Joined: Tue Nov 19, 2019 11:51 am

RE: Trigger on Hostilities Commence

Post by patpatpowercat »

Thanks so much! I just had H instead of 'H' and it wasn't working.
Post Reply

Return to “Lua Legion”