Trigger Question

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
User avatar
kevinkins
Posts: 2465
Joined: Wed Mar 08, 2006 11:54 am

Trigger Question

Post by kevinkins »

Is there a way to kill/delete a unit based on the "unit remains in area" trigger?
You would have to ID the unit precisely since the units name or guid are not known ahead of time.

Thanks.
“The study of history lies at the foundation of all sound military conclusions and practice.”
Alfred Thayer Mahan
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Trigger Question

Post by KnightHawk75 »

Unit In Area trigger. {set type of unit categories}

Code: Select all

local u = ScenEdit_UnitX();
if (u ~=nil) and u.guid ~=nil then 
    local n = u.name;
    --Use this one if you want it to trigger unit destroyed event as well when you remove it.
    ScenEdit_KillUnit({guid=u.guid});
    -- Use either of these two to just remove it without also triggering a destruction event aka silent delete.
    --ScenEdit_DeleteUnit({guid=u.guid}, false);  --assumes is single unit not also it's whole group you want destroyed.  --assumes is single unit not a whole group you want destroyed.
    -- OR 
    --u:delete();  --assumes is single unit not a whole group you want destroyed.
    u=nil; print("Unit " .. tostring(n) .. " destroyed by trigger.");
else
    print('Error: could not obtain unit from unitX, this generally shouldn't happen.');
end
Attached Sample scene (play US), that shows it destroy a US SSN entering an area, but not a SSGN who also enters. (1302+ beta required for scene cause database) But if need event setup:
Image
(click for bigger image)

att: Additionally if the trigger selection categories aren't enough for you, you can always add your own unit checks to the code above, and only execute the delete when they are what you want, or use pre-conditions in concert.
like if ((u~=nil) and u.guid ~=nil) and u.type == 'something' and SomeFucToFindIfRadarOn() and ScenEdit_CurrentTime > xyz then ...kill ... end

Let me know if that answers what you need.
User avatar
kevinkins
Posts: 2465
Joined: Wed Mar 08, 2006 11:54 am

Re: Trigger Question

Post by kevinkins »

Thanks. I went right by UnitX forgetting it's about triggers as well as the "unit". Let you know if I have anything else on this one. Trying to sim a drone swarm attack where they reach a target area and "drop" like a buzz bomb aka on a Ukrainian city.
“The study of history lies at the foundation of all sound military conclusions and practice.”
Alfred Thayer Mahan
Post Reply

Return to “Lua Legion”