Editor-LUA Help

Post bug reports and ask for game support here.

Moderator: MOD_Command

Post Reply
s1nnfe1n
Posts: 6
Joined: Sat Jun 10, 2017 1:35 pm

Editor-LUA Help

Post 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.


User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Editor-LUA Help

Post 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
Michael
s1nnfe1n
Posts: 6
Joined: Sat Jun 10, 2017 1:35 pm

RE: Editor-LUA Help

Post 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.

User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Editor-LUA Help

Post 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
Michael
s1nnfe1n
Posts: 6
Joined: Sat Jun 10, 2017 1:35 pm

RE: Editor-LUA Help

Post 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.
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Editor-LUA Help

Post 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
 --
Michael
s1nnfe1n
Posts: 6
Joined: Sat Jun 10, 2017 1:35 pm

RE: Editor-LUA Help

Post by s1nnfe1n »

Thank you very much mate, that was great help.

I will try it out.
Post Reply

Return to “Tech Support”