LUA script for adding points when unit arrives

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
User avatar
AdmiralSteve
Posts: 288
Joined: Mon Mar 28, 2011 2:32 pm
Location: Red Bluff, CA

LUA script for adding points when unit arrives

Post by AdmiralSteve »

Hello all,

I'm struggling a bit with some Lua script and I'm in dire need for it. I have a scenario that will require a unit to enter an area which triggers points to be added to the respective side. This individual units arrival is key to completing the scenario. The unit though does not exist at the beginning of the scenario and is added through Lua script when a helo remains in another pre-determined area. The helo then picks-up the unit and then returns to its base. (If this sounds like a rescue scenario, that's exactly what it is.)

Can anyone take the time to write a Lua script for that arrival?

Greatly appreciative,

Steven Raymond
“There are no extraordinary men...just extraordinary circumstances that ordinary men are forced to deal with.”
Admiral William Frederick Halsey Jr. 1882-1959

KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: LUA script for adding points when unit arrives

Post by KnightHawk75 »

Do you need help with creating the trigger for a not yet existing unit, with dynamically creating that as part of the units getting generated, or just with the lua to do the simple point change after the triggers execute. You've said basically what you want but not what part you're having a problem with, or is it you need a demo of the entire thing.
User avatar
AdmiralSteve
Posts: 288
Joined: Mon Mar 28, 2011 2:32 pm
Location: Red Bluff, CA

Re: LUA script for adding points when unit arrives

Post by AdmiralSteve »

KnightHawk75 wrote: Mon May 16, 2022 2:51 am Do you need help with creating the trigger for a not yet existing unit, with dynamically creating that as part of the units getting generated, or just with the lua to do the simple point change after the triggers execute. You've said basically what you want but not what part you're having a problem with, or is it you need a demo of the entire thing.
What I have a problem with is the trigger I guess since I thought I would need to have an existing unit to create a trigger. The unit doesn't show up in the scenario (via a lua script) until another unit remains in the area, picks it up and then takes it to a base.

Steve
“There are no extraordinary men...just extraordinary circumstances that ordinary men are forced to deal with.”
Admiral William Frederick Halsey Jr. 1882-1959

Craigkn
Posts: 200
Joined: Thu Jan 27, 2022 12:06 am
Location: Central Maryland

Re: LUA script for adding points when unit arrives

Post by Craigkn »

I did something very similar, but with a slightly different approach - I set "unit enter" triggers to aircraft that already existed. I wanted to simulate a VIP arriving at one air base, and requesting transportation to a second air base. This is how I structured it:

Event 1: Time time based trigger to start event:
- display message "go pick up VIP with your Osprey"
- lua script to spawn a stranded personnel, named "VIP", at a specified point

Event 2: "unit enters area trigger (MV-22)" for square over "VIP" spawn point:
- lua script to delete "VIP" unit
- display message "take VIP to base X"

Event 3: "unit enters area trigger (MV-22)" for square over Base X:
-lua script to spawn VIP unit next to base (if desired)
- display message "VIP delivered, good job!"
- add points
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: LUA script for adding points when unit arrives

Post by KnightHawk75 »

AdmiralSteve wrote: Mon May 16, 2022 1:28 pm
KnightHawk75 wrote: Mon May 16, 2022 2:51 am Do you need help with creating the trigger for a not yet existing unit, with dynamically creating that as part of the units getting generated, or just with the lua to do the simple point change after the triggers execute. You've said basically what you want but not what part you're having a problem with, or is it you need a demo of the entire thing.
What I have a problem with is the trigger I guess since I thought I would need to have an existing unit to create a trigger. The unit doesn't show up in the scenario (via a lua script) until another unit remains in the area, picks it up and then takes it to a base.

Steve
Create the trigger via lua, with the guid of the unit that doesn't exist yet but will exist later (ie when you do create the units use specific guids), and never open it via the gui editor and it should be fine (I've done this plenty). BUT If you then open the trigger in the gui before the unit exists you'll have to delete and recreate the trigger again via lua, as at least as of 1147.4x there is an issue with gui resetting stuff if it doesn't exist during editing. I reported it long ago, it's never been addressed in full. IDK what the new beta does in this regard, so if using that you'll have to see if still has that problem.

Another way is base the trigger on a class and not specific unit, and then don't use that class of unit anywhere else or in a way where it could end up in the same area. This may not always be possible for your purposes.
Post Reply

Return to “Lua Legion”