LunatiK

Chop wood directly into a truck if one is near

54 posts in this topic

Is someone able and willing to share a script to make this possible?

Or is someone interested with helping me with this in another way cuz i already tested it on my own a lot but cant get it to work.

Share this post


Link to post
Share on other sites
Advertisement

What do you have so far?

Nothing that works, just made this for testing:

ExileServer_object_tree_network_chopTreeRequest

/**
 * Exile Mod
 * www.exilemod.com
 * © 2015 Exile Mod Team
 *
 * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 
 * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
 */
 
private["_sessionId","_parameters","_treeNetId","_tree","_isTree","_treeModelNames","_treeHeight","_newDamage","_treePosition","_spawnRadius","_weaponHolders","_weaponHolder","_weaponHolderPosition"];
_sessionId = _this select 0;
_parameters = _this select 1;
_treeNetId = _parameters select 0;
_tree = objectFromNetId _treeNetId;
if (!isNull _tree) then
{
	_isTree = false;
	_treeModelNames = getArray(configFile >> "CfgInteractionModels" >> "WoodSource" >> "models");
	{
		if !(((str _tree) find _x) isEqualTo -1)exitWith {_isTree = true};
	}
	forEach _treeModelNames;
	if (_isTree) then 
	{
		if (alive _tree) then
		{
			_treeHeight = _tree call ExileClient_util_model_getHeight;
			_treeHeight = _treeHeight max 1; 
			_newDamage = ((damage _tree) + (1 / (floor _treeHeight) )) min 1;
			_tree setDamage _newDamage; 
			if (_newDamage isEqualTo 1) then
			{
				_tree setDamage 999; 
			};
			_treePosition = getPosATL _tree;
			_treePosition set[2, 0];
			_spawnRadius = 3;
			_weaponHolders = nearestObjects[_treePosition, ["GroundWeaponHolder"], _spawnRadius];
			_nearestTruck = (getPosATL _tree) nearEntities[["B_Truck_01_transport_F", "O_Truck_03_transport_F", "C_Van_01_box_F", "I_Truck_02_transport_F", "Exile_Car_Van_Black","Exile_Car_Van_Box_Black", "Exile_Car_Van_Fuel_Black", "Exile_Car_Zamak", "Exile_Car_Tempest", "Exile_Car_HEMMT"], 10];
			_weaponHolder = objNull;
			if ( count _nearestTruck > 0) then
			{
				_truck = _nearestTruck select 0;
				_weaponHolder = _truck;
			};	
			if (_weaponHolders isEqualTo []) then
			{
				_weaponHolderPosition = [_treePosition, _spawnRadius] call ExileClient_util_math_getRandomPositionInCircle;
				_weaponHolderPosition set [2, 0];
				_weaponHolder = createVehicle ["GroundWeaponHolder", _weaponHolderPosition, [], 0, "CAN_COLLIDE"];
				_weaponHolder setPosATL _weaponHolderPosition;
			}
			else 
			{
				_weaponHolder = _weaponHolders select 0;
			};
			_weaponHolder addMagazineCargoGlobal ["Exile_Item_WoodLog", 1];
		};
	};
};
true

 

Share this post


Link to post
Share on other sites

--- replace your ExileServer_object_tree_network_chopTreeRequest.sqf with the below code to enable cutting trees straight into the listed vehicles. You can add or remove any vehicles you want this enabled for. 

Edited by happydayz

Share this post


Link to post
Share on other sites
/**
 * Exile Mod
 * www.exilemod.com
 * © 2015 Exile Mod Team
 *
 * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 
 * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
 */
 
private["_sessionId","_parameters","_treeNetId","_tree","_isTree","_treeModelNames","_treeHeight","_newDamage","_treePosition","_spawnRadius","_weaponHolders","_weaponHolder","_weaponHolderPosition","_truck","_nearestTruck"];
_sessionId = _this select 0;
_parameters = _this select 1;
_treeNetId = _parameters select 0;
_tree = objectFromNetId _treeNetId;
if (!isNull _tree) then
{
	_isTree = false;
	_treeModelNames = getArray(configFile >> "CfgInteractionModels" >> "WoodSource" >> "models");
	{
		if !(((str _tree) find _x) isEqualTo -1)exitWith {_isTree = true};
	}
	forEach _treeModelNames;
	if (_isTree) then 
	{
		if (alive _tree) then
		{
			_treeHeight = _tree call ExileClient_util_model_getHeight;
			_treeHeight = _treeHeight max 1; 
			_newDamage = ((damage _tree) + (1 / (floor _treeHeight) )) min 1;
			_tree setDamage _newDamage; 
			if (_newDamage isEqualTo 1) then
			{
				_tree setDamage 999; 
			};

//modified by happydayz and LunatiK to allow trees to be cut straight into vehicles!

			_nearestTruck = (getPosATL _tree) nearEntities[["B_Truck_01_transport_F", "O_Truck_03_transport_F", "C_Van_01_box_F", "I_Truck_02_transport_F", "Exile_Car_Van_Black","Exile_Car_Van_Box_Black", "Exile_Car_Van_Fuel_Black", "Exile_Car_Zamak", "Exile_Car_Tempest", "Exile_Car_HEMMT"], 10];
			_weaponHolder = objNull;
			_truck = _nearestTruck select 0;
			if ((count _nearestTruck > 0)&&(_truck canAdd "Exile_Item_WoodLog")) then {
			_truck addMagazineCargoGlobal ["Exile_Item_WoodLog", 1];
			} else {
			_treePosition = getPosATL _tree;
			_treePosition set[2, 0];
			_spawnRadius = 3;
			_weaponHolders = nearestObjects[_treePosition, ["GroundWeaponHolder"], _spawnRadius];
			_weaponHolder = objNull;
			if (_weaponHolders isEqualTo []) then
			{
				_weaponHolderPosition = [_treePosition, _spawnRadius] call ExileClient_util_math_getRandomPositionInCircle;
				_weaponHolderPosition set [2, 0];
				_weaponHolder = createVehicle ["GroundWeaponHolder", _weaponHolderPosition, [], 0, "CAN_COLLIDE"];
				_weaponHolder setPosATL _weaponHolderPosition;
			}
			else 
			{
				_weaponHolder = _weaponHolders select 0;
			};
			_weaponHolder addMagazineCargoGlobal ["Exile_Item_WoodLog", 1];
			};
		};
	};
};
true

edited - added in check to see if inventory full before placing in truck - thanks for the reminder nark0t1k!

Edited by happydayz

Share this post


Link to post
Share on other sites


@happydayz

Don't forget to check if(canadd "ITEM") before or the truck can hold more than capacity

Edited by nark0t1k
2 people like this

Share this post


Link to post
Share on other sites


@happydayz

Don't forget to check if(canadd "ITEM") before or the truck can hold more than capacity

Possible to share this? Would like to use it!

Share this post


Link to post
Share on other sites

--- replace your ExileServer_object_tree_network_chopTreeRequest.sqf with the below code to enable cutting trees straight into the listed vehicles. You can add or remove any vehicles you want this enabled for. 

Just made this myself yesterday, i have added a check in my version if weaponholder still is null because you can "dupe" wood when you start without a truck choping a tree, then drive the truck there then it will fill the truck and the weaponholder thats how i stoped this from happening:

if ((count _nearestTruck > 0) && (_weaponHolders isEqualTo [])) then

 

Share this post


Link to post
Share on other sites
Advertisement

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

  • Recently Browsing   0 members

    No registered users viewing this page.