Welcome to Tactical Gamer

+ Reply to Thread
Results 1 to 7 of 7
Discussion: Operation Flashpoint - Dragon Rising / OFPDR - Mods and Missions - Editor - Victory condition: all enemy units dead - It took me some time to figure this out: how to set an objective to
  1. #1

    dawolf's Avatar

    Join Date
    Aug 2005
    Location
    Vienna, Austria
    Age
    33
    Posts
    1,373

    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:

    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
    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.

    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

  2.  
  3. #2

    Ivan_the_bad's Avatar

    Join Date
    Jun 2007
    Location
    London
    Age
    22
    Posts
    530

    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

  4.  
  5. #3

    Ivan_the_bad's Avatar

    Join Date
    Jun 2007
    Location
    London
    Age
    22
    Posts
    530

    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

  6.  

     
  7. #4

    dawolf's Avatar

    Join Date
    Aug 2005
    Location
    Vienna, Austria
    Age
    33
    Posts
    1,373

    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

  8.  
  9. #5

    dawolf's Avatar

    Join Date
    Aug 2005
    Location
    Vienna, Austria
    Age
    33
    Posts
    1,373

    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.  
  11. #6

    Ivan_the_bad's Avatar

    Join Date
    Jun 2007
    Location
    London
    Age
    22
    Posts
    530

    Re: Editor - Victory condition: all enemy units dead

    Cool will try give the new script a go!
    PR ingame name - |TG-Irr| SilverJohn

  12.  

     
  13. #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

  14.  

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


  
 

Back to top