Page 1 of 1

Events - firing only if all triggers are accomplished

Posted: Thu Jan 12, 2023 9:39 pm
by Sidewinder294
So I'm trying to set a mission failure message to appear using the events system to fire only if two events are true, however currently the event triggers if either happens.

Is there any way to introduce Boolean style checks using the events editor (in this case an AND condition) or do I need to use Lua for that?

Thanks.

Re: Events - firing only if all triggers are accomplished

Posted: Thu Jan 12, 2023 9:57 pm
by Gunner98
There may be a better way but how I have done this in the past is using Conditions and false sides:

Trigger A fires, sets false side A to hostile (this side has no units so is irrelevant)
Trigger B fires sets false side B to hostile

The real event where you have the two triggers but also two Conditions - Condition A = false side A is hostile, Condition B = false side B is hostile

So the event will only fire if both triggers are met.

I used this in Korea Missile Crises where both the NK SSB and the SRBMs needed to be killed before the scenario ended.

Like I said, there may well be a better way but this works

B

Re: Events - firing only if all triggers are accomplished

Posted: Fri Jan 13, 2023 2:40 pm
by KnightHawk75
Sidewinder294 wrote: Thu Jan 12, 2023 9:39 pm So I'm trying to set a mission failure message to appear using the events system to fire only if two events are true, however currently the event triggers if either happens.

Is there any way to introduce Boolean style checks using the events editor (in this case an AND condition) or do I need to use Lua for that?

Thanks.
I'd just use a condition and simple lua statement (or well simple depends what conditions you are checking but...)

if condition1==true and condition2==true then
return true;
else
return false;
end

Question is are the two "events" actual prior or events, or are you using 'events' to describe conditions in your question, ie like if unit 1 is destroyed and unit 2 is damaged at least 50% sort of thing, vs did 2 other events in the event system already execute.

Re: Events - firing only if all triggers are accomplished

Posted: Fri Jan 13, 2023 10:21 pm
by Sidewinder294
Thanks for these.

I tried creating additional sides but I couldn't get it to work very well. Could be me not covering all the proverbial bases.
KnightHawk75 wrote: Fri Jan 13, 2023 2:40 pm
I'd just use a condition and simple lua statement (or well simple depends what conditions you are checking but...)

if condition1==true and condition2==true then
return true;
else
return false;
end

Question is are the two "events" actual prior or events, or are you using 'events' to describe conditions in your question, ie like if unit 1 is destroyed and unit 2 is damaged at least 50% sort of thing, vs did 2 other events in the event system already execute.
So at the moment I have three events set up to cover the outcome in question - one event for each unit being destroyed, which deducts 100 points (but shouldn't end the mission independently as I want the failure to trigger only if both units are lost) and then a third event that currently has the two UnitDestroyed triggers (also used by the separate unit lost events), a message action and an EndScenario action. Is it just a case of putting a LuaScript condition in the conditions editor for the mission end event?

Sorry - total Lua newbie here.

Re: Events - firing only if all triggers are accomplished

Posted: Sat Jan 14, 2023 7:08 am
by KnightHawk75
Sidewinder294 wrote: Fri Jan 13, 2023 10:21 pm So at the moment I have three events set up to cover the outcome in question - one event for each unit being destroyed, which deducts 100 points (but shouldn't end the mission independently as I want the failure to trigger only if both units are lost) and then a third event that currently has the two UnitDestroyed triggers (also used by the separate unit lost events), a message action and an EndScenario action. Is it just a case of putting a LuaScript condition in the conditions editor for the mission end event?

Sorry - total Lua newbie here.
No problem.
So if I understand right you want to test in a 3rd event using both the other 2 unit destroyed triggers that tests for if the two units are both destroyed before letting the message event happen.

Code: Select all

---paste into a condition--
--define little helper function
--all it does is find if a unit exists and returns true if it does.
local function UnitExists(unitsguid)
  local retval,u = pcall(ScenEdit_GetUnit, {guid=unitsguid}); --tries to get the unit.
  if (retval ==true) and u ~= nil then   --if it fails to get the unit, then unit does not exist.
    return true;  --function returns true
  else 
    return false;  --function returns false
  end
end

if UnitExists('PutUnit1GuidHere') == false and UnitExists('PutUnit2GuidHere') == false then
  return true; -- condition returns true, lets the message get displayed.
else 
 return false; --condition returns false, no message is displayed.
end
Attached very simple scene in (1147.52 db3k 497a) that shows it in action for what I think you are describing. Play red, destroy two contacts, upon both being destroyed action message is displayed (on both sides). I believe I set this up similar to what you are describing, if not let me know, I'm can be a bit dense. :D

Re: Events - firing only if all triggers are accomplished

Posted: Sat Jan 14, 2023 8:01 pm
by Sidewinder294
KnightHawk75 wrote: Sat Jan 14, 2023 7:08 am
No problem.
So if I understand right you want to test in a 3rd event using both the other 2 unit destroyed triggers that tests for if the two units are both destroyed before letting the message event happen.

Code: Select all

---paste into a condition--
--define little helper function
--all it does is find if a unit exists and returns true if it does.
local function UnitExists(unitsguid)
  local retval,u = pcall(ScenEdit_GetUnit, {guid=unitsguid}); --tries to get the unit.
  if (retval ==true) and u ~= nil then   --if it fails to get the unit, then unit does not exist.
    return true;  --function returns true
  else 
    return false;  --function returns false
  end
end

if UnitExists('PutUnit1GuidHere') == false and UnitExists('PutUnit2GuidHere') == false then
  return true; -- condition returns true, lets the message get displayed.
else 
 return false; --condition returns false, no message is displayed.
end
Attached very simple scene in (1147.52 db3k 497a) that shows it in action for what I think you are describing. Play red, destroy two contacts, upon both being destroyed action message is displayed (on both sides). I believe I set this up similar to what you are describing, if not let me know, I'm can be a bit dense. :D
That scene works perfectly and does exactly what I was looking for.. in the scene! Tried putting the code with my generated GUIDs into my scenario and it's no longer triggering when one ship is lost (progress!) but isn't firing when the second carrier is sunk either...
This is what's in the condition, events are either unit sunk and the actions to trigger the message and end the scenario.

Code: Select all

---paste into a condition--
--define little helper function
--all it does is find if a unit exists and returns true if it does.
local function UnitExists(unitsguid)
  local retval,u = pcall(ScenEdit_GetUnit, {guid=unitsguid}); --tries to get the unit.
  if (retval ==true) and u ~= nil then   --if it fails to get the unit, then unit does not exist.
    return true;  --function returns true
  else 
    return false;  --function returns false
  end
end

if UnitExists('O63NGK-0HMNJOLQJS2U7') == false and UnitExists('O63NGK-0HMNJOLQJSF6L') == false then
  return true; -- condition returns true, lets the message get displayed.
else 
 return false; --condition returns false, no message is displayed.
end
Is there anything else I need to set up in the console perhaps?

Re: Events - firing only if all triggers are accomplished

Posted: Sun Jan 15, 2023 2:52 am
by KnightHawk75
No problem... I see the problem.

Basically you're potentially firing an End-scenario before the other full destruction event can fire, since you share triggers one can run before the other, such that scene ends before the other event is processed. This no biggy so long as you can live with say a 5 second delay between the message and the scene ending if the player continues.

I've adjusted it to work that way in the attached, it adds an event that ends the scene after 5 seconds, but is only enabled when your condition checking event succeeds and enables it.
Maldives Melee_khedit.zip
(181.24 KiB) Downloaded 12 times

btw if you want to test easy... just load the scene, press play, and while playing just plop this into console and execute it, it'll set the posture and kill the two ships causing all the events to fire. You should get the message, and then if you continue 4-6 seconds later you should get the end scenario message, and the score should be right.

Code: Select all

ScenEdit_SetSidePosture('US', 'India', 'H');
ScenEdit_KillUnit({guid="O63NGK-0HMNJOLQJS2U7"});
ScenEdit_KillUnit({guid="O63NGK-0HMNJOLQJSF6L"});