Jump to content

[Release] Vehicle Pointer v0.1 (for use w/, w/o Masterkey Script)


jahangir13

Recommended Posts

This is another kind of Vehicle Locator.

Script adds a right-click option to an vehicle key in the gear menu.

The script searches for the vehicle belonging to this key in a near range and marks the vehicle (via sign/light) if found.

If not found in the near range a full map search will be done and if then found a map marker will show where the vehicle is located.
 

Everything is configurable and well documented.

 

The video shows how it works:

https://www.youtube.com/watch?v=FhUoLVYeAK8


The script ( vehicle_pointer.sqf ):

//
// Jahan Vehicle Pointer v0.1 (jahangir13 - 10/2014)
// [email protected]<script type="text/javascript">
/*  */
</script>
// Shows you a vehicle belonging to a key if in 1st search range. If not shows it on map (if allowed via config).
//
private ["_vehDistance","_showMarkerSearchText","_inventoryItems","_rNum""_name","_mark","_showMarkerType","_showMarkerColor","_showMarkerShape","_showMarkerSize","_showMarkerSearchText","_showFlareType","_showFlareOthers","_flare","_light","_showTime","_showMarkerTime","_showSign","_signHeight","_showOthers","_scanRadius","_scanRadius2","_showVehMapMarker","_vehTarget","_arrow","_vehsAround","_keyOwner","_x","_keyName","_ownerID","_vehFoundInRange","_classname","_vehDisplayName","_positionArrow","_location","_inventoryItems"];

//###############################################################################################################################################
// Configuration Options:
//
/////// Sign showing above vehicle
// How long should the sign be shown above the vehicle (in seconds)
_showTime = 5;
// Classname of the sign to show above the car (here red arrow.  Or "testsphere1" ... whatever)
_showSign = "Sign_arrow_down_large_EP1";
// How high above the vehicle the sign shows up (in meters)
_signHeight = 2;
// Shall the sign above the vehicle be seen by others (if false can only be seen by the player)
_showSignOthers = false;
// 1st Range radius to scan for vehicles near the player (should not be too far...as you need to see it) / 2nd range _scanRadius2 for the bigger map marker scan (should cover whole map)
_scanRadius = 80;
_scanRadius2 = 25000;
//
/////// Flare coming down over vehicle (That's for those who like special effects ,) ).
_showFlare = true;
// Show flare to others (false: only player can see the flare)
_showFlareOthers = false;
// The height over map the flare is starting. (The higher the longer it takes to come down.)
_showFlareHeight = 50;
// The type of the flair (classname). Also possible (maybe others too): 
_showFlareType = "F_40mm_White";
//
/////// Marker showing on Map
// Show vehicle on map if nothing was found in first scan doing an extended search (true: show marker on map / false: don't show marker on map)
_showVehMapMarker = true;
// Time the marker stays on the map (in seconds)
_showMarkerTime = 20;
// Color of the map marker ( https://community.bistudio.com/wiki/setMarkerColorLocal )
_showMarkerColor = "ColorRedAlpha"; 
// Type of the map marker (icon on map / E.g.: https://community.bistudio.com/wikidata/images/e/ea/Arma2_markers4.jpg)
_showMarkerType = "Artillery";
// Shape of the marker ( "ICON", "RECTANGLE" or "ELLIPSE" are possible )
_showMarkerShape = "ICON";
// Size of the marker ( Size is in format [a-axis, b-axis]. Depends on which marker type is chosen. )
_showMarkerSize = [3,3];
// Text which shows up behind the marker in the map (after the ': ' the vehicle name is showing.)
_showMarkerSearchText = "Search:";
// Shall the map marker be seen by others (if false can only be seen by the player. Could make some fun if others could see where someone is looking for the vehicle ,) )
_showMarkerOthers = false;
//###############################################################################################################################################

// get key Owner from ui_selectSlot.sqf
_keyOwner = _this select 0;
_keyName = _this select 1;

// variable to remember if vehicle has been found in range
_vehFoundInRange = false;
// The target vehicle which belong to the key
_vehTarget = objNull;

//---------------------------------------------------------------------------------------------------------    
// compare with vehicles around
_vehsAround = nearestObjects [getPos player, ["Plane","LandVehicle","Helicopter","Ship"], _scanRadius];
{
    _ownerID = _x getVariable ["CharacterID", "0"];
    if ( _keyOwner == _ownerID ) exitWith {
        _vehFoundInRange = true; 
        _vehTarget = _x;
    };
} forEach _vehsAround;
//---------------------------------------------------------------------------------------------------------    
    
// if vehicle has been found in range show marker above vehicle
if (_vehFoundInRange) then {
    _classname = typeOf _vehTarget;
    _vehDisplayName = gettext (configFile >> "CfgVehicles" >> (typeof _vehTarget) >> "displayName");
    systemChat format ["VP: %1 belongs to %2 found in range. Trying to mark it...",_keyName, _vehDisplayName];	
    // create the sign which shows up above the target vehicle
    _location = position _vehTarget;
    _positionArrow = _vehTarget modelToWorld [0,0,2];

    // local or globally visible
    if (_showSignOthers) then {
        _arrow = createVehicle [_showSign, _location, [], 0, "NONE"];
        _light = "#lightpoint" createVehicle [0,0,0];
    } else {
        _arrow = _showSign createVehicleLocal _location;
        _light = "#lightpoint" createVehicleLocal [0,0,0];
    };
    _arrow setVehiclePosition [_positionArrow, [], 0];
    _arrow attachTo [_vehTarget,[0,0,_signHeight],""];
            
    // Create a small local white light and attach it to the object.
    if ( _showFlare ) then {
        if ( _showFlareOthers ) then {
            _flare = _showFlareType createVehicle [getPos _vehTarget select 0, getPos _vehTarget select 1, _showFlareHeight];
        } else {
            _flare = _showFlareType createVehicleLocal [getPos _vehTarget select 0, getPos _vehTarget select 1, _showFlareHeight];
        };
    };
    // Create the light effect
    _light setLightBrightness 0.01;
    _light setLightAmbient[1.0, 1.0, 1.0];
    _light setLightColor[1.0, 1.0, 1.0];
    _light lightAttachObject [_vehTarget, [0,0,1]];

    // Show the sign that long above the vehicle
    sleep _showTime;

    // Delete the Sign again
    deleteVehicle _arrow;
    // Turn off the light.
    deletevehicle _light;
    
// if vehicle has not been found in range search in wider range and set marker on map (if config option allows that)    
} else {

    //cutText [format["Key does not belong to any vehicle in range."], "PLAIN DOWN"];
    systemChat format ["JVP: %1 does not belong to any vehicle in range.", _keyName];
    
    // exit if marker config set to 'false'
    if !( _showVehMapMarker ) exitWith { };
    
    // exit if player has no map to see the marker
    _inventoryItems = [player] call BIS_fnc_invString;
    if !("ItemMap" in _inventoryItems) exitWith { systemChat "JVP: You do not have a map to see the marker! Exit.";};
    
    systemChat format ["JVP: Searching for Vehicle in wider range...", _keyName];
    //---------------------------------------------------------------------------------------------------------    
    // Do the bigger search (whole map)
    _vehsAround = nearestObjects [getPos player, ["Plane","LandVehicle","Helicopter","Ship"], _scanRadius2];
    {
        _ownerID = _x getVariable ["CharacterID", "0"];
        if ( _keyOwner == _ownerID ) exitWith {
            _vehFoundInRange = true; 
            _vehTarget = _x;
        };
    } forEach _vehsAround;
    //---------------------------------------------------------------------------------------------------------    
    
    if (_vehFoundInRange) then {
        _classname = typeOf _vehTarget;
        _vehDisplayName = gettext (configFile >> "CfgVehicles" >> (typeof _vehTarget) >> "displayName");
        _vehDistance = floor (player distance _vehTarget);
        systemChat format ["JVP: %1 belongs to %2 found in range. Trying to show on map...",_keyName, _vehDisplayName];
        
        _location = position _vehTarget;
        // Get the vehicle display name from config
        _vehDisplayName = gettext (configFile >> "CfgVehicles" >> (typeof _vehTarget) >> "displayName");
        // Create the map marker: http://forums.bistudio.com/showthread.php?135013-Marker-that-created-with-createMarkerLocal-can-seen-by-everyone
        // random number for map marker name needs to be unique:
        _rNum = floor random 10;
        _name = format ["Search: %1" + " [%2]", _vehDisplayName, _rNum];
        // local or globally visible
        if ( _showMarkerOthers ) then {
            _mark = createMarker [_name, _location];
            _name setMarkerShape _showMarkerShape;
            _name setMarkerType _showMarkerType;
            _name setMarkerColor _showMarkerColor;
            _name setMarkerSize _showMarkerSize;
            _name setMarkerAlpha 1;
            _name setMarkerText format [_showMarkerSearchText + " " + "%1", _vehDisplayName];
            //Marker stays this time on map
        } else {
            _mark = createMarkerLocal [_name, _location];
            _name setMarkerShapeLocal _showMarkerShape;
            _name setMarkerTypeLocal _showMarkerType;
            _name setMarkerColorLocal _showMarkerColor;
            _name setMarkerSizeLocal _showMarkerSize;
            _name setMarkerAlphaLocal 1;
            _name setMarkerTextLocal format [_showMarkerSearchText + " " + "%1" + " " + "[%2 m]", _vehDisplayName, _vehDistance];
        };
        sleep _showMarkerTime;
        // Delete map marker again
        //deleteMarker _name;
        deleteMarker _name;
    } else {
        systemChat format ["JVP: %1 does not belong to any vehicle in big search range.", _keyName];
    };
};


 

Create a file vehicle_pointer.sqf with the content above and place it somewhere in your mission.
 

 

New: The script - Masterkey version ( vehicle_pointer_mk.sqf ):

 

This is a version which works with 1:n relations between key and car(s) (so, 1 master key for several vehicles). If you do not use the Mayterkey mod use the normal vehicle_pointer.sqf.

(As for this version the searches for vehicles cannot be stopped after already finding one (as there could be more for this key) the search always goes over all vehicles available which could cause some longer runtimes the more vehicles are on the map!)

 

//
// Jahan Vehicle Pointer v0.1 - Masterkey mod compatible version (jahangir13 - 11/2014)
// [email protected]
/*  */

// Shows you vehicles belonging to a key if in 1st search range. If not shows them on map (if allowed via config).
//
private ["_markerNames","_i","_j","_arrow1","_arrow2","_arrow3","_arrow4","_arrow5","_light1","_light2","_light3","_light4","_light5","_vehsNearFound","_vehsNearNotFound","_vehDistance","_showMarkerSearchText","_inventoryItems","_rNum""_name","_mark","_showMarkerType","_showMarkerColor","_showMarkerShape","_showMarkerSize","_showMarkerSearchText","_showFlareType","_showFlareOthers","_flare","_light","_showTime","_showMarkerTime","_showSign","_signHeight","_showOthers","_scanRadius","_scanRadius2","_showVehMapMarker","_vehTarget","_arrow","_vehsAround","_keyOwner","_x","_keyName","_ownerID","_vehFoundInRange","_classname","_vehDisplayName","_positionArrow","_location","_inventoryItems"];

//###############################################################################################################################################
// Configuration Options:
//
/////// Sign showing above vehicle
// How long should the sign be shown above the vehicle (in seconds)
_showTime = 5;
// Classname of the sign to show above the car (here red arrow.  Or "testsphere1" ... whatever)
_showSign = "Sign_arrow_down_large_EP1";
// How high above the vehicle the sign shows up (in meters)
_signHeight = 2;
// Shall the sign above the vehicle be seen by others (if false can only be seen by the player)
_showSignOthers = false;
// 1st Range radius to scan for vehicles near the player (should not be too far...as you need to see it) / 2nd range _scanRadius2 for the bigger map marker scan (should cover whole map)
_scanRadius = 80;
_scanRadius2 = 25000;
//
/////// Flare coming down over vehicle (That's for those who like special effects ,) ).
_showFlare = true;
// Show flare to others (false: only player can see the flare)
_showFlareOthers = false;
// The height over map the flare is starting. (The higher the longer it takes to come down.)
_showFlareHeight = 50;
// The type of the flair (classname). Also possible (maybe others too): 
_showFlareType = "F_40mm_White";
//
/////// Marker showing on Map
// Show vehicle on map if nothing was found in first scan doing an extended search (true: show marker on map / false: don't show marker on map)
_showVehMapMarker = true;
// Time the marker stays on the map (in seconds)
_showMarkerTime = 20;
// Color of the map marker ( https://community.bistudio.com/wiki/setMarkerColorLocal )
_showMarkerColor = "ColorRedAlpha"; 
// Type of the map marker (icon on map / E.g.: https://community.bistudio.com/wikidata/images/e/ea/Arma2_markers4.jpg)
_showMarkerType = "Artillery";
// Shape of the marker ( "ICON", "RECTANGLE" or "ELLIPSE" are possible )
_showMarkerShape = "ICON";
// Size of the marker ( Size is in format [a-axis, b-axis]. Depends on which marker type is chosen. )
_showMarkerSize = [3,3];
// Text which shows up behind the marker in the map (after the ': ' the vehicle name is showing.)
_showMarkerSearchText = "Search:";
// Shall the map marker be seen by others (if false can only be seen by the player. Could make some fun if others could see where someone is looking for the vehicle ,) )
_showMarkerOthers = true;
//###############################################################################################################################################

// get key Owner from ui_selectSlot.sqf
_keyOwner = _this select 0;
_keyName = _this select 1;

// variable to remember if vehicle has been found in range
_vehFoundInRange = false;
// The target vehicle which belong to the key
_vehTarget = objNull;

//---------------------------------------------------------------------------------------------------------    
// compare with vehicles around
// array to store vehicles found (could be more than one if masterkey script is used)
systemChat format ["JVP: >>>>>"];
systemChat format ["JVP: Searching for Vehicles in near range..."];
_vehsNearFound = [];
_vehsAround = nearestObjects [getPos player, ["Plane","LandVehicle","Helicopter","Ship"], _scanRadius];
{
    _ownerID = _x getVariable ["CharacterID", "0"];
    if ( _keyOwner == _ownerID ) then {
        _vehFoundInRange = true; 
		_vehsNearFound = _vehsNearFound + [_x];
	};
} forEach _vehsAround;
//---------------------------------------------------------------------------------------------------------    	
    
// if vehicle has been found in range show marker above vehicle
if (_vehFoundInRange) then {
    _i = 0;
	// for all found vehicles in near range
	{
        _vehTarget = _x;
		_classname = typeOf _vehTarget;
		_vehDisplayName = gettext (configFile >> "CfgVehicles" >> (typeof _vehTarget) >> "displayName");
        _i = _i + 1;
		systemChat format ["JVP: %1 belongs to %2 found in range. Mark with Arrow...",_keyName, _vehDisplayName];	
		// create the sign which shows up above the target vehicle
		_location = position _vehTarget;
		_positionArrow = _vehTarget modelToWorld [0,0,2];

		// local or globally visible
		if (_showSignOthers) then {
			_arrow = createVehicle [_showSign, _location, [], 0, "NONE"];
			_light = "#lightpoint" createVehicle [0,0,0];
		} else {
			_arrow = _showSign createVehicleLocal _location;
			_light = "#lightpoint" createVehicleLocal [0,0,0];
		};
        _lightname = format ["light%1", _i];
        _light setVehicleVarName _lightname;
        call compile format["%1 = _light", _lightname];
        _arrowname = format ["arrow%1", _i];
        _arrow setVehicleVarName _arrowname;
        call compile format["%1 = _arrow", _arrowname];
        
        _arrow setVehiclePosition [_positionArrow, [], 0];
	    _arrow attachTo [_vehTarget,[0,0,_signHeight],""];
        
        // Create the light effect
		_light setLightBrightness 0.01;
		_light setLightAmbient[1.0, 1.0, 1.0];
		_light setLightColor[1.0, 1.0, 1.0];
		_light lightAttachObject [_vehTarget, [0,0,1]];
        
		if ( _showFlare ) then {
			if ( _showFlareOthers ) then {
				_flare = _showFlareType createVehicle [getPos _vehTarget select 0, getPos _vehTarget select 1, _showFlareHeight];
			} else {
				_flare = _showFlareType createVehicleLocal [getPos _vehTarget select 0, getPos _vehTarget select 1, _showFlareHeight];
			};
		};

        } forEach _vehsNearFound;
        
        systemChat format ["JVP: <<<<<"];
        
		// Show the sign that long above the vehicle
		sleep _showTime;

		// Delete the Sign again
        for "_j" from 1 to _i do {
            deleteVehicle call compile format ["arrow%1", _j];  
            // Turn off the light.
            deletevehicle call compile format ["light%1", _j];
        };
	
// if vehicle has not been found in range search in wider range and set marker on map (if config option allows that)    
};

///// Marker stuff for vehicles not found in the near range
    
    // exit if marker config set to 'false'
    if !( _showVehMapMarker ) exitWith { };
    
    // exit if no map or gps in the players inventory
    _inventoryItems = [player] call BIS_fnc_invString;
    if ( !("ItemGPS" in _inventoryItems) && !("ItemMap" in _inventoryItems) ) exitWith {systemChat "JVP: You need a Map or GPS to see the markers! Exit.";};
    
    systemChat format ["JVP: Searching for Vehicles in wider range..."];
    //---------------------------------------------------------------------------------------------------------    
    // Do the bigger search (whole map)
    _vehFoundInRange = false; 
    _vehsFarFound = [];
    _vehsAround = nearestObjects [getPos player, ["Plane","LandVehicle","Helicopter","Ship"], _scanRadius2];
    {
        _ownerID = _x getVariable ["CharacterID", "0"];
        if ( _keyOwner == _ownerID ) then {
            _vehFoundInRange = true; 
            _vehsFarFound = _vehsFarFound + [_x];
        };
    } forEach _vehsAround;
    // delete vehicles from array where we've already showed the arrow sign
    _vehsFarFound = _vehsFarFound - _vehsNearFound;
    //---------------------------------------------------------------------------------------------------------    
    
    if (_vehFoundInRange) then {
    
        _markerNames = [];
        _i = 0;
        {
            _i = _i + 1;
            _vehTarget = _x;
            _classname = typeOf _vehTarget;
            _vehDisplayName = gettext (configFile >> "CfgVehicles" >> (typeof _vehTarget) >> "displayName");
            _vehDistance = floor (player distance _vehTarget);
            systemChat format ["JVP: %1 belongs to %2 found in range. Show on map...",_keyName, _vehDisplayName];
        
            _location = position _vehTarget;
            // Get the vehicle display name from config
            _vehDisplayName = gettext (configFile >> "CfgVehicles" >> (typeof _vehTarget) >> "displayName");
            // Create the map marker: http://forums.bistudio.com/showthread.php?135013-Marker-that-created-with-createMarkerLocal-can-seen-by-everyone
            // random number for map marker name needs to be unique:
            _rNum = floor random 10;
            _name = format ["Search: %1" + " [%2]", _vehDisplayName, _rNum];
            // store markername in array
            _markerNames = _markerNames + [_name];
            
            // local or globally visible
            if ( _showMarkerOthers ) then {
                _mark = createMarker [_name, _location];
                _name setMarkerShape _showMarkerShape;
                _name setMarkerType _showMarkerType;
                _name setMarkerColor _showMarkerColor;
                _name setMarkerSize _showMarkerSize;
                _name setMarkerAlpha 1;
                _name setMarkerText format [_showMarkerSearchText + " " + "%1", _vehDisplayName];
                //Marker stays this time on map
            } else {
                _mark = createMarkerLocal [_name, _location];
                _name setMarkerShapeLocal _showMarkerShape;
                _name setMarkerTypeLocal _showMarkerType;
                _name setMarkerColorLocal _showMarkerColor;
                _name setMarkerSizeLocal _showMarkerSize;
                _name setMarkerAlphaLocal 1;
                _name setMarkerTextLocal format [_showMarkerSearchText + " " + "%1" + " " + "[%2 m]", _vehDisplayName, _vehDistance];
            };
        
        } forEach _vehsFarFound;
        
        systemChat format ["JVP: <<<<<"];
        
        sleep _showMarkerTime;
        // Delete map marker again
        {
            deleteMarker _x;
        } forEach _markerNames;
        
    } else {
        systemChat format ["JVP: %1 does not belong to any vehicle in big search range.", _keyName];
        systemChat format ["JVP: <<<<<"];
    };
    

 

Create a file vehicle_pointer_mk.sqf with the content above and place it somewhere in your mission. In ui_selectSlot.sqf you set the path to this script.

 

 

ui_selectSlot.sqf (custom):

 

///// jahan - begin vehicle pointer
        // key colors
        _colors = ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"];
		if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _item)) in _colors) then {
            // characterID of the key (car character number)
			_keyOwner = getNumber(configFile >> "CfgWeapons" >> _item >> "keyid");
            // key name (like: e3f2)
            _keyName = getText(configFile >> "CfgWeapons" >> _item >> "displayName");

            //Menu entry Key vehicle pointer
            _control =  _parent displayCtrl (1600 + _numActions);
            _control ctrlShow true;
            _height = _height + (0.025 * safezoneH);
            // this needs to point the place where the script is in your mission (vehicle_pointer.sqf)
            _script =  "custom\jtools\vehicle_pointer.sqf";
            _exescript = format["_id = ['%2','%3'] execVM '%1';closeDialog 0;",_script,_keyOwner,_keyName];
            uiNamespace setVariable ['uiControl', _control];
            // sets the text in the right button menu
            _control ctrlSetText "Vehicle Pointer";
            _control ctrlSetTextColor [0.3,0.4,1,1];
            _control ctrlSetTooltip "Pinpoint vehicle. Mark on map if not in range.";
            _control ctrlSetTooltipColorBox [0.3,0.4,1,1];
            _control ctrlSetTooltipColorShade [0, 0, 0, 1];
            _control ctrlSetTooltipColorText [0.3,0.4,1,1];
            _control ctrlSetEventHandler ["ButtonClick",_exescript];
            _numActions = _numActions + 1; // if there are other item action after that (other mods) add 1 to _numactions
		};
///// jahan - end vehicle pointer

 

This needs to be added into ui_selectSlot.sqf (you need to make that custom). The path pointing to the script needs to be adjusted!!

If you do not already have any other right click option scripts (or Macas right clickt options method) it would be pasted below:

			_array = 	getArray	(_config >> "output");
			_outputClass = _array select 0;
			_outputType = _array select 1;
			_name = getText (configFile >> _outputType >> _outputClass >> "displayName");
			_compile =  format["_id = ['%2',%3] %1;",_script,_item,_array];
		};
		
		_menu ctrlSetText format[_type,_name];
		_menu ctrlSetEventHandler ["ButtonClick",_compile];
	};

and above this:

	_pos set [3,_height];
	//hint format["Obj: %1 \nHeight: %2\nPos: %3",_item,_height,_grpPos];		

	_group ctrlShow true;
	ctrlSetFocus _group;

If you have other right click content already in ui_selectSlot.sqf then copy it below Maca's right click option (if available) and above other one(s) like Remote Vehicle Door Opener.

 

 

Let me know for any battleye restrictions to add this here. I got no kicks while testing, so you may have different files.

And any feedback is also always welcome.

 

There is an bug with createVehicleLocal for some objects which might spam your RPT log:

https://dev.withsix.com/issues/25648

Link to comment
Share on other sites

It says it requires a map to work, can I make it so you need a map or GPS? I added:

 

if !("ItemGPS" in _inventoryItems) exitWith { systemChat "JVP: You do not have a map to see the marker! Exit.";};

Below:

if !("ItemMap" in _inventoryItems) exitWith { systemChat "JVP: You do not have a map to see the marker! Exit.";};

But it didn't work. Any thoughts?

Link to comment
Share on other sites

Tricks: one of the 2 condition get false and the script exits with exitWith if you don't have both of the 2 items.

 

You would need 1 condition like: if !( ("ItemGPS" in _inventoryItems) && ("ItemMAP" in _inventoryItems) ) exitWith {systemChat "JVP: You either need a map or radio for the marker! Exit.";};

If you negate an OR you get an AND. So if BOTH are not available throw the message.

 

But how should the player see the map marker without map? Or does a GPS 'contain' a map which can be seen by pressing 'M'?

Link to comment
Share on other sites

Works great with Infistar 336D. 

 

I'd like the text to be white when I right click on a key. What do I change to get that?

 

I don't use this but just having a quick look I found what you're looking for.

 _control ctrlSetText "Vehicle Pointer";
 _control ctrlSetTextColor [0.3,0.4,1,1];

Modify the [R,G,B,A] array to suit your need. Values range from 0 to 1, white would be [1,1,1,1].

That's in the 'ui_selectSlot.sqf' file.

Link to comment
Share on other sites

11:03:44   Error Undefined variable in expression: _this
11:03:44 File mpmissions\__cur_mp.chernarus\Scripts\vehicle_pointer.sqf, line 53

 

Where am I doing wrong Do you have any idea? 
thanks
 
ui_selectSlot.sqf

private ["_control","_button","_parent","_group","_pos","_item","_conf","_name","_cfgActions","_numActions","_height","_menu","_config","_type","_script","_outputOriented","_compile","_array","_outputClass","_outputType","_erc_cfgActions", "_erc_numActions"];
disableSerialization;
_control = 	_this select 0;
_button =	_this select 1;
_parent = 	findDisplay 106;

//if ((time - dayzClickTime) < 1) exitWith {};

if (_button == 1) then {
	//dayzClickTime = time;
	_group = _parent displayCtrl 6902;
	
	_pos = 		ctrlPosition _group;
	_pos set [0,((_this select 2) + 0.48)];
	_pos set [1,((_this select 3) + 0.07)];
	
	_item = gearSlotData _control;
	
	_conf = configFile >> "cfgMagazines" >> _item;
	if (!isClass _conf) then {
		_conf = configFile >> "cfgWeapons" >> _item;
	};
	_name = getText(_conf >> "displayName");
	
	_cfgActions = _conf >> "ItemActions";
	_numActions = (count _cfgActions);
	_height = 0;
	
	//Populate Menu
	for "_i" from 0 to (_numActions - 1) do 
	{
		_menu = 	_parent displayCtrl (1600 + _i);
		_menu ctrlShow true;
		_config = 	(_cfgActions select _i);
		_type = 	getText	(_config >> "text");
		_script = 	getText	(_config >> "script");
		_outputOriented = 	getNumber	(_config >> "outputOriented") == 1;
		_height = _height + (0.025 * safezoneH);
		_compile =  format["_id = '%2' %1;",_script,_item];
		uiNamespace setVariable ['uiControl', _control];
		if (_outputOriented) then {
			/*
				This flag means that the action is output oriented
				the output class will then be transferred to the script
				and the type used for the name
			*/			
				_pos set [3,_height];
	//hint format["Obj: %1 \nHeight: %2\nPos: %3",_item,_height,_grpPos];		

	_group ctrlShow true;
	ctrlSetFocus _group;
			
			
			_array = 	getArray	(_config >> "output");
			_outputClass = _array select 0;
			_outputType = _array select 1;
			_name = getText (configFile >> _outputType >> _outputClass >> "displayName");
			_compile =  format["_id = ['%2',%3] %1;",_script,_item,_array];
		};
		
		_menu ctrlSetText format[_type,_name];
		_menu ctrlSetEventHandler ["ButtonClick",_compile];
	};
	
	
	
	// Add extra context menus
	_erc_cfgActions = (missionConfigFile >> "ExtraRc" >> _item);
	_erc_numActions = (count _erc_cfgActions);
	if (isClass _erc_cfgActions) then {
		for "_j" from 0 to (_erc_numActions - 1) do 
		{
			_menu = 	_parent displayCtrl (1600 + _j + _numActions);
			_menu ctrlShow true;
			_config = 	(_erc_cfgActions select _j);
			_text = 	getText	(_config >> "text");
			_script = 	getText	(_config >> "script");
			_height = _height + (0.025 * safezoneH);
			uiNamespace setVariable ['uiControl', _control];
			_menu ctrlSetText _text;
			_menu ctrlSetEventHandler ["ButtonClick",_script];
		};
	};

	_pos set [3,_height];
	//hint format["Obj: %1 \nHeight: %2\nPos: %3",_item,_height,_grpPos];		

	_group ctrlShow true;
	ctrlSetFocus _group;
	_group ctrlSetPosition _pos;
	_group ctrlCommit 0;
};

///// jahan - begin vehicle pointer
        // key colors
        _colors = ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"];
		if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _item)) in _colors) then {
            // characterID of the key (car character number)
			_keyOwner = getNumber(configFile >> "CfgWeapons" >> _item >> "keyid");
            // key name (like: e3f2)
            _keyName = getText(configFile >> "CfgWeapons" >> _item >> "displayName");

            //Menu entry Key vehicle pointer
            _control =  _parent displayCtrl (1600 + _numActions);
            _control ctrlShow true;
            _height = _height + (0.025 * safezoneH);
            // this needs to point the place where the script is in your mission (vehicle_pointer.sqf)
            _script =  "Scripts\vehicle_pointer.sqf";
            _exescript = format["_id = ['%2','%3'] execVM '%1';closeDialog 0;",_script,_keyOwner,_keyName];
            uiNamespace setVariable ['uiControl', _control];
            // sets the text in the right button menu
            _control ctrlSetText "Vehicle Pointer";
            _control ctrlSetTextColor [0.3,0.4,1,1];
            _control ctrlSetTooltip "Pinpoint vehicle. Mark on map if not in range.";
            _control ctrlSetTooltipColorBox [0.3,0.4,1,1];
            _control ctrlSetTooltipColorShade [0, 0, 0, 1];
            _control ctrlSetTooltipColorText [0.3,0.4,1,1];
            _control ctrlSetEventHandler ["ButtonClick",_exescript];
            _numActions = _numActions + 1; // if there are other item action after that (other mods) add 1 to _numactions
		};
///// jahan - end vehicle pointer

Link to comment
Share on other sites

Tricks: one of the 2 condition get false and the script exits with exitWith if you don't have both of the 2 items.

 

You would need 1 condition like: if !( ("ItemGPS" in _inventoryItems) && ("ItemMAP" in _inventoryItems) ) exitWith {systemChat "JVP: You either need a map or radio for the marker! Exit.";};

If you negate an OR you get an AND. So if BOTH are not available throw the message.

 

But how should the player see the map marker without map? Or does a GPS 'contain' a map which can be seen by pressing 'M'?

 

I tried this, but it doesn't work. I have the GPS, but it still says I need a map or a GPS.

Link to comment
Share on other sites

Yes, this was written from my phone. It should just give a hint that 2 lines with exitWith will always leave the script independantly from which of the 2 items you have in your inventory.

So this needs to be handled in 1 condition.

 

The problem here is how it is written. '"ItemXYZ" in _array' takes capitalization into account (but I also tried 5 times now ;)) ).

 

This is the diag_log of _inventoryItems:

"Items: ["ItemCompass","ItemRadio","ItemToolbox","ItemMachete","ItemMatchbox_DZE","MeleeHatchet_DZE","ItemKnife","ItemKeyYellow262","ItemGPS","ItemMap","ItemBandage","ItemBandage","Hatchet_Swing"]"

 

ItemMap is the correct classname. Not ItemMAP.

 

So:

if ( !("ItemGPS" in _inventoryItems) && !("ItemMap" in _inventoryItems) ) exitWith {systemChat "JVP: You either need a map or GPS for the marker! Exit.";};

Link to comment
Share on other sites

Yes, this was written from my phone. It should just give a hint that 2 lines with exitWith will always leave the script independantly from which of the 2 items you have in your inventory.

So this needs to be handled in 1 condition.

 

The problem here is how it is written. '"ItemXYZ" in _array' takes capitalization into account (but I also tried 5 times now ;)) ).

 

This is the diag_log of _inventoryItems:

"Items: ["ItemCompass","ItemRadio","ItemToolbox","ItemMachete","ItemMatchbox_DZE","MeleeHatchet_DZE","ItemKnife","ItemKeyYellow262","ItemGPS","ItemMap","ItemBandage","ItemBandage","Hatchet_Swing"]"

 

ItemMap is the correct classname. Not ItemMAP.

 

So:

if ( !("ItemGPS" in _inventoryItems) && !("ItemMap" in _inventoryItems) ) exitWith {systemChat "JVP: You either need a map or GPS for the marker! Exit.";};

 

Thank you. That worked. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...