Jump to content
Sign in to follow this  
cruoriss

Filer cfgvehicles by side

Recommended Posts

Hey,

So i'm using an AI recruitement script working fine but only listing unit from player faction .

I'm trying to make it filter unit from player side .

Here's the concerned code :

_faction = [format["%1",faction player]];
if ((getText(_Vehicle >> "faction") in _faction)) then .....

_vehicle return the cfgvehicles

Working fine for faction but replacing by side breaks it .

Any idea ?

Thanks

Edited by vinceXD

Share this post


Link to post
Share on other sites

in CfgVehicles vehicle side is defined as an integer.

https://community.bistudio.com/wiki/CfgVehicles_Config_Reference

Maybe this will give you an idea?

Walk up to a vehicle and in debug console execute this.

private ["_object","_className","_vehClass","_pVehSide"];
switch (true) do
{
case (side player == EAST) : {_pVehSide = 0;};
case (side player == WEST) : {_pVehSide = 1;};
case (side player == RESISTANCE) : {_pVehSide = 2;};
case (side player == CIVILIAN) : {_pVehSide = 3;};
};

_object = (nearestObjects [position player, ["LandVehicle","Air"], 5]) select 0;
_className = format["%1", typeOf _object];

if (getNumber(configfile >> "CfgVehicles" >> _className >> "side") == _pVehSide) then
{
hint "Vehicle is on your side";
}
else
{
hint "Vehicle is not on your side";
};

Share this post


Link to post
Share on other sites

Here's how you can filter cfgVehicles. Hope it helps.

//cfgVehicles side filter
private ["_cfg","_sel","_className","_displayName","_scope","_sideVehicle","_sidePlayer","_vehClass"];

_cfg = configFile >> "cfgVehicles";
_sidePlayer = getNumber (_cfg >> typeOf player >> "side");

for "_i" from 0 to (count (_cfg) - 1) do {
   _sel = _cfg select _i;

if (isClass _sel) then {	
	_className = configName _sel;
	_displayName = getText (_sel >> "displayName");
	_sideVehicle = getNumber (_sel >> "side");
	_vehClass = getText (_sel >> "vehicleClass");
	_scope = getNumber (_sel >> "scope");

	if (_scope >= 2 && {_sideVehicle == _sidePlayer}) then {
		diag_log format ["%1", _displayName]; //Print the vehicle's display name to the rpt.
		player sideChat format ["%1", _displayName]; //Print the vehicle's display name in side chat.
       };
};
};

Edited by Iceman77

Share this post


Link to post
Share on other sites
switch (true) do

{

case (side player == EAST) : {_pVehSide = 0;};

case (side player == WEST) : {_pVehSide = 1;};

case (side player == RESISTANCE) : {_pVehSide = 2;};

case (side player == CIVILIAN) : {_pVehSide = 3;};

};

This whole structure can be replaced with

_pVehSide = (side player) call BIS_fnc_sideID;

Uses BIS's side enumerations.

Since V1.24 there is also a new command that will iterate through the specified config and filter stuff based on a condition you give it, much like using a count structure.

filtered = " ( getNumber (_x >> 'side') == (side player) call BIS_fnc_sideID) " configClasses (configFile >>"CfgVehicles");

filtered here will hold a list of classes that match the players side. The filtered list is in config format e.g an index of filtered will look like config.bin/CfgVehicles/ArtilleryTargetW to use it you will need to use configName on each index to change it to a usable type e.g

_filtered = [];
_matchingClasses = " ( getNumber (_x >> 'side') == (side player) call BIS_fnc_sideID) " configClasses (configFile >>"CfgVehicles");
{
_filtered set [count _filtered, configName _x];
}forEach _matchingClasses;

The above is just an example there is no need to forEach through the array just remember that its in config format and when you want to use an index remember to get its actual config name. Again just an example and there may be other things you want to include in the filter condition e.g scope, class type "LandVehicle" or "Man" etc

Edited by Larrow

Share this post


Link to post
Share on other sites

Thanks a lot ,

Don't really know what i was doing but got it to work .

Share this post


Link to post
Share on other sites

Didn't know about the new command/function BIS_fnc_sideID. Short and to the point Larrow. Iceman, good to see you back. Larrow and Iceman you guys are great assets to the community. Three ways to get vehicle config side number and compare them to player side.

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
Sign in to follow this  

×