LUA events script.

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
User avatar
KLAB
Posts: 501
Joined: Tue Feb 27, 2007 5:24 pm

LUA events script.

Post by KLAB »

I've scoured forum for an example to no avail.
With LUA from a special action key I have:
Set and Event.
Set a trigger. (unit remains in area)
This fires an action which throws up a message. So far so good.
But trying to get a LuaScipt action to no avail. How is it written into the Seteventaction?
How exactly is the Scriptext written into the Seteventaction?
I'm trying to get one special action to add an aircraft which flies to a destination stays on the ground there for 1hr then changes sides from Neutral to Player.
I can get this to happen in LUA in isolation but not a one sequential event?
Any help much appreciated and in the context of even the beginners LUA examples being quite challenging.
Thanks.
K
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: LUA events script.

Post by KnightHawk75 »

But trying to get a LuaScipt action to no avail. How is it written into the Seteventaction?
--
So if you're trying to assign an existing LuaScript Action that you have created via gui to an event you are creating in a script and you already have the trigger created and stuff:

Code: Select all

ScenEdit_SetEvent(..sounds like you have this already)
 ScenEdit_SetTrigger(..sounds like you have this already)
 ScenEdit_SetEventTrigger(NameORGuidofTheEventYouCreatedAbove, {mode='add', name='NameOfTriggerYouCreatedAbove'})
 ScenEdit_SetEventAction(NameORGuidofTheEventYouCreatedAbove, {mode='add', name='NameOfAlreadyMadeLuaScriptAction'})
 

How exactly is the Scriptext written into the Seteventaction?
If you mean, you want to script the creation of the Lua Script action itself this would be how.

Code: Select all

 local bk = "\r\n"
 local scriptText1 = 'local abc = 123; print("hello world! I'm now doing going to switch sides");' .. bk .. 'if(abc) == 123 then' .. bk .. 'print("abc=123 bla bla bla ");' .. bk .. 'else' ..bk .. 'print("abc not 123");' .. bk .. end'
 ScenEdit_SetAction({mode='add', type='LuaScript', name= 'MyWonderfulAction', ScriptText = scriptText1})
 ^ creates the LuaScript action using the script you've provided.
 
 --Then just like you use an existing one...
 ScenEdit_SetEvent(..you have this already..)
 ScenEdit_SetTrigger(..sounds like you have this already)
 ScenEdit_SetEventTrigger(NameORGuidofTheEventYouCreatedAbove, {mode='add', name='NameOfTriggerYouCreatedAbove'})
 ScenEdit_SetEventAction(NameORGuidofTheEventYouCreatedAbove, {mode='add', name='MyWonderfulAction'})
 

Not sure I see the need for the second method of scripting the script(but maybe there is a reason\detail of the scene I don't know). BTW you can have multiple actions to one event, so you could have the message first, and a luascript action second.

Some related threads that deal with script events and scripting script creation. Namely timed events and triggers but it applies about the same.
Found just by searching on SetAction, probably more.
fb.asp?m=4759748
fb.asp?m=4559797
fb.asp?m=4846163
fb.asp?m=4390833
fb.asp?m=4822622

If you're having specific problem with a piece of code, let me know.




User avatar
KLAB
Posts: 501
Joined: Tue Feb 27, 2007 5:24 pm

RE: LUA events script.

Post by KLAB »

Very much appreciated, it was an example such as this below I wanted, I just wasn't getting the syntax correct. Thanks again. ScenEdit_SetAction({mode='add', type='LuaScript', name= 'triggerunitAction', ScriptText ="ScenEdit_SetEMCON('Group', 'VisbyGroup', 'Inherit;Radar=Active')"}) -- Add an action that changes the EMCON back to active.
Post Reply

Return to “Lua Legion”