Jump to content

Recommended Posts

Hey men,
I'm just starting with scripting in SQF. I've scripted some easy things like an air raid speaker with switches and stuff. Now, I want to implement a squawk code system for air traffic control.

Here's my idea: You get in a plane and ask for clearance to take off. The ATC gives you a squawk code. To set your squawk code, you type "#squawk" followed by the code in the chat. The ATC and other aircrafts will see your code as a movable marker on the map. It will display your squawk code, altitude, heading, and speed.
My Problems:
1.: I can set a marker with a #squawk command. and if I write somethink like #squawk 2121 I'll get a feedback from the system - but it sets my code to 'scalar' - so i thought, I'll force it to lower. then I'll get 'any'. When I type letters like #squawk Alpha I'll get an error. So the script recognizes the characters after the command.
2.: My Marker doesnt update its position. and I'll get no informations next to the marker like heading, speed etc.To be honest, I'm quite exhausted at the moment. However, I don't think I can come up with a solution quickly. Does anyone have any ideas on what might be causing it? Thank you in advance for your help!

CBA, ACE and so on are active btw.

// define chat cmd #squawk
["squawk", {
    // Check if the player is sitting in an airplane
    if (!(vehicle player isKindOf "Air")) exitWith {
        hint "You need to be in an airplane to change the transponder.";
    };

    // Retrieve the entered transponder code from the chat command
    private _transponderCode = parseNumber (_this select 1) ;

    // Set the transponder code of the aircraft.
    vehicle player setVariable ["transponderCode", _transponderCode, true];

    // Update the map marker with the new transponder code.
    private _marker = vehicle player getVariable ["marker", objNull];
    if (!isNull _marker) then {
        _marker setMarkerText format ["Squawk: %1", _transponderCode];
    } else {
        // Create a new map marker if none exists.
        private _markerPos = position vehicle player;
        private _markerName = format ["Squawk Marker (%1)", name vehicle player];
        _marker = createMarker [_markerName, _markerPos];
        _marker setMarkerType "mil_dot";
        _marker setMarkerColor "ColorRed";
        _marker setMarkerText format ["Squawk: %1", _transponderCode];
        vehicle player setVariable ["marker", _marker, true];
    };

    hint format ["Transponder code set to %1.", _transponderCode];
}] call CBA_fnc_registerChatCommand;
// Function to update the map marker.
_updateMarker = {
    private _marker = vehicle player getVariable ["marker", objNull];
    if (!isNull _marker) then {
        _marker setMarkerPos position vehicle player;
        _marker setMarkerText format ["Squawk: %1\nSpeed: %2 km/h\nAltitude: %3 m\nHeading: %4", 
            vehicle player getVariable ["transponderCode", 0],
            round (speed vehicle player * 3.6), // Conversion from m/s to km/h.
            getPosASL vehicle player select 2,
            vehicle player getDir
        ];
    };
};

// Update the map marker every 2 seconds.
0.1 spawn {
    while {true} do {
        _updateMarker;
        sleep 2;
    };
};

 

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×