Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup Backpacks #2607

Merged
merged 1 commit into from
Sep 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/backpacks/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include "script_component.hpp"

["backpackOpened", DFUNC(backpackOpened)] call EFUNC(common,addEventHandler);
["backpackOpened", {_this call FUNC(backpackOpened)}] call EFUNC(common,addEventHandler);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen you do this in multiple PR's now, and understanding the reason behind this it is a good thing to do.
However I feel like this is fixing the symptoms rather the issue. The issue being, that addEventHandler can only create copies of code, instead of being also be able to reference to existing variables.

Fixing this at the source of the problem might be the better approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look at that. But in a later PR to not cause conflicts now.

19 changes: 10 additions & 9 deletions addons/backpacks/functions/fnc_backpackOpened.sqf
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
/*
* Author: commy2
* Someone opened your backpack. Play sound and camshake. Execute locally.
*
* Someone opened your backpack. Execute locally.
*
* Argument:
* Arguments:
* 0: Who accessed your inventory? (Object)
* 1: Unit that wields the backpack (Object)
* 2: The backpack object (Object)
*
* Return value:
* None.
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
private ["_sounds", "_position"];

params ["_target", "_backpack"];

// do cam shake if the target is the player
if ([_target] call EFUNC(common,isPlayer)) then {
addCamShake [4, 0.5, 5];
};

// play a rustling sound
// play a zipper sound effect
private ["_sounds", "_position"];

_sounds = [
/*"a3\sounds_f\characters\ingame\AinvPknlMstpSlayWpstDnon_medic.wss",
Expand All @@ -32,8 +34,7 @@ _sounds = [
QUOTE(PATHTO_R(sounds\zip_out.wav))
];

_position = _target modelToWorldVisual (_target selectionPosition "Spine3");
_position = _position call EFUNC(common,positionToASL);
_position = AGLToASL (_target modelToWorldVisual (_target selectionPosition "Spine3"));

playSound3D [
_sounds select floor random count _sounds,
Expand Down
15 changes: 8 additions & 7 deletions addons/backpacks/functions/fnc_isBackpack.sqf
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
/*
* Author: commy2
* Check if the given backpack is an actual backpack that can store items. Parachute, static weapon packs, etc. will return false.
*
* Check if the given backpack is an actual backpack that can store items. Parachute backpacks will return false for example.
* Arguments:
* 0: Backpack <OBJECT, STRING>
*
* Argument:
* 0: A backpack (Object or String)
* Return Value:
* Boolean <BOOL>
*
* Return value:
* Boolean (Bool)
* Public: Yes
*/
#include "script_component.hpp"

private ["_config"];
params ["_backpack"];

if (typeName _backpack == "OBJECT") then {
_backpack = typeOf _backpack;
};

private "_config";
_config = configFile >> "CfgVehicles" >> _backpack;

getText (_config >> "vehicleClass") == "backpacks" && {getNumber (_config >> "maximumLoad") > 0}
getText (_config >> "vehicleClass") == "backpacks" && {getNumber (_config >> "maximumLoad") > 0} // return
14 changes: 8 additions & 6 deletions addons/backpacks/functions/fnc_onOpenInventory.sqf
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/*
* Author: commy2
* Handle the open inventory event. Camshake and sound on target client.
*
* Handle the open inventory event. Display message on target client.
* Arguments:
* 0: Unit <OBJECT>
* 1: Backpack <OBJECT>
*
* Argument:
* Input from "InventoryOpened" eventhandler
*
* Return value:
* Return Value:
* false. Always open the inventory dialog. (Bool)
*
* Public: No
*/
#include "script_component.hpp"

params ["_unit","_backpack"];
params ["_unit", "_backpack"];

// exit if the target is not a real backpack, i.e. parachute, static weapon bag etc.
if !([_backpack] call FUNC(isBackpack)) exitWith {false};
Expand Down