Skip to content

Commit

Permalink
#393 - Placeables (v1.1.0!)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scarso327 committed Nov 21, 2023
1 parent 45f5cd8 commit b5aa1e1
Show file tree
Hide file tree
Showing 18 changed files with 247 additions and 74 deletions.
9 changes: 9 additions & 0 deletions Client Side/Framework/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,15 @@ class CfgFunctions {
file = "Functions\Shipwreck";
class onShipwreckSpawn {};
};

class Placeables {
file = "Functions\Placeables";
class placedObjects {};
class placeObject {};
class removeObject {};
class stopPlacement {};
class isPlaceable {};
};
};

class ULP_Functions_UI {
Expand Down
2 changes: 1 addition & 1 deletion Client Side/Framework/Configuration/CfgSettings.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CfgSettings {
developers[] = { "76561198092567307", "76561197971322689" };

framework_version = "1.0.8";
framework_version = "1.1.0";

total_maxWeight = 5;

Expand Down
1 change: 1 addition & 0 deletions Client Side/Framework/Functions/Admin/CfgAdmin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class CfgAdmin {
};
class Camera : Suit {};
class Invis : Camera {};
class RemovePlaceable : Suit {};

// ADMINISTRATOR (L3)
class Teleport {
Expand Down
2 changes: 2 additions & 0 deletions Client Side/Framework/Functions/Events/fn_onGetIn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ if ([] call ULP_fnc_isEscorting) then {

["SecondNature", _unit] call ULP_fnc_activatePerk;

[] call ULP_fnc_stopPlacement;

true
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,7 @@ if ([player, ["Police", "Hato"]] call ULP_fnc_isFaction) then {
}] call ULP_fnc_addEventHandler;

["Incapacitated", {
if !(isNull (missionNamespace getVariable ["ULP_Spike", objNull])) then {
deleteVehicle ULP_Spike;
player removeAction (missionNamespace getVariable ["ULP_SpikePlaceAction", -1]);

ULP_SpikePlaceAction = nil;
ULP_Spike = nil;
};
[] call ULP_fnc_stopPlacement;
}] call ULP_fnc_addEventHandler;

["CommunicationsSeized", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ if (_addActions) then {

if ([player, ["Police", "Hato"]] call ULP_fnc_isFaction) then {
ULP_PlayerActions pushBackUnique (player addAction ["Packup Stinger", {
private _spike = (nearestObjects [player, ["Land_Razorwire_F"], 5] select { !((_x getVariable ["spike_owner", []]) isEqualTo []) }) param [0, objNull];
private _spike = (nearestObjects [player, ["Land_Razorwire_F"], 5] select { !((_x getVariable ["object_owner", []]) isEqualTo []) }) param [0, objNull];
if (isNull _spike) exitWith {};

if (["Stinger", 1, false, true] call ULP_fnc_handleItem) then {
["You have packed up a stinger..."] call ULP_fnc_hint;
deleteVehicle _spike;
};
}, nil, 10, false, false, "", "isNull (objectParent player) && { !([] call ULP_UI_fnc_isProgress) } && { private _spike = (nearestObjects [player, [""Land_Razorwire_F""], 5] select { !((_x getVariable [""spike_owner"", []]) isEqualTo []) }) param [0, objNull]; (!(isNull _spike) && { (damage _spike) isEqualTo 1 })}"]);
}, nil, 10, false, false, "", "isNull (objectParent player) && { !([] call ULP_UI_fnc_isProgress) } && { private _spike = (nearestObjects [player, [""Land_Razorwire_F""], 5] select { !((_x getVariable [""object_owner"", []]) isEqualTo []) }) param [0, objNull]; (!(isNull _spike) && { (damage _spike) isEqualTo 1 })}"]);
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ class CfgInteractions {
};
};

class Placeable {
class Remove {
title = "Remove Placeable";
factions[] = { "Police", "Medic", "Hato", "Civilian" };
onClick = "_this call ULP_fnc_removeObject; closeDialog 0;";
condition = "[player, [""Police"", ""Medic"", ""Hato""]] call ULP_fnc_isFaction || { [] call ULP_fnc_isStaff && { [player] call ULP_fnc_onDuty } && { [""RemovePlaceable"", false] call ULP_fnc_checkPower } }";
};
};

class Person {
class GiveKeys {
title = "Give Keys";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ private _typeOf = typeOf _object;
(_typeOf call BIS_fnc_objectType) params ["", "_type"];

private _actions = missionConfigFile >> "CfgInteractions" >> (switch (true) do {
case ([_object] call ULP_fnc_isPlaceable): { "Placeable" };
case ([getNumber (missionConfigFile >> "CfgVehicles" >> _typeOf >> "isHouse")] call ULP_fnc_bool): { "HouseStorage" };
case (_typeOf isEqualTo "Land_MoneyBills_01_stack_F" && { (_object getVariable ["ULP_MoneyStack", 0]) > 0 }): { "Money" };
case (_typeOf isEqualTo "Land_CargoBox_V1_F"): { "Vault" };
Expand Down
7 changes: 6 additions & 1 deletion Client Side/Framework/Functions/Items/CfgVirtualItems.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ class CfgVirtualItems {
blueprints[] = { { "Tools", "B_MakeshiftStinger" } };
materials[] = { {"SteelBar", 22} };
};
class Events { onUse = "[] call ULP_fnc_spikeStrip;"; };
class Events { onUse = "_this call ULP_fnc_spikeStrip;"; };
conditions = "true";
};
class MakeshiftStinger : Stinger {
Expand Down Expand Up @@ -788,6 +788,7 @@ class CfgVirtualItems {
isEventItem = false;
isSystemItem = false;
};
class Events { onUse = "[""TapeSign"", _this select 0] call ULP_fnc_placeObject;"; };
conditions = "true";
};
class PlasticBarrier_02_yellow_F : TapeSign_F {
Expand Down Expand Up @@ -833,23 +834,27 @@ class CfgVirtualItems {
sellPrice = 0;
weight = 2;
class Settings : Settings {};
class Events { onUse = "[""RoadCone"", _this select 0] call ULP_fnc_placeObject;"; };
};
class RoadCone_L_F : RoadCone_F {
displayName = "Road Cone (Light)";
class Settings : Settings {};
class Events { onUse = "[""RoadConeWithLight"", _this select 0] call ULP_fnc_placeObject;"; };
};
class Land_PortableLight_single_F : TapeSign_F {
displayName = "Portable Light (Single)";
icon = "Data\Icons\portableLight.paa";
buyPrice = 0;
sellPrice = 0;
class Settings : Settings {};
class Events { onUse = "[""SinglePortableLight"", _this select 0] call ULP_fnc_placeObject;"; };
};
class Land_PortableLight_double_F : Land_PortableLight_single_F {
displayName = "Portable Light (Double)";
buyPrice = 0;
sellPrice = 0;
class Settings : Settings {};
class Events { onUse = "[""DoublePortableLight"", _this select 0] call ULP_fnc_placeObject;"; };
};
class TargetP_Inf4_F : TapeSign_F {
displayName = "Pop-Up Target (Hostile)";
Expand Down
50 changes: 2 additions & 48 deletions Client Side/Framework/Functions/Items/Scripts/fn_spikeStrip.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,6 @@
#include "..\..\..\script_macros.hpp"
scopeName "fn_spikeStrip";

if !(isNull (objectParent player)) exitWith {
["You must be outside of a vehicle..."] call ULP_fnc_hint;
};
_this params [ ["_item", "", [""]] ];

if !(isNull (missionNamespace getVariable ["ULP_Spike", objNull])) exitWith {
["You must place your current stringer before you can place another..."] call ULP_fnc_hint;
};

private _spike = createVehicle ["Land_Razorwire_F", [0, 0, 0]];
_spike attachTo [player, [0, 5.5, 0]];
_spike setDir 90;
_spike setVariable ["spike_owner", [getPlayerUID player, profileName], true];

ULP_Spike = _spike;

ULP_SpikePlaceAction = player addAction ["Place Stinger", {
_this params ["", "", "_actionId"];

private _spike = missionNamespace getVariable ["ULP_Spike", objNull];
player removeAction _actionId;

if (isNull _spike) exitWith {
["An error occured while attempting to place this stringer..."] call ULP_fnc_hint;
};

["Placing Stringer", 2, [_spike], { !(isNull (_this select 0)) && { (["Stinger"] call ULP_fnc_hasItem) > 0 } }, {
_this params [ "_spike" ];

if (isNull _spike) exitWith {};

if !(["Stinger", 1, true] call ULP_fnc_handleItem) exitWith {
deleteVehicle _spike;
};

detach _spike;

private _pos = getPosATL _spike;
_pos set[2, 0];

_spike setPosATL _pos;
_spike setVectorUp surfaceNormal _pos;
_spike setDamage 1;

[_spike] remoteExecCall ["ULP_SRV_fnc_registerStinger", RSERV];

["You have placed a stinger..."] call ULP_fnc_hint;
ULP_Spike = nil;
}, { deleteVehicle (_this select 0); }, ["GRAB", "CROUCH"]] call ULP_UI_fnc_startProgress;
}, nil, 10, false, false, "", "!(isNull (missionNamespace getVariable [""ULP_Spike"", objNull]))"];
["SpikeStrip", _item] call ULP_fnc_placeObject;
41 changes: 41 additions & 0 deletions Client Side/Framework/Functions/Placeables/CfgPlaceables.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class CfgPlaceables {
maxPlaceables = 20;

class Objects {
class SpikeStrip {
displayName = "Stinger";
className = "Land_Razorwire_F";
positioning[] = { { 0, 5.5, 0 }, 90 };
placementTime = 2;
onPlaced = "(_this select 0) setDamage 1; _this remoteExecCall [""ULP_SRV_fnc_registerStinger"", 2];";
};

class RoadCone {
displayName = "Road Cone";
className = "RoadCone_F";
positioning[] = { { 0, 3, 0.5 }, 0 };
placementTime = 2;
onPlaced = "";
};

class RoadConeWithLight : RoadCone {
displayName = "Road Cone With Light";
className = "RoadCone_L_F";
};

class SinglePortableLight : RoadCone {
displayName = "Portable Light (Single)";
className = "Land_PortableLight_single_F";
};

class DoublePortableLight : RoadCone {
displayName = "Portable Light (Double)";
className = "Land_PortableLight_double_F";
};

class TapeSign : RoadCone {
displayName = "Red-White Tape";
className = "TapeSign_F";
};
};
};
10 changes: 10 additions & 0 deletions Client Side/Framework/Functions/Placeables/fn_isPlaceable.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
** Author: Jack "Scarso" Farhall
** Description: Returns count of all objects placed by a certain player
*/
#include "..\..\script_macros.hpp"
scopeName "fn_isPlaceable";

private _object = _this param [0, objNull, [objNull]];

!(isNull _object && { isNil { _object getVariable "object_owner" } })
91 changes: 91 additions & 0 deletions Client Side/Framework/Functions/Placeables/fn_placeObject.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
** Author: Jack "Scarso" Farhall
** Description:
*/
#include "..\..\script_macros.hpp"
scopeName "fn_placeObject";

if (canSuspend) exitWith { _this call ULP_fnc_placeObject; };

_this params [
["_placeable", "", [""]],
["_item", "", [""]]
];

private _cfg = missionConfigFile >> "CfgPlaceables" >> "Objects" >> _placeable;
if !(isClass _cfg) exitWith { false };

if !(isNull (objectParent player)) exitWith {
["You must be outside of a vehicle..."] call ULP_fnc_hint;
false
};

if !(isNull (missionNamespace getVariable ["ULP_PlaceableObject", objNull])) exitWith {
["You must place your current object before you can place another..."] call ULP_fnc_hint;
false
};

private _maxPlaceables = getNumber (missionConfigFile >> "CfgPlaceables" >> "maxPlaceables");
if (([] call ULP_fnc_placedObjects) >= _maxPlaceables) exitWith {
[format ["You've got %1 objects still active, please delete some to place more...", _maxPlaceables]] call ULP_fnc_hint;
false
};

// Ensure no ui is open for this step
[] spawn ULP_UI_fnc_closeDialogs;

[{ !dialog }, [_cfg, _item], {
_this params [ "_cfg", "_item" ];

private _className = getText(_cfg >> "className");
private _positioning = getArray(_cfg >> "positioning") params [
"_attachPoint", "_rot"
];

private _object = createVehicle [_className, [0, 0, 0]];
_object attachTo [player, _attachPoint];
_object setDir _rot;
_object setVariable ["object_owner", [getPlayerUID player, profileName], true];

ULP_PlaceableObject = _object;

ULP_PlaceableObjectAction = player addAction [format ["Place %1", getText(_cfg >> "displayName")], {
_this params ["", "", "_actionId", "_params"];
_params params [ "_cfg", "_item" ];

private _object = missionNamespace getVariable ["ULP_PlaceableObject", objNull];
player removeAction _actionId;

if (isNull _object) exitWith {
["An error occured while attempting to place this object..."] call ULP_fnc_hint;
};

[format ["Placing %1", getText(_cfg >> "displayName")], getNumber(_cfg >> "placementTime"),
[_object, _item, _cfg], { !(isNull (_this select 0)) && { ([(_this select 1)] call ULP_fnc_hasItem) > 0 } }, {
_this params [ "_object", "_item", "_cfg" ];

if (isNull _object) exitWith {};

if !([_item, 1, true] call ULP_fnc_handleItem) exitWith {
deleteVehicle _object;
};

detach _object;

private _pos = getPosATL _object;
_pos set[2, 0];

_object setPosATL _pos;
_object setVectorUp surfaceNormal _pos;

[_object] call compile getText(_cfg >> "onPlaced");

[format["You have placed a %1...", getText(_cfg >> "displayName")]] call ULP_fnc_hint;
[false] call ULP_fnc_stopPlacement;
}, {
[] call ULP_fnc_stopPlacement;
}, ["GRAB", "CROUCH"]] call ULP_UI_fnc_startProgress;
}, [_cfg, _item], 10, false, false, "", "!(isNull (missionNamespace getVariable [""ULP_PlaceableObject"", objNull]))"];
}] call ULP_fnc_waitUntilExecute;

true
15 changes: 15 additions & 0 deletions Client Side/Framework/Functions/Placeables/fn_placedObjects.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
** Author: Jack "Scarso" Farhall
** Description: Returns count of all objects placed by a certain player
*/
#include "..\..\script_macros.hpp"
scopeName "fn_placedObjects";

_this params [
["_steamId", getPlayerUID player, [""]]
];

if (_steamId isEqualTo "") exitWith { 0 };

// Semi-Intensive - Will be a good idea to look into alternatives but only runs once when initially placing an objects so not high prio
count (vehicles select { ((_x getVariable ["object_owner", [""]]) param [0, "", [""]]) isEqualTo _steamId })
19 changes: 19 additions & 0 deletions Client Side/Framework/Functions/Placeables/fn_removeObject.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
** Author: Jack "Scarso" Farhall
** Description:
*/
#include "..\..\script_macros.hpp"
scopeName "fn_removeObject";

if (canSuspend) exitWith {
[ULP_fnc_removeObject, _this] call ULP_fnc_directCall;
};

_this params [
["_object", objNull, [objNull]]
];

if !([_object] call ULP_fnc_isPlaceable) exitWith { false };

deleteVehicle _object;
true
Loading

0 comments on commit b5aa1e1

Please sign in to comment.