-
10-13-2009, 06:14 PM #1
Editor - Victory condition: all enemy units dead
It took me some time to figure this out: how to set an objective to COMPLETED after all enemies have been killed off.
Place a few enemy units on the map and add them all to a group named "enemies".
Add an objective (Systems / Missions / Mission objective) to the map - default name is "objective".
Then place a script anywhere on the map (Systems / Scripting / Level Script), go to the level.lua Tab that appears and start coding:
When the mission starts the objective is set to "IN_PROGRESS". When somebody dies on the battlefield OFP:isAlive(enemies) checks if anyone of the group "enemies" is still alive. If they are all dead the objective is set to "COMPLETED" and the mission ends.Code:function onMissionStart() OFP:setObjectiveState("objective", "IN_PROGRESS"); end function onDeath(victim,killer) a = OFP:isAlive(enemies); if(a == false) then OFP:setObjectiveState("objective", "COMPLETED"); OFP:missionCompleted(); end end
It might be wise to add a bit of a delay before OFP:missionCompleted(); but I still have to figure out how.TG-E1st TacticalGamer European Division | Watch this (pretty old) video to find out what TG is all about






A Tactical Gamer since 2005
-
10-16-2009, 05:04 PM #2
Re: Editor - Victory condition: all enemy units dead
Thats a pretty neat script and i'll be using that shortly once i get time to start doing some editing.
Maybe we should have a script thread where people Write out their script and explain what it does. I'm sure if we had something like that, we would get such a huge veriaty of missions from all sorts of different people.PR ingame name - |TG-Irr| SilverJohn
-
10-17-2009, 08:40 AM #3
Re: Editor - Victory condition: all enemy units dead
Just tried the script it seems when ever 1 enemy dies, the mission ends?
PR ingame name - |TG-Irr| SilverJohn
-
10-17-2009, 04:23 PM #4
Re: Editor - Victory condition: all enemy units dead
I found the error ... you need to do OFP:isAlive("enemies") with the quotes or it won't work.
TG-E1st TacticalGamer European Division | Watch this (pretty old) video to find out what TG is all about






A Tactical Gamer since 2005
-
10-17-2009, 04:27 PM #5
Re: Editor - Victory condition: all enemy units dead
Updated script with bugfix and timer:
Code:function onMissionStart() OFP:setObjectiveState("objective", "IN_PROGRESS"); end function onDeath(victim,killer) if(not OFP:isAlive("enemies")) then OFP:addTimer("YouWin", 20000); -- this will wait 20 secs before announcing mission complete end end function onTimerYouWin() OFP:removeTimer("YouWin"); -- remove the timer OFP:setObjectiveState("objective", "COMPLETED"); -- set objective complete OFP:missionCompleted(); -- end mission - success end
edit: still not sure if this OFP:isAlive("enemies") works consistently. i am getting mixed results. sometimes it is true even if there are still enemies standing, sometimes it is not.Last edited by dawolf; 10-17-2009 at 05:21 PM.
TG-E1st TacticalGamer European Division | Watch this (pretty old) video to find out what TG is all about






A Tactical Gamer since 2005
-
10-17-2009, 08:27 PM #6
Re: Editor - Victory condition: all enemy units dead
Cool will try give the new script a go!
PR ingame name - |TG-Irr| SilverJohn
-
10-24-2009, 06:39 PM #7
- Join Date
- Jun 2007
- Location
- Myrtle Beach, SC
- Posts
- 303
Re: Editor - Victory condition: all enemy units dead
I am using this script but I modified it a bit to monitor 2 different echelons that are guarding a town. For some reason it is not reporting the deaths of either the individual echelon members or triggering the objective completion. Any ideas?
It was working yesterday but it stopped for some reason :/
Code:capture = 0; function onDeath_echeloni10(victim, killer) OFP:displaySystemMessage("soldier down") a = OFP:isAlive("EchelonI10"); if(a == false) then capture = capture +1; if capture == 2 then captureComplete(); end end end function onDeath_echeloni5(victim, killer) OFP:displaySystemMessage("soldier down") a = OFP:isAlive("EchelonI5"); if(a == false) then capture = capture +1; if capture == 2 then captureComplete(); end end end function captureComplete() OFP:setObjectiveState("capture", "COMPLETED") heliReinforcements() end

The liberties of our country, the freedom of our civil Constitution, are worth defending at all hazards; and it is our duty to defend them against all attacks. We have received them as a fair inheritance from our worthy ancestors: they purchased them for us with toil and danger and expense of treasure and blood, and transmitted them to us with care and diligence. It will bring an everlasting mark of infamy on the present generation, enlightened as it is, if we should suffer them to be wrested from us by violence without a struggle, or to be cheated out of them by the artifices of false and designing men.
Samuel Adams
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)




Reply With Quote


Bookmarks