On4fox

Car wheel salvage

50 posts in this topic

Nice! I'm going to install your script today. Thanks.

:)

1 person likes this

Share this post


Link to post
Share on other sites
Advertisement
1 hour ago, On4fox said:

Heyho,

I got a small script that lets you salvage wheels from cars.
Its very small.
https://github.com/Onefox/SalvageWheels

Its running perfect with the repair script from John.

Cheers,

Very good idea! :)

I've seen you have a little "left over" within the code that you probably just forgot to remove

Spoiler

_workingWheels = [];
{
    if ((_vehicle getHitPointDamage _x) < 0.2) then
    {    
        _damage = _vehicle getHitPointDamage _x; <<---- this 
        _workingWheels = _workingWheels + [_x];
    };
} forEach _wheels;

also you call the script from within unscheduled environment but use sleep within the script itself:
 

called:

Spoiler

class SalvageWheels: ExileAbstractAction
{
    title = "Salvage Wheels";
    condition = "call ExileClient_object_vehicle_interaction_show";
    action = "_this call Onefox_fnc_salvageWheels";
};

sleep:

Spoiler

    if (("Exile_Item_Foolbox" in _equippedMagazines) && ("Exile_Item_Wrench" in _equippedMagazines) && (_canAdd)) then
    {
        player playMove "AinvPknlMstpSnonWnonDr_medic3";
        sleep 10;
        _vehicle setHitPointDamage [_wheelToSalvage,1];
        player addItem "Exile_Item_CarWheel";
        ["Success",["You have salvage a wheel"]] call ExileClient_gui_notification_event_addNotification;
    };

Also if you have some checks for example here "player needs item x to do this" then sleep then take action, you should make sure if he still has those items after the sleep :P in this case it is "whatever" but within the repair parts script you can start repairing and drop for example the wheel out of the inventory so you don't lose it and tada still repaired (which is why I changed it in the other topic)

 

Please try this instead, I've been looking into your script a bit and added more checks like "is the vehicle still local? (because if you have another player join it during the "10 seconds sleep" it would simply not remove the wheel from the vehicle as it will become local to the other player.

And a few other things, just look at this please:

 

Spoiler

/*
	License: WTFPL <-- ?? what is this?
*/

// functions needed for the script:
FN_GET_WORKING_WHEELS = {
	_hitpoints = getAllHitPointsDamage _vehicle;
	_hitpointnames = _hitpoints select 0;
	_hitpontdamages = _hitpoints select 2;
	_workingwheels = [];
	{
		_hitpoint = toLower _x;
		if!(_hitpoint find "wheel" isEqualTo -1)then
		{
			if(_hitpontdamages select _forEachIndex > 0.2)then
			{
				_workingWheels pushBack _x;
			};
		};
	} forEach _hitpointnames;
	_workingWheels
};

FN_ADD_AND_REMOVE_WHEEL = {
	params[['_vehicle',objNull]];
	if(isNull _vehicle)exitWith
	{
		["RepairFailedWarning", ["No vehicle selected"]] call ExileClient_gui_notification_event_addNotification;
	};
	if(!local _vehicle)exitWith
	{
		["RepairFailedWarning", ["Get in driver first"]] call ExileClient_gui_notification_event_addNotification;
	};
	player playMove "AinvPknlMstpSnonWnonDr_medic3";
	sleep 10;
	
	if(!local _vehicle)exitWith
	{
		["RepairFailedWarning", ["Get in driver first"]] call ExileClient_gui_notification_event_addNotification;
	};
	_workingWheels = _vehicle call FN_GET_WORKING_WHEELS;
	if(_workingWheels isEqualTo [])exitWith
	{
		["RepairFailedWarning", ["The wheels are to damaged"]] call ExileClient_gui_notification_event_addNotification;
	};
	
	_canAdd = [player,"Exile_Item_CarWheel"] call ExileClient_util_playerCargo_canAdd;
	if!(_canAdd)exitWith
	{
		["InventoryFullWarning"] call ExileClient_gui_notification_event_addNotification;
	};
	
	_vehicle setHitPointDamage [_workingWheels select 0,1];
	player addItem "Exile_Item_CarWheel";
	["Success",["You have salvage a wheel"]] call ExileClient_gui_notification_event_addNotification;
};


// real script begins here:
params[['_vehicle',objNull]];
if(isNull _vehicle)exitWith
{
	["RepairFailedWarning", ["No vehicle selected"]] call ExileClient_gui_notification_event_addNotification;
};
if(vehicle player isEqualTo _vehicle)exitWith 
{
	["RepairFailedWarning", ["Get out of the vehicle!"]] call ExileClient_gui_notification_event_addNotification;
};
if(!local _vehicle)exitWith
{
	["RepairFailedWarning", ["Get in driver first"]] call ExileClient_gui_notification_event_addNotification;
};
_workingWheels = _vehicle call FN_GET_WORKING_WHEELS;
if(_workingWheels isEqualTo [])exitWith
{
	["RepairFailedWarning", ["The wheels are to damaged"]] call ExileClient_gui_notification_event_addNotification;
};
if!("Exile_Item_Foolbox" in (magazines player))exitWith
{
	["RepairFailedWarning", ["You need a toolbox"]] call ExileClient_gui_notification_event_addNotification;
};
if!("Exile_Item_Wrench" in (magazines player))exitWith
{
	["RepairFailedWarning", ["You need a wrench"]] call ExileClient_gui_notification_event_addNotification;
};
if(!isNil'salvage_wheel_thread')then{terminate salvage_wheel_thread;salvage_wheel_thread=nil;};
salvage_wheel_thread = _vehicle spawn FN_ADD_AND_REMOVE_WHEEL;
true

 

 

2 people like this

Share this post


Link to post
Share on other sites

Thanks @infiSTAR, when i call the addNotification function without a sleep they are overlap each other and you cant read it :/ so i also need a sleep there right?

Its looking so ugly with that amount of duplicated code. But i guess its just arma...
 

Edited by On4fox

Share this post


Link to post
Share on other sites

Yeah, the 2 big FN_ (functions) you could put into different files and have them compiled first - i just put them there but they are not needed in that particular file (as you probably know)

 

It should only throw one error message, I will edit the post in a few min to make that sure :)

Share this post


Link to post
Share on other sites

jup - hab eben nen update gemacht also meinen alten post editiert

Spoiler

/*
	License: WTFPL <-- ?? what is this?
*/

// functions needed for the script:
FN_GET_WORKING_WHEELS = {
	_hitpoints = getAllHitPointsDamage _vehicle;
	_hitpointnames = _hitpoints select 0;
	_hitpontdamages = _hitpoints select 2;
	_workingwheels = [];
	{
		_hitpoint = toLower _x;
		if!(_hitpoint find "wheel" isEqualTo -1)then
		{
			if(_hitpontdamages select _forEachIndex > 0.2)then
			{
				_workingWheels pushBack _x;
			};
		};
	} forEach _hitpointnames;
	_workingWheels
};

FN_ADD_AND_REMOVE_WHEEL = {
	params[['_vehicle',objNull]];
	if(isNull _vehicle)exitWith
	{
		["RepairFailedWarning", ["No vehicle selected"]] call ExileClient_gui_notification_event_addNotification;
	};
	if(!local _vehicle)exitWith
	{
		["RepairFailedWarning", ["Get in driver first"]] call ExileClient_gui_notification_event_addNotification;
	};
	player playMove "AinvPknlMstpSnonWnonDr_medic3";
	sleep 10;
	
	if(!local _vehicle)exitWith
	{
		["RepairFailedWarning", ["Get in driver first"]] call ExileClient_gui_notification_event_addNotification;
	};
	_workingWheels = _vehicle call FN_GET_WORKING_WHEELS;
	if(_workingWheels isEqualTo [])exitWith
	{
		["RepairFailedWarning", ["The wheels are to damaged"]] call ExileClient_gui_notification_event_addNotification;
	};
	
	_canAdd = [player,"Exile_Item_CarWheel"] call ExileClient_util_playerCargo_canAdd;
	if!(_canAdd)exitWith
	{
		["InventoryFullWarning"] call ExileClient_gui_notification_event_addNotification;
	};
	
	_vehicle setHitPointDamage [_workingWheels select 0,1];
	player addItem "Exile_Item_CarWheel";
	["Success",["You have salvage a wheel"]] call ExileClient_gui_notification_event_addNotification;
};


// real script begins here:
params[['_vehicle',objNull]];
if(isNull _vehicle)exitWith
{
	["RepairFailedWarning", ["No vehicle selected"]] call ExileClient_gui_notification_event_addNotification;
};
if(vehicle player isEqualTo _vehicle)exitWith 
{
	["RepairFailedWarning", ["Get out of the vehicle!"]] call ExileClient_gui_notification_event_addNotification;
};
if(!local _vehicle)exitWith
{
	["RepairFailedWarning", ["Get in driver first"]] call ExileClient_gui_notification_event_addNotification;
};
_workingWheels = _vehicle call FN_GET_WORKING_WHEELS;
if(_workingWheels isEqualTo [])exitWith
{
	["RepairFailedWarning", ["The wheels are to damaged"]] call ExileClient_gui_notification_event_addNotification;
};
if!("Exile_Item_Foolbox" in (magazines player))exitWith
{
	["RepairFailedWarning", ["You need a toolbox"]] call ExileClient_gui_notification_event_addNotification;
};
if!("Exile_Item_Wrench" in (magazines player))exitWith
{
	["RepairFailedWarning", ["You need a wrench"]] call ExileClient_gui_notification_event_addNotification;
};
if(!isNil'salvage_wheel_thread')then{terminate salvage_wheel_thread;salvage_wheel_thread=nil;};
salvage_wheel_thread = _vehicle spawn FN_ADD_AND_REMOVE_WHEEL;
true

 

 

1 person likes this

Share this post


Link to post
Share on other sites
21 minutes ago, infiSTAR said:

It should only throw one error message, I will edit the post in a few min to make that sure :)

But thats the thing, the error messages: 

You need a toolbox and You need a wrench

Should both be displayed.
 

Why? Because its a shitty user experience if you just throw the errors one by one.

If you go to a car try to (in this case) salvage some wheels you get told you need a toolbox, than you go back to your base and get one, than you discover that you also need a Wrench.

Thats the kind of thing i want to reduces.

Share this post


Link to post
Share on other sites

If both is missing it will throw that both is needed and if only one is missing it will show the one that's missing:

 

Spoiler

/*
	License: WTFPL <-- ?? what is this?
*/

// functions needed for the script:
FN_GET_WORKING_WHEELS = {
	_hitpoints = getAllHitPointsDamage _vehicle;
	_hitpointnames = _hitpoints select 0;
	_hitpontdamages = _hitpoints select 2;
	_workingwheels = [];
	{
		_hitpoint = toLower _x;
		if!(_hitpoint find "wheel" isEqualTo -1)then
		{
			if(_hitpontdamages select _forEachIndex > 0.2)then
			{
				_workingWheels pushBack _x;
			};
		};
	} forEach _hitpointnames;
	_workingWheels
};

FN_ADD_AND_REMOVE_WHEEL = {
	params[['_vehicle',objNull]];
	if(isNull _vehicle)exitWith
	{
		["RepairFailedWarning", ["No vehicle selected"]] call ExileClient_gui_notification_event_addNotification;
	};
	if(!local _vehicle)exitWith
	{
		["RepairFailedWarning", ["Get in driver first"]] call ExileClient_gui_notification_event_addNotification;
	};
	player playMove "AinvPknlMstpSnonWnonDr_medic3";
	sleep 10;
	
	if(!local _vehicle)exitWith
	{
		["RepairFailedWarning", ["Get in driver first"]] call ExileClient_gui_notification_event_addNotification;
	};
	_workingWheels = _vehicle call FN_GET_WORKING_WHEELS;
	if(_workingWheels isEqualTo [])exitWith
	{
		["RepairFailedWarning", ["The wheels are to damaged"]] call ExileClient_gui_notification_event_addNotification;
	};
	
	_canAdd = [player,"Exile_Item_CarWheel"] call ExileClient_util_playerCargo_canAdd;
	if!(_canAdd)exitWith
	{
		["InventoryFullWarning"] call ExileClient_gui_notification_event_addNotification;
	};
	
	_vehicle setHitPointDamage [_workingWheels select 0,1];
	player addItem "Exile_Item_CarWheel";
	["Success",["You have salvage a wheel"]] call ExileClient_gui_notification_event_addNotification;
};


// real script begins here:
params[['_vehicle',objNull]];
if(isNull _vehicle)exitWith
{
	["RepairFailedWarning", ["No vehicle selected"]] call ExileClient_gui_notification_event_addNotification;
};
if(vehicle player isEqualTo _vehicle)exitWith 
{
	["RepairFailedWarning", ["Get out of the vehicle!"]] call ExileClient_gui_notification_event_addNotification;
};
if(!local _vehicle)exitWith
{
	["RepairFailedWarning", ["Get in driver first"]] call ExileClient_gui_notification_event_addNotification;
};
_workingWheels = _vehicle call FN_GET_WORKING_WHEELS;
if(_workingWheels isEqualTo [])exitWith
{
	["RepairFailedWarning", ["The wheels are to damaged"]] call ExileClient_gui_notification_event_addNotification;
};

if(!("Exile_Item_Foolbox" in (magazines player))&&!("Exile_Item_Foolbox" in (magazines player)))exitWith
{
	["RepairFailedWarning", ["Toolbox & wrench needed!"]] call ExileClient_gui_notification_event_addNotification;
};
if!("Exile_Item_Foolbox" in (magazines player))exitWith
{
	["RepairFailedWarning", ["You need a toolbox"]] call ExileClient_gui_notification_event_addNotification;
};
if!("Exile_Item_Wrench" in (magazines player))exitWith
{
	["RepairFailedWarning", ["You need a wrench"]] call ExileClient_gui_notification_event_addNotification;
};
if(!isNil'salvage_wheel_thread')then{terminate salvage_wheel_thread;salvage_wheel_thread=nil;};
salvage_wheel_thread = _vehicle spawn FN_ADD_AND_REMOVE_WHEEL;
true

 

 

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.