Jump to content

[Release]Locate Ore Veins Script


_Jack

Recommended Posts

Hey guys, here is a simple script I made that allows players to scan for ore veins. I no longer run arma 2 servers so I decided to release some of the scripts I used!

Hope you find it useful! :)

//Range that it will scan for veins
ScanRange = 1500;

//Get number of each vein within defined range
VeinsCountIron = count ((position player) nearObjects ["Iron_Vein_DZE",ScanRange]);
VeinsCountSilver = count ((position player) nearObjects ["Silver_Vein_DZE",ScanRange]);
VeinsCountGold = count ((position player) nearObjects ["Gold_Vein_DZE",ScanRange]);

//Get total veins
VeinsCountTotal = VeinsCountGold+VeinsCountSilver+VeinsCountIron;

//Display results to player
systemChat format["[IG]Within %1M there are %2 ore veins: %3 Iron, %4 Silver and %5 Gold.",ScanRange,VeinsCountTotal,VeinsCountIron,VeinsCountSilver,VeinsCountGold];

format["[IG]Within %1M there are %2 ore veins: %3 Iron, %4 Silver and %5 Gold.",ScanRange,VeinsCountTotal,VeinsCountIron,VeinsCountSilver,VeinsCountGold] call dayz_rollingMessages;

 

Link to comment
Share on other sites

Thank you for this. Would you happen to have an idea on how to add a General direction such as N,NE,E,SE,S,SW,W,NW or if not then a direction in Degrees Relative?

Such as 1 Silver Vein 140, 1 Iron Vein 224

I am pretty sure it would need to use the following but I really do not know how to implement it.

_dir = [player, object] call BIS_fnc_relativeDirTo;

 

Link to comment
Share on other sites

Could try something similar to this;

_dir = [player, VeinsCountIron] call BIS_fnc_relativeDirTo
systemchat format ["There is %1 Iron vein at %2 on compass",VeinsCountIron,_dir];

Might have to play around with foreach.

Could cause lag if there are a lot of gems nearby though.

Link to comment
Share on other sites

Thank you for the script. Also, its more clearly to use:
- getPosATL instead of position player (getPos), that slower in 1.67 times.
- local variables instead of global.

My variant:

//Range that it will scan for veins
_scanRange = 1500;

//Get number of each vein within defined range
_pos = getPosATL player;
_ironVeins = count (_pos nearObjects ["Iron_Vein_DZE",_scanRange]);
_silverVeins = count (_pos nearObjects ["Silver_Vein_DZE",_scanRange]);
_goldVeins = count (_pos nearObjects ["Gold_Vein_DZE",_scanRange]);

//Get total veins
_total = _ironVeins + _silverVeins + _goldVeins;

//Display results to player
systemChat format["Within %1m there are %2 ore veins: %3 Iron, %4 Silver and %5 Gold.", _scanRange,_total,_ironVeins,_silverVeins,_goldVeins];

If you are using "Deploy Anything" script, its so simple to add script handler on right click on, e.g. map.

DZE_CLICK_ACTIONS = DZE_CLICK_ACTIONS + ["ItemMap","Find Ore Veins","execVM 'scripts\findOreVeins.sqf';","true"];

 

Link to comment
Share on other sites

On 23.08.2017 at 0:57 PM, Zoranth said:

Thank you Ford for the variation. I will give it a try.

I have already added this to my clickactions off of the Compass

Also, what is your take on providing a direction to an ore vein type from player position? Any Ideas?

I modified the script a bit. Now it shows nearest iron, silver and gold ore vines, distance to it and direction too.

E.g.

bcbf449762514528ad233547f474d0b5.jpg

Code:

Spoiler

private ["_ironVeins","_silverVeins","_goldVeins"];

/**
	Config.
*/
_scanRange = 1500; // Scanning range.
_showAllVeines = true; // Show how many each ore vines are in range. E.g. Within 1500m there are 3 Ore Veins: 2 Iron, 0 Silver and 1 Gold.
_showNearestIronOreVine = true; // Show nearest iron ore vine with distance and direction. 
_showNearestSilverOreVine = true;  // Show nearest silver ore vine with distance and direction. 
_showNearestGoldOreVine = true;  // Show nearest gold ore vine with distance and direction. 

_findObj = {
	private ["_class","_pos","_range","_objectsArray","_nearest"];
	_class = _this select 0;
	_pos = _this select 1;
	_range = _this select 2;
	_objectsArray = [];
	_nearest = "";
	
	{
		_objectsArray set [count _objectsArray, _x];
		if (_forEachIndex == 0) then {
			_nearest = _x;
		};
	}
	forEach nearestObjects [_pos, [_class], _scanRange];
	
	[_objectsArray, count _objectsArray, _nearest]
};

_revealNearest = {
	private ["_name","_nearest"];
	_name = _this select 0;
	_nearest = _this select 1;
	
	_degree = round (abs ([player, _nearest] call BIS_fnc_relativeDirTo));
	_distance = floor (player distance _nearest);
	
	_direction = call {
		if ((_degree >= 0 && _degree < 45) || _degree == 360) exitWith { 'North' };
		if (_degree >= 45 && _degree < 90) exitWith { 'NorthEast' };
		if (_degree >= 90 && _degree < 135) exitWith { 'East' };
		if (_degree >= 135 && _degree < 180) exitWith { 'SouthEast' };
		if (_degree >= 180 && _degree < 225) exitWith { 'South' };
		if (_degree >= 225 && _degree < 270) exitWith { 'SouthWest' };
		if (_degree >= 270 && _degree < 315) exitWith { 'West' };
		if (_degree >= 315 && _degree < 360) exitWith { 'NorthWest' };
		"unknown"
	};
	
	systemChat format["Nearest %1 Ore Vein in %2m on the %3.", _name, _distance, _direction];
};

_pos = getPosATL player;

_ironVeins = ["Iron_Vein_DZE", _pos, _scanRange] call _findObj;
_silverVeins = ["Silver_Vein_DZE", _pos, _scanRange] call _findObj;
_goldVeins = ["Gold_Vein_DZE", _pos, _scanRange] call _findObj;

_ironCount = _ironVeins select 1;
_silverCount = _silverVeins select 1;
_goldCount = _goldVeins select 1;

if (_showAllVeines) then {
	_total = _ironCount + _silverCount + _goldCount;
	if (_total > 0) then {
		systemChat format["Within %1m there are %2 Ore Veins: %3 Iron, %4 Silver and %5 Gold.", _scanRange, _total, _ironCount, _silverCount, _goldCount];
	} else {
		systemChat format["Within %1m there are no Ore Vines.", _scanRange];
	};
};
	
if (_showNearestIronOreVine && _ironCount > 0) then {
	["Iron", (_ironVeins select 2)] call _revealNearest;
};
if (_showNearestSilverOreVine && _silverCount > 0) then {
	["Silver", (_silverVeins select 2)] call _revealNearest;
};
if (_showNearestGoldOreVine && _goldCount > 0) then {
	["Gold", (_goldVeins select 2)] call _revealNearest;
};

 

Link to comment
Share on other sites

@Ford

I just tried this and it is showing the direction to the ore vein based on the direction you are facing. For example:

If I am facing true north and the _nearest ore vein is to the east, it will display the ore vein is to the east. However, if I am facing east and the _nearest is to the east, it will display that the ore vein is to the north.

In other words, it is displaying the relative direction based on the direction I am facing instead of true north.

Link to comment
Share on other sites

@Zoranth

Yeah, you are right. I just edited script and used other function to get real direction to object.

Code:

Spoiler

/**
	Config.
*/
_scanRange = 1500; // Scanning range.
_showAllVeines = true; // Show how many each ore vines are in range. E.g. Within 1500m there are 3 Ore Veins: 2 Iron, 0 Silver and 1 Gold.
_showNearestIronOreVine = true; // Show nearest iron ore vine with distance and direction. 
_showNearestSilverOreVine = true;  // Show nearest silver ore vine with distance and direction. 
_showNearestGoldOreVine = true;  // Show nearest gold ore vine with distance and direction. 

_findObj = {
	private ["_class","_pos","_range","_objects","_objCount","_nearest"];
	_class = _this select 0;
	_pos = _this select 1;
	_range = _this select 2;
	_nearest = objNull;
	
	_objects = nearestObjects [_pos, [_class], _scanRange];
	_objCount = count _objects;
	
	if (_objCount > 0) then {
		_nearest = _objects select 0;
	};
	
	[_objCount, _nearest]
};

_revealNearest = {
	private ["_name","_nearest"];
	_name = _this select 0;
	_nearest = _this select 1;
	
	_degree = round ([player, _nearest] call BIS_fnc_dirTo);
	if (_degree < 0 ) then { _degree = 360 + _degree };
	_distance = floor (player distance _nearest);
	
	_direction = call {
		if ((_degree >= 0 && _degree < 45) || _degree == 360) exitWith { 'North' };
		if (_degree >= 45 && _degree < 90) exitWith { 'NorthEast' };
		if (_degree >= 90 && _degree < 135) exitWith { 'East' };
		if (_degree >= 135 && _degree < 180) exitWith { 'SouthEast' };
		if (_degree >= 180 && _degree < 225) exitWith { 'South' };
		if (_degree >= 225 && _degree < 270) exitWith { 'SouthWest' };
		if (_degree >= 270 && _degree < 315) exitWith { 'West' };
		if (_degree >= 315 && _degree < 360) exitWith { 'NorthWest' };
		"unknown"
	};
	
	systemChat format["Nearest %1 Ore Vein in %2m on the %3.", _name, _distance, _direction];
};

_pos = getPosATL player;

_ironVeins = ["Iron_Vein_DZE", _pos, _scanRange] call _findObj;
_silverVeins = ["Silver_Vein_DZE", _pos, _scanRange] call _findObj;
_goldVeins = ["Gold_Vein_DZE", _pos, _scanRange] call _findObj;

_ironCount = _ironVeins select 0;
_silverCount = _silverVeins select 0;
_goldCount = _goldVeins select 0;

if (_showAllVeines) then {
	_total = _ironCount + _silverCount + _goldCount;
	
	if (_total > 0) then {
		systemChat format["Within %1m there are %2 Ore Veins: %3 Iron, %4 Silver and %5 Gold.", _scanRange, _total, _ironCount, _silverCount, _goldCount];
	} else {
		systemChat format["Within %1m there are no Ore Vines.", _scanRange];
	};
};
	
if (_showNearestIronOreVine && _ironCount > 0) then {
	["Iron", (_ironVeins select 1)] call _revealNearest;
};
if (_showNearestSilverOreVine && _silverCount > 0) then {
	["Silver", (_silverVeins select 1)] call _revealNearest;
};
if (_showNearestGoldOreVine && _goldCount > 0) then {
	["Gold", (_goldVeins select 1)] call _revealNearest;
};

 

Link to comment
Share on other sites

@Ford@jack

Thank You, This works Great. and again, Thank You @jack for the original work

For anyone that wants to use actual Compass Directions in Degree's instead of Points of the Compass (otherwise known as a Compass Rose) you can change the following:

Spoiler

    _degree = round ([player, _nearest] call BIS_fnc_dirTo);
    if (_degree < 0 ) then { _degree = 360 + _degree };
    _distance = floor (player distance _nearest);
 //  Remove or Comment out everything from this line   


    _direction = call {
        if ((_degree >= 0 && _degree < 45) || _degree == 360) exitWith { 'North' };
        if (_degree >= 45 && _degree < 90) exitWith { 'NorthEast' };
        if (_degree >= 90 && _degree < 135) exitWith { 'East' };
        if (_degree >= 135 && _degree < 180) exitWith { 'SouthEast' };
        if (_degree >= 180 && _degree < 225) exitWith { 'South' };
        if (_degree >= 225 && _degree < 270) exitWith { 'SouthWest' };
        if (_degree >= 270 && _degree < 315) exitWith { 'West' };
        if (_degree >= 315 && _degree < 360) exitWith { 'NorthWest' };
        "unknown"
    };

 //  To this line 

//  Change this line:


systemChat format["Nearest %1 Ore Vein in %2m on the %3.", _name, _distance, _direction];

//  To this:


systemChat format["Nearest %1 Ore Vein in %2m on heading %3.", _name, _distance, _degree];

 

If you want to change the output from being displayed in System Chat to Rolling Messages that are in the middle of your screen. Do the following:

Spoiler

Change the following line"


systemChat format["Nearest %1 Ore Vein in %2m on the %3.", _name, _distance, _direction];

// To this:


 format["Nearest %1 Ore Vein in %2m on the %3.", _name, _distance, _direction]; call dayz_rollingMessages;

 

You could even have two separate files. One that is activated off of the Map that gives the Points of the Compass (General Direction such as NW, W, SE) to the ore vein. Then have the second file that is activated off of the GPS that  gives the actual relative direction from you to the ore vein.

 

 

Link to comment
Share on other sites

  • 2 years later...
  • 4 weeks later...

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...