Page 1 of 1

Editor-LUA Help

Posted: Sat Jun 10, 2017 1:54 pm
by s1nnfe1n
Hello, I am posting this here, i hope i am in the right section.

I am building a scenario where 2 strike packages will destroy 2 bridges, each bridge compromised from 3 sections, East, Center and West grouped together.

And 3 strike packages will SEAD, 3 different sections. South, Center, North. South has 4 radar sites, center has 2 radar sites and north has 4 radar sites.

My problem is that i do not want the scenario to be point based but objective based with time limit.

For the bridges in the Event Editor its something like this.

Trigger
NorthBridgeEastDestroyed (Unit Destroyed Trigger)
NorthBridgeWestDestroyed (Unit Destroyed Trigger)
NorthBridgeCenterDestroyed (Unit Destroyed Trigger)
Condition
Not Have
Action
BridgeDestroyed (Message)

Now i want to end the scenario when all the targets are destroyed.

So in the Event Editor is like:
Trigger
Site A (Unit Destroyed Trigger)
Site B (Unit Destroyed Trigger)
Bridge Etc (Unit Destroyed Trigger)
Condition
Not have
Action
Congratulations bluh bluh (Message)
End Scenario

The problem is that once the first site is destroyed the scenario ends of course. The triggers together are connected with "or".

Did i miss something in the event editor?
Can i do this with Lua Scripting? If Yes How?

Thank you in advance.



RE: Editor-LUA Help

Posted: Sat Jun 10, 2017 2:32 pm
by michaelm75au
The events fire whenever any of triggers are fired.
What I suggest is:
Trigger
NorthBridgeEastDestroyed (Unit Destroyed Trigger)
NorthBridgeWestDestroyed (Unit Destroyed Trigger)
NorthBridgeCenterDestroyed (Unit Destroyed Trigger)
Condition
Return false if all 3 'units' have not been destroyed, else return true
Action
BridgeDestroyed (Message)


---

Trigger
Site A (Unit Destroyed Trigger)
Site B (Unit Destroyed Trigger)
Bridge Etc (Unit Destroyed Trigger)
Condition
Return false if all 'units' have not been destroyed, else return true.
Action
Congratulations bluh bluh (Message)
End Scenario

RE: Editor-LUA Help

Posted: Sat Jun 10, 2017 3:22 pm
by s1nnfe1n
Thank you for your response.

I was thinking the same but in conditions the only way to do this is with Lua. Which i do not know how to use. I read some tutorials to start with by i did nt find anything similar. Only unit related codes, lke changing loads, behaviour, spawn etc.


RE: Editor-LUA Help

Posted: Sat Jun 10, 2017 3:42 pm
by michaelm75au
Yes conditions are basically Lua scripts that return true or false.

Sample condition:

Code: Select all

-- this is the bridge group 
 local unit = ScenEdit_GetUnit({name='North Bridge'})
 if unit == nil then
   -- no group unit, so linked units destroyed
   return true
 end
 return false
 --
Or you could check the individual units of the group in case someone un-grouped them

RE: Editor-LUA Help

Posted: Sat Jun 10, 2017 4:27 pm
by s1nnfe1n
I see.
So You use the units not the triggers to code.

If there are more than one unit for the condition to be true how do i do it?


local unit1 = ScenEdit_GetUnit({name='Rad1'})
if unit1 == nil
and
local unit2 = ScenEdit_GetUnit({name='Rad2'})
if unit2 == nil then
return true
end
return false

or
local unit = ScenEdit_GetUnit({name='Rad1','Rad2','Rad3'})
if unit == nil
return true
end
return false

Is this correct? do i need the -- because i am looking into lua tutorial syntax and i cannot find what -- is for.
Sorry if i ask stupid things but i am new to coding. I understand the principles but the syntax is look chinese to me.

RE: Editor-LUA Help

Posted: Sun Jun 11, 2017 12:34 am
by michaelm75au
Looking at Lua tutorials in general will give you a background on how to interpret the code.
Best way then is to look at some of the community scenarios; a number of the more recent ones make use of Lua to some degree.
To handle multiple unit checks, I usually create a table of the units in question and then cycle thru it.
Something like ...

Code: Select all

-- it is better to use the GUID from the units when you have added them. 
 -- Protects against units with same name or player changing the name during play
 local units = {'Rad1', 'Rad2', 'Rad3'}
 local result = true -- assume condition will pass with all units destroyed
 for i = 1, #units do
 local unit = ScenEdit_GetUnit({ name = units[i]})
 if unit ~= nil then
   -- unit not destroyed
   result = false
   -- no need to check further
   break
 end
 return result
 --

RE: Editor-LUA Help

Posted: Sun Jun 11, 2017 2:20 am
by s1nnfe1n
Thank you very much mate, that was great help.

I will try it out.