Jump to content

Need some scripting help.


nighthawk2174

Recommended Posts

The goal of the script is every time a unit is killed it will a) detect the event, b) figure out its type and coalition, c) Increase the value of a sides point tracking flag, d) display a message that said event occurred e) Display the total number of points every few minutes.

 

What I need help with is I haven't got the messages working and I'm not actually sure of a good way to check and see if the value of the point flags is increasing correctly as well. Secondly, I'd like to get a message system working that can also only send the message to the player that killed said unit but i'm not sure how that's even possible. I am very new to both DCS scripting and lua so forgive me if its a bunch of stupid mistakes I made.

 

Code:

 

 

--setup
env.setErrorMessageBoxEnabled(false)

--Setup Messages Used

Killmessage 		= "UNIT KILLED! ";
KilledUnit 			= "Killed - ";
K_lightunit			= "Light Vehicle";
K_APCunit 			= "APC";
K_IFVunit 			= "IFV";
K_APC_missile_unit  = "APC with AT Missile";
K_IFV_missile_unit  = "IFV with AT Missile";
K_TDLTunit 			= "TD/LT";
K_MBTunit			= "MBT";
K_Artillery 		= "Arty";
K_AAAunit 			= "AAA";
K_IRSAMunit 		= "IR SHORAD";
K_SRadar			= "Radar SHORD";
K_MRadar			= "Medium Range SAM Radar";
K_LRadar  			= "Long Range SAM Radar";
K_Luancher	 		= "Launcher";
K_Lheli				= "Light Helicopter";
K_Mheli				= "Transport Helicopter";
K_Aheli				= "Attack Helicopter";
K_Fighter			= "Fighter";
K_Mrole				= "Fixed Wing Multirole";
K_Strike			= "Fixed Wing Strike";
---------------------------

-- flag names table:
flag_names = {
["blue_point_counter"] = '1', 	-- 1 - flag for counting blue points
["red_point_counter"] = '2',	-- 2 - flag for counting red points
};
---------------------------
-- resets flags:
trigger.action.setUserFlag(blue_point_counter, 0); 
trigger.action.setUserFlag(red_point_counter, 0); 
---------------------------
-- Adding points--
if (world.event.S_EVENT_DEAD == event.id) then
--
local _status, unit_properties = pcall(function() return { 
typeName = event.initiator:getTypeName(), coalition = event.initiator:getCoalition(); } end);

		if 'M1043' == unit_properties.typeName 
			or 'M1045' == unit_properties.typeName


				then
			
			if unit_properties.coalition == coalition.side.BLUE then 
				local RedPoints = trigger.misc.getUserFlag(flag_names.red_point_counter); 
				trigger.action.outTextForCoalition(RED,Killmessage .. KilledUnit .. K_lightunit, 3,0);
				trigger.action.setUserFlag(flag_names.red_point_counter, RedPoints + 1);
			end
			
			if unit_properties.coalition == coalition.side.RED then 
				local BluePoints = trigger.misc.getUserFlag(flag_names.blue_point_counter); 
				trigger.action.outTextForCoalition(BLUE,Killmessage .. KilledUnit .. K_lightunit, 3,0);
				trigger.action.setUserFlag(flag_names.blue_point_counter, BluePoints + 1);
			end
			
		end
---------------------- APC
if 'BMD-1' == unit_properties.typeName 
			or 'BTR-80' == unit_properties.typeName
			or 'M-113' == unit_properties.typeName
			or 'AAV7' == unit_properties.typeName
			or 'M1126 Stryker ICV' == unit_properties.typeName

				then
			
			if unit_properties.coalition == coalition.side.BLUE then 
				local RedPoints = trigger.misc.getUserFlag(flag_names.red_point_counter); 
				trigger.action.outTextForCoalition(RED,Killmessage .. KilledUnit .. K_APCunit, 3,0);
				trigger.action.setUserFlag(flag_names.red_point_counter, RedPoints + 2);
			end
			
			if unit_properties.coalition == coalition.side.RED then 
				local BluePoints = trigger.misc.getUserFlag(flag_names.blue_point_counter); 
				trigger.action.outTextForCoalition(BLUE,Killmessage .. KilledUnit .. K_APCunit, 3,0);
				trigger.action.setUserFlag(flag_names.blue_point_counter, BluePoints + 2);
			end
			
		end
---------------------- IFV
if 'BMD-1' == unit_properties.typeName 
			or 'BMP-1' == unit_properties.typeName
			or 'BMP-2' == unit_properties.typeName
			or 'BMP-3' == unit_properties.typeName
			or 'LAV-25' == unit_properties.typeName
			or 'Marder' == unit_properties.typeName 
			or 'warrior' == unit_properties.typeName
			or 'MCV-80' == unit_properties.typeName

				then
			
			if unit_properties.coalition == coalition.side.BLUE then 
				local RedPoints = trigger.misc.getUserFlag(flag_names.red_point_counter); 
				trigger.action.outTextForCoalition(RED,Killmessage .. KilledUnit .. K_IFVunit, 3,0);
				trigger.action.setUserFlag(flag_names.red_point_counter, RedPoints + 3);
			end
			
			if unit_properties.coalition == coalition.side.RED then 
				local BluePoints = trigger.misc.getUserFlag(flag_names.blue_point_counter); 
				trigger.action.outTextForCoalition(BLUE,Killmessage .. KilledUnit .. K_IFVunit, 3,0);
				trigger.action.setUserFlag(flag_names.blue_point_counter, BluePoints + 3);
			end
			
		end
---------------------- APC with missiles
if 'M1134 Stryker ATGM' == unit_properties.typeName
			or 'BTR-RD' == unit_properties.tyepName

				then
			
			if unit_properties.coalition == coalition.side.BLUE then 
				local RedPoints = trigger.misc.getUserFlag(flag_names.red_point_counter); 
				trigger.action.outTextForCoalition(RED,Killmessage .. KilledUnit .. K_APC_missileunit, 3,0);
				trigger.action.setUserFlag(flag_names.red_point_counter, RedPoints + 4);
			end
			
			if unit_properties.coalition == coalition.side.RED then 
				local BluePoints = trigger.misc.getUserFlag(flag_names.blue_point_counter); 
				trigger.action.outTextForCoalition(BLUE,Killmessage .. KilledUnit .. K_APC_missileunit, 3,0);
				trigger.action.setUserFlag(flag_names.blue_point_counter, BluePoints + 4);
			end
			
		end
---------------------- IFV with missiles
if 'M-2 Bradley' == unit_properties.typeName 
			or 'BMP-1' == unit_properties.typeName
			or 'BMP-2' == unit_properties.typeName
			or 'BMD-2' == unit_properties.typeName

				then
			
			if unit_properties.coalition == coalition.side.BLUE then 
				local RedPoints = trigger.misc.getUserFlag(flag_names.red_point_counter); 
				trigger.action.outTextForCoalition(RED,Killmessage .. KilledUnit .. K_IFV_missileunit, 3,0);
				trigger.action.setUserFlag(flag_names.red_point_counter, RedPoints + 6);
			end
			
			if unit_properties.coalition == coalition.side.RED then 
				local BluePoints = trigger.misc.getUserFlag(flag_names.blue_point_counter); 
				trigger.action.outTextForCoalition(BLUE,Killmessage .. KilledUnit .. K_IFV_missileunit, 3,0);
				trigger.action.setUserFlag(flag_names.blue_point_counter, BluePoints + 6);
			end
			
		end
---------------------- TD's and light tanks

---------------------- Main Battle Tanks
if 'T-90' == unit_properties.typeName
			or 'T-80UD' == unit_properties.typeName
			or 'T-72B' == unit_properties.typeName
			or 'T-55' == unit_properties.typeName
			or 'M-1 Abrams' == unit_properties.typeName
			or 'Leopard-2' == unit_properties.typeName

				then
			
			if unit_properties.coalition == coalition.side.BLUE then 
				local RedPoints = trigger.misc.getUserFlag(flag_names.red_point_counter); 
				trigger.action.outTextForCoalition(RED,Killmessage .. KilledUnit .. K_MBTunit, 3);
				trigger.action.setUserFlag(flag_names.red_point_counter, RedPoints + 5);
			end
			
			if unit_properties.coalition == coalition.side.RED then 
				local BluePoints = trigger.misc.getUserFlag(flag_names.blue_point_counter); 
				trigger.action.outTextForCoalition(BLUE,Killmessage .. "" KilledUnit .. "" K_MBTunit, 3);
				trigger.action.setUserFlag(flag_names.blue_point_counter, BluePoints + 5);
				trigger.action.env.info("test",1);
			end
			
		end
---------------------- Artillery

---------------------- AAA guns

---------------------- Manpad
if 'Stinger manpad' == unit_properties.typeName
			or 'SA-18 Igla-S manpad' == unit_properties.typeName

				then
			
			if unit_properties.coalition == coalition.side.BLUE then 
				local RedPoints = trigger.misc.getUserFlag(flag_names.red_point_counter); 
				--trigger.action.outText(string text, Time delay)
				trigger.action.setUserFlag(flag_names.red_point_counter, RedPoints + 2);
			end
			
			if unit_properties.coalition == coalition.side.RED then 
				local BluePoints = trigger.misc.getUserFlag(flag_names.blue_point_counter); 
				--trigger.action.outText(string text, Time delay)
				trigger.action.setUserFlag(flag_names.blue_point_counter, BluePoints + 2);
			end
			
		end
---------------------- IR SAM

---------------------- Short Range Radar

---------------------- Medium Range Radar

---------------------- Long Range Radar

---------------------- Any Launcher

---------------------- Light Helicopter
if 'SA342' == _aircraft_properties.typeName
			or 'Kiowa' == unit_properties.typeName

				then
			
			if _aircraft_properties.coalition == coalition.side.BLUE then 
				local RedPoints = trigger.misc.getUserFlag(flag_names.red_point_counter); 
				--trigger.action.outText(string text, Time delay)
				trigger.action.setUserFlag(flag_names.red_point_counter, RedPoints + 10);
			end
			
			if _aircraft_properties.coalition == coalition.side.RED then 
				local BluePoints = trigger.misc.getUserFlag(flag_names.blue_point_counter); 
				--trigger.action.outText(string text, Time delay)
				trigger.action.setUserFlag(flag_names.blue_point_counter, BluePoints + 10);
			end
			
		end
---------------------- Attack Helicopter
if 'AH-64D' == _aircraft_properties.typeName
			or 'MI-28' == unit_properties.typeName
			or 'KA-50' == unit_properties.tyepName
			or 'MI-24' == unit_properties.tyepName
			
				then
			
			if _aircraft_properties.coalition == coalition.side.BLUE then 
				local RedPoints = trigger.misc.getUserFlag(flag_names.red_point_counter); 
				--trigger.action.outText(string text, Time delay)
				trigger.action.setUserFlag(flag_names.red_point_counter, RedPoints + 25);
			end
			
			if _aircraft_properties.coalition == coalition.side.RED then 
				local BluePoints = trigger.misc.getUserFlag(flag_names.blue_point_counter); 
				--trigger.action.outText(string text, Time delay)
				trigger.action.setUserFlag(flag_names.blue_point_counter, BluePoints + 25);
			end
			
		end
---------------------- Fighter
if 'F-15C' == _aircraft_properties.typeName
			or 'Su-27' == unit_properties.typeName
			or 'MiG-29A' == unit_properties.tyepName
			or 'MiG-29S' == unit_properties.tyepName
			or 'Su-33' == unit_properties.tyepName
			or 'M-2000C' == unit_properties.tyepName
			or 'F-14B' == unit_properties.tyepName
			or 'J-11A' == unit_properties.tyepName

				then
			
			if _aircraft_properties.coalition == coalition.side.BLUE then 
				local RedPoints = trigger.misc.getUserFlag(flag_names.red_point_counter); 
				--trigger.action.outText(string text, Time delay)
				trigger.action.setUserFlag(flag_names.red_point_counter, RedPoints + 20);
			end
			
			if _aircraft_properties.coalition == coalition.side.RED then 
				local BluePoints = trigger.misc.getUserFlag(flag_names.blue_point_counter); 
				--trigger.action.outText(string text, Time delay)
				trigger.action.setUserFlag(flag_names.blue_point_counter, BluePoints + 20);
			end
			
		end
---------------------- Multirole
if 'F-16C_50' == _aircraft_properties.typeName
			or 'FA-18C_hornet' == unit_properties.typeName
			or 'JF-17' == unit_properties.typeName
				then
			
			if _aircraft_properties.coalition == coalition.side.BLUE then 
				local RedPoints = trigger.misc.getUserFlag(flag_names.red_point_counter); 
				--trigger.action.outText(string text, Time delay)
				trigger.action.setUserFlag(flag_names.red_point_counter, RedPoints + 40);
			end
			
			if _aircraft_properties.coalition == coalition.side.RED then 
				local BluePoints = trigger.misc.getUserFlag(flag_names.blue_point_counter); 
				--trigger.action.outText(string text, Time delay)
				trigger.action.setUserFlag(flag_names.blue_point_counter, BluePoints + 40);
			end
			
		end
	end
---------------------- Strike
if 'Su-25T' == _aircraft_properties.typeName
			or 'A-10A' == unit_properties.typeName
			or 'A-10C' == unit_properties.tyepName
			or 'AV8BNA' == unit_properties.tyepName
			or 'AJS37' == unit_properties.tyepName
			or 'f-5e3' == unit_properties.tyepName
				then
			
			if _aircraft_properties.coalition == coalition.side.BLUE then 
				local RedPoints = trigger.misc.getUserFlag(flag_names.red_point_counter); 
				--trigger.action.outText(string text, Time delay)
				trigger.action.setUserFlag(flag_names.red_point_counter, RedPoints + 50);
			end
			
			if _aircraft_properties.coalition == coalition.side.RED then 
				local BluePoints = trigger.misc.getUserFlag(flag_names.blue_point_counter); 
				--trigger.action.outText(string text, Time delay)
				trigger.action.setUserFlag(flag_names.blue_point_counter, BluePoints + 50);
			end
			
		end
	end
end
end;


-- Dispaly Point level every few minutes
local show_points_timeout = 300; -- 300 seconds (5 minutes.)
--[[
local tostring(RedPoints)
local tostring(BluePoints)




]]--

 

Link to comment
Share on other sites

Hi

 

The coding can be done in lua . I setup a separate variable inside of lua just to keep score.

Then you create event handlers to check to see if anything is the "DEAD" state.

 

Well the rest you can dig up and keep reading as it's online somewhere.

Link to comment
Share on other sites

I don't know enough about scripting straight in Lua.

 

I'm thinking you might be way better off doing this with MOOSE tho.

 

The guy's have set all this up in moose. You just call the Function you need.

 

All of them

https://flightcontrol-master.github.io/MOOSE_DOCS/Moose_Functional.html

 

Scoring

https://flightcontrol-master.github.io/MOOSE_DOCS/Documentation/Functional.Scoring.html

 

 

MOOSE Docs

https://flightcontrol-master.github.io/MOOSE_DOCS/

 

 

 

SCORING:SetMessagesToCoalition()

Configure to send messages to only those players within the same coalition as the player.

 

looks like with online play, you can send to all. Not a separate spawned unit?

i7-7700K OC @ 5Ghz | ASUS IX Hero MB | ASUS GTX 1080 Ti STRIX | 32GB Corsair 3000Mhz | Corsair H100i V2 Radiator | Samsung 960 EVO M.2 NVMe 500G SSD | Samsung 850 EVO 500G SSD | Corsair HX850i Platinum 850W | Oculus Rift | ASUS PG278Q 27-inch, 2560 x 1440, G-SYNC, 144Hz, 1ms | VKB Gunfighter Pro

Chuck's DCS Tutorial Library

Download PDF Tutorial guides to help get up to speed with aircraft quickly and also great for taking a good look at the aircraft available for DCS before purchasing. Link

Link to comment
Share on other sites

I have been using glogg logger and it will give you instantaneous results at the bottom. Also it filters by such words as SCRIPTING and highlights them in colors that you choose. Makes going through logs much easier to read.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...