Redbeard_Actual

Vehicle Hotwire Custom Codes

1 post in this topic

I have never quite liked the fact that Knives are so rare on the EXILE Server. With all those tasty critters roaming around, it is really hard to take advantage of when you have no way of gutting them. I've always felt the Hunting aspect of the game should be a little bit more accessible.

Therefore I have done what any good critic would do. I wrote some code of my own.

What the heck does this do?

Simple, it changes the object needed to Hot Wire a Vehicle from the Knife to the Mobile Phone. In addition, it checks the Players Score and adjusts the Fail Chance and Duration of the Hot Wire attempt accordingly.

This is the Rough Draft of what I have hacked together and gotten to work on my server so far. Had to get some bare bones working before I flesh it out further with more tool checks. Because I want it to take more than just the Mobile Phone to Hot Wire.

That sounds AMAZING. How did you do it?

You are going to need to add these files to your mission PBO. I personally add a custom/code/server and custom/code/client folder structure to my mission PBO in order to contain said files.

custom/code/client/ExileClient_action_execute.sqf

Spoiler

/**
 * ExileClient_action_execute
 *
 * 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["_actionName", "_parameters", "_progress", "_actionConfig", "_duration", "_durationFunction", "_failChance", "_animation", "_animationType", "_conditionFunction", "_abortInCombatMode", "_startTime", "_sleepDuration", "_failAt", "_errorMessage", "_keyDownHandle", "_mouseButtonDownHandle", "_display", "_label", "_progressBarBackground", "_progressBarMaxSize", "_progressBar", "_function", "_progressBarColor"];
disableSerialization;
if (ExileClientActionDelayShown) exitWith { false };
ExileClientActionDelayShown = true;
ExileClientActionDelayAbort = false;
_actionName = _this select 0;
_parameters = _this select 1;
_progress = 0;
_actionConfig = configFile >> "CfgExileDelayedActions" >> _actionName;
_durationFunction = getText (_actionConfig >> "durationFunction");

// CUSTOM SHIT START!!!
if (_actionName isEqualTo "HotwireVehicle") then {
	if (ExileClientPlayerScore >= 270000) then {
		_duration = 60;
		_failChance = 45;
	} else {
		if (ExileClientPlayerScore >= 90000) then {
			_duration = 120;
			_failChance = 60;
		} else {
			if (ExileClientPlayerScore >= 30000) then {
				_duration = getNumber (_actionConfig >> "duration");
				_failChance = 75;
			} else {
				_duration = getNumber (_actionConfig >> "duration");
				_failChance = 95;
			};
		};
	};	
} else {
	_duration = getNumber (_actionConfig >> "duration");
	_failChance = getNumber (_actionConfig >> "failChance");
};
// CUSTOM SHIT END!!!

_animation = getText (_actionConfig >> "animation");
_animationType = getText (_actionConfig >> "animationType");
_conditionFunction = getText (_actionConfig >> "conditionFunction");
_abortInCombatMode = (getText (_actionConfig >> "abortInCombatMode")) isEqualTo 1;
_startTime = diag_tickTime;
_sleepDuration = _duration / 100;
_failAt = diag_tickTime + 99999;
_errorMessage = "";
if !(_conditionFunction isEqualTo "") then 
{
	_errorMessage = _parameters call (missionNameSpace getVariable [_conditionFunction,{}]);
};
if !(_errorMessage isEqualTo "") exitWith
{
	ExileClientActionDelayShown = false;
	["ErrorTitleAndText", ["Whoops!", _errorMessage]] call ExileClient_gui_toaster_addTemplateToast;
};
if !(_durationFunction isEqualTo "") then 
{
    _duration = _parameters call (missionNameSpace getVariable [_durationFunction,{}]);
};
if ((floor (random 100)) < _failChance) then 
{
	_failAt = _startTime + _duration * (0.5 + (random 0.5));
};
("ExileActionProgressLayer" call BIS_fnc_rscLayer) cutRsc ["RscExileActionProgress", "PLAIN", 1, false];
_keyDownHandle = (findDisplay 46) displayAddEventHandler ["KeyDown","_this call ExileClient_action_event_onKeyDown"];
_mouseButtonDownHandle = (findDisplay 46) displayAddEventHandler ["MouseButtonDown","_this call ExileClient_action_event_onMouseButtonDown"];
_display = uiNamespace getVariable "RscExileActionProgress";   
_label = _display displayCtrl 4002;
_label ctrlSetText "0%";
_progressBarBackground = _display displayCtrl 4001;  
_progressBarMaxSize = ctrlPosition _progressBarBackground;
_progressBar = _display displayCtrl 4000;  
_progressBar ctrlSetPosition [_progressBarMaxSize select 0, _progressBarMaxSize select 1, 0, _progressBarMaxSize select 3];
_progressBar ctrlSetBackgroundColor [0, 0.78, 0.93, 1];
_progressBar ctrlCommit 0;
_progressBar ctrlSetPosition _progressBarMaxSize; 
_progressBar ctrlCommit _duration;
if !(_animation isEqualTo "") then 
{
	if (_animationType isEqualTo "switchMove") then 
	{
		player switchMove _animation;
		["switchMoveRequest", [netId player, _animation]] call ExileClient_system_network_send;
	}
	else 
	{
		player playMoveNow _animation;
	};
};
try
{
	while {_progress < 1} do 
	{
		if (diag_tickTime >= _failAt) then 
		{
			throw 1;
		};
		if (ExileClientActionDelayAbort) then 
		{
			throw 2;
		};
		if (ExileClientPlayerIsInCombat) then 
		{
			if (_abortInCombatMode) then 
			{
				throw 2;
			};
		};
		if !(alive player) then 
		{
			throw 2;
		};
		uiSleep _sleepDuration; 
		_progress = ((diag_tickTime - _startTime) / _duration) min 1;
		_label ctrlSetText format["%1%2", round (_progress * 100), "%"];
	};
	_errorMessage = "";
	if !(_conditionFunction isEqualTo "") then 
	{
		_errorMessage = _parameters call (missionNameSpace getVariable [_conditionFunction,{}]);
	};
	if !(_errorMessage isEqualTo "") exitWith
	{
		["ErrorTitleAndText", ["Whoops!", _errorMessage]] call ExileClient_gui_toaster_addTemplateToast;
		throw 2;
	};
	throw 0;
}
catch
{
	_function = "";
	_progressBarColor = [];
	switch (_exception) do 
	{
		case 0: 	
		{ 
			_function = getText (_actionConfig >> "completedFunction"); 
			_progressBarColor = [0.7, 0.93, 0, 1];
		};
		case 2: 	
		{ 
			_function = getText (_actionConfig >> "abortedFunction"); 
			_progressBarColor = [0.82, 0.82, 0.82, 1];
		};
		case 1:  	
		{ 
			_function = getText (_actionConfig >> "failedFunction"); 
			_progressBarColor = [0.91, 0, 0, 1];
		};
	};
	_progressBar ctrlSetBackgroundColor _progressBarColor;
	if !(_function isEqualTo "") then 
	{
		_parameters call (missionNameSpace getVariable [_function,{}]);
	};
	if !(_animation isEqualTo "") then 
	{
		player switchMove "";
		["switchMoveRequest", [netId player, ""]] call ExileClient_system_network_send;
	};
	_progressBar ctrlSetPosition _progressBarMaxSize;
	_progressBar ctrlCommit 0;
};
("ExileActionProgressLayer" call BIS_fnc_rscLayer) cutFadeOut 2; 
(findDisplay 46) displayRemoveEventHandler ["KeyDown", _keyDownHandle];
(findDisplay 46) displayRemoveEventHandler ["MouseButtonDown", _mouseButtonDownHandle];
ExileClientActionDelayShown = false;
ExileClientActionDelayAbort = false;

 

custom/code/client/ExileClient_action_hotwireVehicle_condition.sqf

Spoiler

/**
 * ExileClient_action_hotwireVehicle_condition
 *
 * 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["_vehicle", "_result"];
_vehicle = _this;
_result = "";
try 
{
	if (ExilePlayerInSafezone) then
	{
		throw "You are in a safe zone!";
	};
	if (ExileClientPlayerIsInCombat) then
	{
		throw "You are in combat!";
	};
	switch (locked _vehicle) do 
	{
		case 0:	{ throw "Vehicle is not locked!"; };
		case 1:	{ throw "Vehicle does not have a lock!"; };
	};
	if !("Exile_Item_Knife" in (magazines player)) then
	{
		throw "You need a Knife to pry the code panel!";
	};
	if !("Exile_Item_Pliers" in (magazines player)) then
	{
		throw "You need Pliers to expose the wires!";
	};
	if !("Exile_Item_MobilePhone" in (magazines player)) then
	{
		throw "You need a Mobile Phone to bypass the Lock!";
	};
	if ((_vehicle distance player) > 7) then 
	{
		throw "You are too far away!";
	};
}
catch 
{
	_result = _exception;
};
_result

 

custom/code/client/ExileClient_action_hotwireVehicle_failed.sqf

Spoiler

/**
 * ExileClient_action_hotwireVehicle_failed
 *
 * 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 ["_breakIt"];
_breakIt = selectRandom ["Exile_Item_MobilePhone","Exile_Item_MobilePhone","Exile_Item_MobilePhone","Exile_Item_MobilePhone","Exile_Item_MobilePhone","Exile_Item_MobilePhone","Exile_Item_Knife","Exile_Item_Knife"];
player removeItem _breakIt;

switch (_breakIt) do {
    case "Exile_Item_MobilePhone": ["ErrorTitleOnly", ["Your Mobile Phone Broke Bitch!"]] call ExileClient_gui_toaster_addTemplateToast;
    case "Exile_Item_Knife": ["ErrorTitleOnly", ["Your Knife Broke Bitch!"]] call ExileClient_gui_toaster_addTemplateToast;
};

 

custom/code/server/ExileServer_object_lock_network_hotwireLockRequest.sqf

Spoiler

/**
 * ExileServer_object_lock_network_hotwireLockRequest
 *
 * 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", "_object", "_player"];
_sessionID = _this select 0;
_parameters = _this select 1;
try 
{
	_object = objectFromNetId (_parameters select 0);
	if (isNull _object) then 
	{
		throw "Vehicle object is null."; 
	};
	_player = _sessionID call ExileServer_system_session_getPlayerObject;
	if (isNull _player) then 
	{
		throw "Player is null."; 
	};
	if ((_player distance _object) > 10) then 
	{
		throw "You are too far away."; 
	};
	if !("Exile_Item_Knife" in (magazines player)) then
	{
		throw "You need a Knife to pry the code panel!";
	};
	if !("Exile_Item_Pliers" in (magazines player)) then
	{
		throw "You need Pliers to expose the wires!";
	};
	if !("Exile_Item_MobilePhone" in (magazines _player)) then 
	{
		throw "You do not have a Mobile Phone."; 
	};
	if (isNumber(configFile >> "CfgVehicles" >> typeOf _object >> "exileIsLockable")) then
	{
		_object setVariable ["ExileIsLocked", 0, true];
	}
	else
	{
		if (local _object) then
		{
			_object lock 0;
		}
		else
		{
			[owner _object, "hotwireLockRequest", [netId _object]] call ExileServer_system_network_send_to;
		};
		_object setVariable ["ExileIsLocked", 0];
		_object call ExileServer_system_vehicleSaveQueue_addVehicle;
	};
	_object enableRopeAttach true;
	_object setVariable ["ExileLastLockToggleAt", time];
	_object setVariable ["ExileAccessDenied", false];
	_object setVariable ["ExileAccessDeniedExpiresAt", 0];
	[_sessionID, "toastRequest", ["SuccessTitleOnly", ["Vehicle hotwired!"]]] call ExileServer_system_network_send_to;
}
catch 
{
	[_sessionID, "toastRequest", ["ErrorTitleAndText", ["Failed to hotwire!", _exception]]] call ExileServer_system_network_send_to;
};

 

And Last but not least, you must add these lines to the CfgExileCustomCode area of your mission config.cpp

Spoiler

class CfgExileCustomCode 
{
	/*
		You can overwrite every single file of our code without touching it.
		To do that, add the function name you want to overwrite plus the 
		path to your custom file here. If you wonder how this works, have a
		look at our bootstrap/fn_preInit.sqf function.

		Simply add the following scheme here:

		<Function Name of Exile> = "<New File Name>";

		Example:

		ExileClient_util_fusRoDah = "myaddon\myfunction.sqf";
	*/
     ExileClient_action_hotwireVehicle_condition = "custom\code\client\ExileClient_action_hotwireVehicle_condition.sqf";
	ExileClient_action_hotwireVehicle_failed = "custom\code\client\ExileClient_action_hotwireVehicle_failed.sqf";
	ExileServer_object_lock_network_hotwireLockRequest = "custom\code\server\ExileServer_object_lock_network_hotwireLockRequest.sqf";
	ExileClient_action_execute = "custom\code\client\ExileClient_action_execute.sqf";
};

 

Thanks for checking it out!

Feel free to make suggestions and let me know what you think.

Edited by Redbeard_Actual
I added some of the code I was talking about in the original post.
  • Like 2

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.