The Fighting 99th Air Wing

AIR : LAND : SEA : FIGHT!

Hello script?

8 years 3 months ago
TracerFacer
Administrator
Administrator
Posts: 16
Karma: 1
More
Topic Author
Hello script? #700
Looking for a script that welcomes the player when they join an aircraft slot.

It should recognize the aircraft type and give a mission specific message welcoming them to the mission and give any specific instructions that the mission designer deems relevant for that airframe and mission goals.

I could envision at least the following message groups

Cap,
Cas,
Sead
Helo transport (uh1,mi8)
Helo cas (ka, gaz)

So if you enter a slot of that type you get a custom welcome message where the mission designer can give specific inductions to that pilot. Reading the mission briefings won't be such a huge deal since we could give brief but specific instructions for that pilot.

This can all be done with triggers in the mission editor, you just have to give each and every slot it's own trigger. Huge pain!

Any takers?

Please Log in or Create an account to join the conversation.

8 years 3 months ago
LokiV7
Senior Member
Senior Member
Posts: 70
More
Hello script? #4847
and if it's a script, you wouldn't need to set each slot? or even if it's a script you'd have to?

(also, when i type this in chrome, it's like super light green font on grey, can't read unless i highlight what i just typed :-/ )

Please Log in or Create an account to join the conversation.

8 years 3 months ago
TracerFacer
Administrator
Administrator
Posts: 16
Karma: 1
More
Topic Author
Hello script? #4848
In order to send a message to a player, I have to have a trigger for every single aircraft I add to the game. Very tedious and can easily miss some.

Instead I would like to just add a message to a text file. And when a certain type of aircraft becomes alive, send that pilot a 'welcome' message.

Have several different types of messages to send to different aircraft types.

This would probably be a ONCE trigger set to ON TAKE CONTROL. Guessing here, not sure. Hence my request for help :)

Problems with seeing stuff in the forum post in this thread.

Please Log in or Create an account to join the conversation.

8 years 3 months ago
Cygon_Parrot
New Member
New Member
Posts: 1
More
Hello script? #4850
I don't know, Tracer <shrug>

Maybe something like this?
-- Briefing texts...
RED_SEAD = "You must blow up SAM radars, comrade!"
RED_CAP = "You must shoot down attacking bombers and defend our bombers, comrade!"
RED_TRANS_HELO = "You must deliver our valiant soldiers to the front line, comrade!"
RED_ATK_HELO = "You must attack the advancing tanks, comrade!"
RED_CAS = "You must attack all ground units at the front line, comrade!"
BLUE_SEAD = "You gotta be shitting me, man!"
BLUE_CAP = "Follow Sweeper, man!"
BLUE_TRANS_HELO = "Get those GI to where they can kick some butt, man!"
BLUE_ATK_HELO = "Dang! Wish we had some Apaches or Cobras, man!"
BLUE_CAS = "Hogs, ahoy! Go do your stuff, man!"

local Event_Handler = {}

function Event_Handler:onEvent(_Event)

	if _Event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT then
		if _Event.initiator then
			local player_unit = _Event.initiator
			local player_type = player_unit:getTypeName()
			local player_coalition = player_unit:getCoalition()
			local player_name = player_unit:getPlayerName()
			local player_group = player_unit:getGroup()
			local player_group_ID = player_group:getID()
			local side_ID = "nil"
			local message = "nil"

			if player_coalition == 1 then
				side_ID = "Red"
			else
				side_ID = "Blue"
			end
			
			if player_type == "Su-25T" then
				if player_coalition == 1 then
					message = string.format("%s %s %s %s %s", "Hello", side_ID, player_name, ".", RED_SEAD)
				else
					message = string.format("%s %s %s %s %s", "Hello", side_ID, player_name, ".", BLUE_SEAD)
				end
			elseif player_type == "Su-27" or player_type == "F-15C" then
				if player_coalition == 1 then
					message = string.format("%s %s %s %s %s", "Hello", side_ID, player_name, ".", RED_CAP)
				else
					message = string.format("%s %s %s %s %s", "Hello", side_ID, player_name, ".", BLUE_CAP)
				end
			elseif player_type == "UH-1H" or player_type == "Mi-8MTV2" then
				if player_coalition == 1 then
					message = string.format("%s %s %s %s %s", "Hello", side_ID, player_name, ".", RED_TRANS_HELO)
				else
					message = string.format("%s %s %s %s %s", "Hello", side_ID, player_name, ".", BLUE_TRANS_HELO)
				end
			elseif player_type == "Ka-50" then
				if player_coalition == 1 then
					message = string.format("%s %s %s %s %s", "Hello", side_ID, player_name, ".", RED_ATK_HELO)
				end
			elseif player_type == "A-10C" or player_type == "Su-25A" then
				if player_coalition == 1 then
					message = string.format("%s %s %s %s %s", "Hello", side_ID, player_name, ".", RED_CAS)
				else
					message = string.format("%s %s %s %s %s", "Hello", side_ID, player_name, ".", BLUE_CAS)
				end
			end
			
			trigger.action.outTextForGroup(player_group_ID, message, 10, true)
			
		end
	end
end

world.addEventHandler(Event_Handler)

If that is along the lines of what you want, it can be done much more elegantly, coding-wise. Just did this quick and dirty to see if we're thinking along the same lines. Use it in a mission start type trigger.

NOTE: I cannot guarantee I have all the type names right here, but that can be solved if this is sort of what you want. OK?

Please Log in or Create an account to join the conversation.

8 years 3 months ago
TracerFacer
Administrator
Administrator
Posts: 16
Karma: 1
More
Topic Author
Hello script? #4856
Looks pretty good, will try asap! Thx!

Please Log in or Create an account to join the conversation.

8 years 3 months ago
Cygon_Parrot
New Member
New Member
Posts: 1
More
Hello script? #4862

I gave it a try as you requested here, regarding a text file for the briefings, but it wouldn't work. After some head scratching, I think I came upon the reason why lua file I/O won't work in DCS. Look here...

forums.eagle.ru/showpost.php?p=2401585&postcount=2

You OK with just editing the briefings in the script file itself?

On another count, let me throw an idea here for the future. Some aircraft can be used in multiple roles, for example the SU-25T as SEAD or CAS. I was just wondering if it might not be a good idea to have an alternate version of this "Hello" script in which the client aircraft Group name is used to access the briefings. That way you could call them SEAD-01 and CAS-01 (for example) and still use the same type, associated to the Group name, and dependent on the coalition for the exact type selection. Just an idea. Do you see any snags with that?

Finally, here's a list of the aircraft types, as the game identifies them...
02959.976 INFO    SCRIPTING: Mi-8MT
02959.976 INFO    SCRIPTING: Ka-50
02959.976 INFO    SCRIPTING: Su-33
02959.976 INFO    SCRIPTING: Su-27
02959.976 INFO    SCRIPTING: Su-25T
02959.976 INFO    SCRIPTING: Su-25
02959.976 INFO    SCRIPTING: MiG-29S
02959.976 INFO    SCRIPTING: MiG-29A
02959.976 INFO    SCRIPTING: SA342Mistral
02959.976 INFO    SCRIPTING: SA342M
02959.976 INFO    SCRIPTING: SA342L
02959.976 INFO    SCRIPTING: UH-1H
02959.976 INFO    SCRIPTING: C-101EB
02959.976 INFO    SCRIPTING: C-101CC
02959.976 INFO    SCRIPTING: FW-190D9
02959.976 INFO    SCRIPTING: Bf-109K-4
02959.976 INFO    SCRIPTING: TF-51D
02959.976 INFO    SCRIPTING: P-51D
02959.976 INFO    SCRIPTING: MiG-21Bis
02959.976 INFO    SCRIPTING: MiG-15bis
02959.976 INFO    SCRIPTING: M-2000C
02959.976 INFO    SCRIPTING: L-39ZA
02959.976 INFO    SCRIPTING: L-39C
02959.976 INFO    SCRIPTING: F-86F Sabre
02959.976 INFO    SCRIPTING: F-5E-3
02959.976 INFO    SCRIPTING: F-15C
02959.976 INFO    SCRIPTING: A-10C
02959.976 INFO    SCRIPTING: A-10A
02959.976 INFO    SCRIPTING: MiG-29G

Please Log in or Create an account to join the conversation.

8 years 3 months ago
pb_magnet
New Member
New Member
Posts: 1
More
Hello script? #4864
Be careful with those internal unit type IDs.

There are notes in the CTLD code that some of those dashes are high-ASCII / UNICODE:
ctld.vehicleTransportEnabled = {
    "76MD", -- the il-76 mod doesnt use a normal - sign so il-76md wont match... !!!! GRR
    "C-130",
}
ctld.jtacUnitTypes = {
    "SKP", "Hummer" -- there are some wierd encoding issues so if you write SKP-11 it wont match as the - sign is encoded differently...
}

Please Log in or Create an account to join the conversation.

8 years 3 months ago
Cygon_Parrot
New Member
New Member
Posts: 1
More
Hello script? #4866

Thanks, Magnet! I'm kind of used to that sort of thing and many others like it from my C/C++ coding days, but it is a good consideration for all, just the same. It is precisely the reason that I got an output of the type ID names straight from a running game and dumped it to env. info, so copy paste from that list should be safe. Also, the script is pretty memory leak proof, as far as I can see, as the job is done once the briefing is output to screen, and there's no need to do any PLAYER LEAVE UNIT or PLAYER DEAD memory cleanup routines. That the file I/O doesn't work is a plus there, too. It was, is and will always be a famous source of problems as long as coders are still humans.

Anyway, here's a cleaned up version, tested as far as I can, as I do not have all the modules. Also, not tested in MP on a server, yet. I used the slightly (lol!) old fashioned way of array indexing, as it is more rock solid and problem proof for this sort of application, at least.
-- Array table init...
local BRIEFINGS = {}
local AC_TYPES = {}

-- NOTE: Option base 1
-- local NUMBER_OF_TASKS = 7 
local NUMBER_OF_TASKS = {7, 5}

-- Briefing texts...
BRIEFINGS[1] = 
	{
		"Red SEAD: Destroy enemy SAM radars." ,
		"Red CAP: Protect our SEAD and CAS flights from enemy fighters.",
		"Red CAS: Destroy enemy ground units at the front line.",
		"Red STRIKE: Perform strike on enemy fixed installations.",
		"Red INTCPT: Intercept inbound enemy strike aircraft.",
		"Red TRNS HELO: Transport troops and other hardware to the front line.",
		"Red ATK HELO: Supplement the efforts of our CAS flights destroying enemy ground units."
	}

BRIEFINGS[2]= 
	{
		-- "Blue SEAD: Destroy enemy SAM radars.",
		-- "Blue CAP: Protect our SEAD and CAS flights from enemy fighters.",
		"Blue CAS: Destroy enemy ground units at the front line.",
		"Blue STRIKE: Perform strike on enemy fixed installations.",
		"Blue INTCPT: Intercept inbound enemy strike aircraft.",
		"Blue TRNS HELO: Transport troops and other hardware to the front line.",
		"Blue ATK HELO: Supplement the efforts of our CAS flights destroying enemy ground units."
	}

-- Default...
DEFAULT_MESSAGE = "You do not have an assigned task." 
 
-- Mission aircraft types...
AC_TYPES[1] = 
	{
		"Su-25T",
		"Su-27",
		"Su-25",
		"MiG-29S",
		"MiG-21Bis",
		"Mi-8MT",
		"Ka-50"
	}

AC_TYPES[2] = 
	{
		-- "Su-25T",
		-- "F-15C",
		"A-10C",
		"F-5E-3",
		"M-2000C",
		"UH-1H",
		"SA342M"
	}

local Event_Handler = {}

function Event_Handler:onEvent(_Event)

	if _Event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT then
		if _Event.initiator then
			local player_unit = _Event.initiator
			local player_type = player_unit:getTypeName()
			local player_coalition = player_unit:getCoalition()
			local player_name = player_unit:getPlayerName()
			local player_group = player_unit:getGroup()
			local player_group_ID = player_group:getID()
			local message = "nil"
			local i = 1
			
			while player_type ~= AC_TYPES[player_coalition][i] do
				i = i + 1
				-- if i > NUMBER_OF_TASKS then
				if i > NUMBER_OF_TASKS[player_coalition] then
					message = string.format("%s%s %s", player_name, ".", DEFAULT_MESSAGE)
					trigger.action.outTextForGroup(player_group_ID, message, 15, true)
					break
				end
			end
			
			if player_type == AC_TYPES[player_coalition][i] then
				message = string.format("%s%s %s", player_name, ", your Task is:", BRIEFINGS[player_coalition][i])
				trigger.action.outTextForGroup(player_group_ID, message, 15, true)
			end
		end
	end
end

world.addEventHandler(Event_Handler)

That would be all.

Please Log in or Create an account to join the conversation.

8 years 3 months ago
Cygon_Parrot
New Member
New Member
Posts: 1
More
Hello script? #4877
One very small but useful change done to the above code. With it, you are now no longer restricted to creating an equal number of tasks for red and blue side. The changes are these;
local NUMBER_OF_TASKS = 7 
-- original
-- ..changed to..

local NUMBER_OF_TASKS = {7, 5} 

-- new: NUMBER_OF_TASKS is now a player_coalition dependent array.
if i > NUMBER_OF_TASKS then
-- original
--..changed to..

if i > NUMBER_OF_TASKS[player_coalition] then

-- new: the while loop will now break out as it reaches the value of the player_coalition dependent NUMBER_OF_TASKS.

Think that will make the script more usable and flexible.

Please Log in or Create an account to join the conversation.

Time to create page: 0.088 seconds