PDA

View Full Version : Take-off/landing script to generate HUD msg - will it work?



ATAG_Ezzie
Oct-18-2014, 18:28
Hi,

Bolox et al have been assisting me re getting going re scripting in a couple of threads in this forum. But rather than continue to hijack Salmo's random weather thread I've created this thread in which I've loaded my first go at developing a script. I would have first tested this in FMB but unfortunately my PC is not letting me use it (should be fixed mid-week hopefully) so thought i would post it here and get advice on how it looks. And then once my PC is back working give it a go and see what happens.

In order to to test my understanding I'm going to try and describe what is happening (this might be helpful for other script learners?) and hopefully if i'm wrong someone will kindly point out the errors/misconception. Here goes

(a) Using: This just defines the libraries that will be used by the various script 'commands' contained in the script. These are what COD uses to do its stuff under the hood (noting there are probably various levels of 'under the hood')

(b) AMission: Not exactly sure but this seems to be present on most scripts I've seen. I think it says that what follows is a class/mission called AMission and COD recognises this and reacts according to what the script goes on to do

(c) Listen to events of every mission: Again this seems to be a common line in a lot of scripts i have seen. Not 100% sure but it seems to initialise something that keeps track of all msgs issues by the game and the script then uses these messages to do stuff.

(d) public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft): This line creates a class called OnAircraftTookOff- according to my book a class is bundling of unlike data and functions that belong together in one tidy package. So OnAircraftTookOff is a class and its associated data/functions/parameters are int missionNumber (not sure where this comes from - perhaps generated by the game?), string shortname (again not sure where this variable comes from) and AiAircraft aircraft (huh?). Maybe every time an aircraft takes off it get assigned these variable which is carries with it for the rest of its flight?

(e) base.OnAircraft... This is member of the OnAircraftTookOff class - i think? I'm totally guessing here but am thinking that this says when an aircraft takes off it takes note of the aircraft's details (mission number, short name and aircraft type) - this is where i lose track of what is happening (assuming i knew what was happening before this point)

(f) GamePlay.gpHUDLogCenter. This seems to be the command to generate the HUD message. I'm guessing we have no control over how the HUD message looks and it is displayed for a set time before it goes away (I havent seen anything that says 'display HUD message for a certain time before removing it - but maybe there is a way to do this?).

So I'm hoping the above says that when an aircraft takes off a HUD msg is generated saying 'Nice take off'. And i'm thinking that everytime an aircraft takes off it creates a public class called onAircraftTakeOff with a set of unique identifiers - mission name, shortname and aircraft type)?

Like i said above ordinarily i would have tested this to see if it works (pretty good chance it wont) but because of my PC issues i wasnt able to. But I'm hoping that because its a relatively simple (for an experienced coder - there is no such thing as a simple script for me yet) script then someone will be able to easily correct my thinking/code.

Thanks in advance for any assistance.

Ezzie



using System;
using System.Collections;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;



public class Mission:AMission
{
//Listen to events of every mission
public override void Init(maddox.game.ABattle battle, int missionNumber)
{
base.Init(battle, missionNumber);
MissionNumberListener = -1; //Listen to events of every mission
}

//Generation of HUD msg on take off

public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftTookOff(missionNumber, shortName, aircraft);

GamePlay.gpHUDLogCenter("Nice take-off");
}

//generation of HUD msg on landing

public override void OnAircraftLanded (int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftLanded(missionNumber, shortName, aircraft);

GamePlay.gpHUDLogCenter("Nice landing");
}
}

Salmo
Oct-18-2014, 19:22
Well done Ezzie, you got most things OK. Just a few pointers ....


(c) Listen to events of every mission: Again this seems to be a common line in a lot of scripts i have seen. Not 100% sure but it seems to initialise something that keeps track of all msgs issues by the game and the script then uses these messages to do stuff.
Quite right. This line initiates a "C# listener" that will listen (detect) events that happen during the game. Without this line, the only events that your script will detect are those events that are from the mission with the same name as the script.


((d) public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft): This line creates a class called OnAircraftTookOff- according to my book a class is bundling of unlike data and functions that belong together in one tidy package. So OnAircraftTookOff is a class and its associated data/functions/parameters are int missionNumber (not sure where this comes from - perhaps generated by the game?), string shortname (again not sure where this variable comes from) and AiAircraft aircraft (huh?). Maybe every time an aircraft takes off it get assigned these variable which is carries with it for the rest of its flight?
Yes, the OnAircraftTookOff event is fired every time an aircraft takes off, and every time this event fires the game will send you the missionnumber, the shortname of the plane that tookoff, and the aircraft object of the plane that tookoff. You can use these parameters inside the OnAircraftTookOff event to do stuff. eg. you could add after the base. line something like .... GamePlay.gpHUDLogCenter("Nice take-off " + aircraft.Place(0).Name()); which would display on the screen as "Nice take-off Ezzie" if Ezzie was in the pilot's seat (place(0) in the aircraft).


(f) GamePlay.gpHUDLogCenter. This seems to be the command to generate the HUD message. I'm guessing we have no control over how the HUD message looks and it is displayed for a set time before it goes away (I havent seen anything that says 'display HUD message for a certain time before removing it - but maybe there is a way to do this?).
Correct, it's the command to show a HUD message. You do have some control over how the message is displayed. This command has a few different formats, the format you've used is fine for most messages; it displays a message for about 6 seconds to all players in the game.


So I'm hoping the above says that when an aircraft takes off a HUD msg is generated saying 'Nice take off'. And i'm thinking that everytime an aircraft takes off it creates a public class called onAircraftTakeOff with a set of unique identifiers - mission name, shortname and aircraft type)?
Yes & No, your thinking is not quite correct. The public override void OnAircraftTookoff event line means; (public) make this event available to all scripts; (override) override the games built-in OnAircraftTookoff event handler code with this code I'm writing; (void) this code does not return a any values back to where it was called from. A new class is not created perse, just the code is executed every time the event is fired.

Your code is sound & should work OK.



using System;
using System.Collections;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;


public class Mission:AMission
{
//Listen to events of every mission
public override void Init(maddox.game.ABattle battle, int missionNumber)
{
base.Init(battle, missionNumber);
MissionNumberListener = -1; //Listen to events of every mission
}

//Generation of HUD msg on take off

public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftTookOff(missionNumber, shortName, aircraft);

GamePlay.gpHUDLogCenter("Nice take-off");
}

//generation of HUD msg on landing

public override void OnAircraftLanded (int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftLanded(missionNumber, shortName, aircraft);

GamePlay.gpHUDLogCenter("Nice landing");
}
}

ATAG_Ezzie
Oct-18-2014, 19:58
Thanks for the review and comments Salmo.

I'll make sure i get this working in my FMB and then i will try to introduce some new stuff and slowly build on my understanding.

Its very motivating/comforting to know i seem to be on the right path re trying to make sense of this.

Thanks

Ezzie

ATAG_Ezzie
Oct-22-2014, 05:44
Thanks Salmo - it worked!!

Ezzie