Skip to content

Commit

Permalink
Add create teleporter module (#122)
Browse files Browse the repository at this point in the history
* Add create teleporter module

* Add docs to modules list

* Apply suggestions from code review

Co-Authored-By: Ralfs Garkaklis <ralfs@garkaklis.com>

* Move event code to function

* Use macro for location icon path
  • Loading branch information
mharis001 authored Aug 17, 2019
1 parent ae94878 commit 58b80af
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 0 deletions.
3 changes: 3 additions & 0 deletions addons/common/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@
<German>Höhe (m)</German>
<Polish>Wysokość (m)</Polish>
</Key>
<Key ID="STR_ZEN_Common_Teleport">
<English>Teleport</English>
</Key>
<Key ID="STR_ZEN_Common_AutoAddObjects">
<English>Add Objects to Curators</English>
<Russian>Сдалвть объекты редактируемыми</Russian>
Expand Down
7 changes: 7 additions & 0 deletions addons/modules/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ class CfgVehicles {
icon = QPATHTOF(ui\target_ca.paa);
portrait = QPATHTOF(ui\target_ca.paa);
};
class GVAR(moduleCreateTeleporter): GVAR(moduleBase) {
curatorCanAttach = 1;
category = QGVAR(Players);
displayName = CSTRING(ModuleCreateTeleporter);
function = QFUNC(moduleCreateTeleporter);
icon = "\a3\3den\data\displays\display3den\panelleft\entitylist_location_ca.paa";
};
class GVAR(moduleDamageBuildings): GVAR(moduleBase) {
category = QGVAR(Buildings);
displayName = CSTRING(ModuleDamageBuildings);
Expand Down
3 changes: 3 additions & 0 deletions addons/modules/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PREP(addTeleporterAction);
PREP(bi_moduleMine);
PREP(compileAircraft);
PREP(compileCAS);
Expand Down Expand Up @@ -32,6 +33,8 @@ PREP(moduleConvoyParameters);
PREP(moduleCreateIED);
PREP(moduleCreateMinefield);
PREP(moduleCreateTarget);
PREP(moduleCreateTeleporter);
PREP(moduleCreateTeleporterServer);
PREP(moduleDamageBuildings);
PREP(moduleEarthquake);
PREP(moduleEditableObjects);
Expand Down
7 changes: 7 additions & 0 deletions addons/modules/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ if (isServer) then {

// Public variable to track created target logics
missionNamespace setVariable [QGVAR(targetLogics), [], true];

// Public variable to track created teleporter objects
missionNamespace setVariable [QGVAR(teleporters), [], true];

[QGVAR(moduleCreateTeleporter), LINKFUNC(moduleCreateTeleporterServer)] call CBA_fnc_addEventHandler;
};

[QGVAR(addTeleporterAction), LINKFUNC(addTeleporterAction)] call CBA_fnc_addEventHandler;

[QGVAR(sayMessage), BIS_fnc_sayMessage] call CBA_fnc_addEventHandler;
[QGVAR(carrierInit), BIS_fnc_Carrier01Init] call CBA_fnc_addEventHandler;
[QGVAR(destroyerInit), BIS_fnc_Destroyer01Init] call CBA_fnc_addEventHandler;
Expand Down
1 change: 1 addition & 0 deletions addons/modules/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CfgPatches {
QGVAR(moduleCreateIED),
QGVAR(moduleCreateMinefield),
QGVAR(moduleCreateTarget),
QGVAR(moduleCreateTeleporter),
QGVAR(moduleDamageBuildings),
QGVAR(moduleEarthquake),
QGVAR(moduleEditableObjects),
Expand Down
67 changes: 67 additions & 0 deletions addons/modules/functions/fnc_addTeleporterAction.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Adds a teleporter action to the given object.
*
* Arguments:
* 0: Teleporter <OBJECT>
*
* Return Value:
* None
*
* Example:
* [cursorObject] call zen_modules_fnc_addTeleporterAction
*
* Public: No
*/

params ["_object"];

private _actionID = _object addAction [
"",
{
params ["_target"];

private _names = [];
private _objects = [];

{
_x params ["_object", "_name"];

if (_object != _target) then {
_names pushBack _name;
_objects pushBack _object;
};
} forEach GVAR(teleporters);

[ELSTRING(common,Teleport), [
["LIST", "str_dn_locations", [_objects, _names, 0], true]
], {
params ["_values"];
_values params ["_object"];

// Exit if the object was deleted after opening the menu
// Otherwise the unit will be teleported to [0, 0, 0]
if (isNull _object) exitWith {};

private _unit = call CBA_fnc_currentUnit;

// Attempt to move unit into the object if it is a vehicle
if (_unit moveInAny _object) exitWith {};

// Move unit near the object if the object is not a vehicle or is full
_unit setVehiclePosition [_object, [], 0, "NONE"];
}] call EFUNC(dialog,create);
},
nil,
100,
true,
true,
"",
QUOTE(!(GVAR(teleporters) select {_x select 0 != _target} isEqualTo [])),
10
];

private _text = format ["<t color='#FFFFFF'>%1</t>", localize ELSTRING(common,Teleport)];
private _picture = format ["<img image='%1' size='1.75' /><br />%2", ICON_LOCATION, _text];
_object setUserActionText [_actionID, _text, "", _picture];
33 changes: 33 additions & 0 deletions addons/modules/functions/fnc_moduleCreateTeleporter.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Zeus module function to create a teleporter.
*
* Arguments:
* 0: Logic <OBJECT>
*
* Return Value:
* None
*
* Example:
* [LOGIC] call zen_modules_fnc_moduleCreateTeleporter
*
* Public: No
*/

params ["_logic"];

private _object = attachedTo _logic;
private _position = getPosATL _logic;

[LSTRING(ModuleCreateTeleporter), [
["EDIT", "STR_3DEN_Object_Attribute_UnitName_displayName", _position call BIS_fnc_locationDescription, true]
], {
params ["_values", "_args"];
_values params ["_name"];
_args params ["_object", "_position"];

[QGVAR(moduleCreateTeleporter), [_object, _position, _name]] call CBA_fnc_serverEvent;
}, {}, [_object, _position]] call EFUNC(dialog,create);

deleteVehicle _logic;
48 changes: 48 additions & 0 deletions addons/modules/functions/fnc_moduleCreateTeleporterServer.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Zeus module function to create a new teleport location.
*
* Arguments:
* 0: Teleporter <OBJECT>
* 1: Position <ARRAY>
* 2: Name <STRING>
*
* Return Value:
* None
*
* Example:
* [objNull, [0, 0, 0], "Location"] call zen_modules_fnc_moduleCreateTeleporterServer
*
* Public: No
*/

params ["_object", "_position", "_name"];

// Create a flag pole object if an object wasn't given
if (isNull _object) then {
_object = createVehicle ["FlagPole_F", _position, [], 0, "NONE"];
[QEGVAR(common,addObjects), [[_object]]] call CBA_fnc_localEvent;
};

// Add teleport action to new teleporter object
private _jipID = [QGVAR(addTeleporterAction), _object] call CBA_fnc_globalEventJIP;
[_jipID, _object] call CBA_fnc_removeGlobalEventJIP;

// Add EH to remove object from the teleporters list if it is deleted
_object addEventHandler ["Deleted", {
params ["_object"];

private _index = GVAR(teleporters) findIf {
_object isEqualTo (_x select 0);
};

if (_index != -1) then {
GVAR(teleporters) deleteAt _index;
publicVariable QGVAR(teleporters);
};
}];

// Add new teleport location and broadcast the updated list
GVAR(teleporters) pushBack [_object, _name];
publicVariable QGVAR(teleporters);
2 changes: 2 additions & 0 deletions addons/modules/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@

#define ICON_GROUP "\a3\ui_f_curator\data\displays\rscdisplaycurator\modegroups_ca.paa"

#define ICON_LOCATION "\a3\3den\data\displays\display3den\panelleft\locationlist_ca.paa"

#define ICON_BLUFOR QPATHTOEF(common,ui\icon_blufor_ca.paa)
#define ICON_OPFOR QPATHTOEF(common,ui\icon_opfor_ca.paa)
#define ICON_INDEPENDENT QPATHTOEF(common,ui\icon_independent_ca.paa)
Expand Down
3 changes: 3 additions & 0 deletions addons/modules/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,9 @@
<Key ID="STR_ZEN_Modules_ModuleWeather_FogAltitude_Tooltip">
<English>Sets the base altitude of the fog layer, in meters above/below sea level.</English>
</Key>
<Key ID="STR_ZEN_Modules_ModuleCreateTeleporter">
<English>Create Teleporter</English>
</Key>
<!-- Module Categories -->
<Key ID="STR_ZEN_Modules_AI">
<English>AI</English>
Expand Down
6 changes: 6 additions & 0 deletions docs/modules_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ The mine density option affects the spacing of the mines from: Very Low = 30 m t

!> Caution should be used when using a large area with a high mine density.

## Create Teleporter

Creates a teleport location at the attached object or, if not attached, at a newly created flag pole.
Players can use the "Teleport" action on any teleporter objects to teleport between them.
When used on a vehicle, players will first be teleported into an empty seat if possible.

## Damage Buildings

Sets the damaged state of the nearest building to the module or all buildings within the given radius, depending on the selected mode.
Expand Down

0 comments on commit 58b80af

Please sign in to comment.