Jump to content

Help: Unit name checking trigger condition


Recommended Posts

Hello,

 

I am trying to create a better scoring system for our PvP match.

 

If any unit named as "R-GND1*****" is dead, the score flag of the blue would be increased by one.

If any unit named as "R-GND2*****" is dead, the score flag of the blue would be increased by two.

If any aircraft named as "B-AIR*****" is dead, the score flag of the red would be increased by five.

 

Here the name should start as R-GND1 and the rest of the unit name does not matter for score to be registered as one point.

How can add this to condition triggers with lua?

 

Any help is appreciated. Thanks in advance.


Edited by Terzi
[CENTER] [/CENTER]
Link to post
Share on other sites

Since I don't know how you get notified that a unit is dead (i'm assuming that you are using some kind of event processing for your script), it'll be something along the following:

 

function stringStartsWith(theString, thePrefix)
	return theString:find(thePrefix) == 1
end
-- theUnit is the unit that was killed
if stringStartsWith(theUnit:getName(), "R-GND1") then trigger.action.setUserFlag(blueScore, trigger.action.getUserFlag(theFlag) + 1 end

if stringStartsWith(theUnit:getName(), "R-GND2") then trigger.action.setUserFlag(bluesScore, trigger.action.getUserFlag(theFlag) + 2 end

-- and so forth

 

 

-ch

Link to post
Share on other sites
24 minutes ago, cfrag said:

Since I don't know how you get notified that a unit is dead (i'm assuming that you are using some kind of event processing for your script), it'll be something along the following:

 


function stringStartsWith(theString, thePrefix)
	return theString:find(thePrefix) == 1
end
-- theUnit is the unit that was killed
if stringStartsWith(theUnit:getName(), "R-GND1") then trigger.action.setUserFlag(blueScore, trigger.action.getUserFlag(theFlag) + 1 end

if stringStartsWith(theUnit:getName(), "R-GND2") then trigger.action.setUserFlag(bluesScore, trigger.action.getUserFlag(theFlag) + 2 end

-- and so forth

 

 

-ch

Thanks!

 

So another problem is to find out a way to get an event for unit deaths.. Well maybe one way is to keep a list of all units in the map and update the score on a regular basis (let's say every ten seconds) to check which ones are dead.

[CENTER] [/CENTER]
Link to post
Share on other sites

Usually, you'll provide a callback to DCS, and your script will be called every time something happens. You then look for specific events (like Kill or Destroy) and when you have found the appropriate event, you look if a unit you are interested in is affected, and then execute the code. This is probably of interest for you.

  • Like 1
Link to post
Share on other sites
56 minutes ago, cfrag said:

Usually, you'll provide a callback to DCS, and your script will be called every time something happens. You then look for specific events (like Kill or Destroy) and when you have found the appropriate event, you look if a unit you are interested in is affected, and then execute the code. This is probably of interest for you.

I have just checked the library called mist and found the documentation of it. I think that library provides what I need. It has API to obtain a table of units, subtract dead ones etc. Thanks for your help I really appreciate it.

[CENTER] [/CENTER]
Link to post
Share on other sites
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...