Page 1 of 1

Trigger Question

Posted: Mon Jan 09, 2023 2:59 am
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.

Re: Trigger Question

Posted: Mon Jan 09, 2023 6:10 am
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.

Re: Trigger Question

Posted: Mon Jan 09, 2023 4:09 pm
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.