Technical > Editing & Coding

Respawn with captured territory

(1/4) > >>

LeonZ:
Respawn with captured territory

Respawn with captured territory

File edited:

* client\systems\playerMenu\dialog\loadRespawnDialog.sqf
* client\functions\clientCompile.sqf
* client\functions\spawnAction.sqf
* server\default_config.sqf
File added:

* client\functions\spawnOnTerritory.sqf
client\systems\playerMenu\dialog\loadRespawnDialog.sqf

--- Code: ---#define TERRITORY_SPAWN_COOLDOWN (["A3W_territorySpawnCooldown", 5*60] call getPublicVar)

// #L42
_territorySpawnCooldown = TERRITORY_SPAWN_COOLDOWN;

// #L61 - #L78
_setPlayersInfo =
{
private ["_location"];

_location = _this; // spawn beacon object or town marker name
_isBeacon = (typeName _location == "OBJECT");
_friendlyUnits = [];
_friendlyPlayers = 0;
_friendlyNPCs = 0;
_enemyPlayers = 0;
_enemyNPCs = 0;

{
if (alive _x && {_x isKindOf "CAManBase" && {!(_x call A3W_fnc_isUnconscious) && _x inArea _location}}) then
{
if (FRIENDLY_CONDITION) then
{
if (isPlayer _x) then

// #L124 - #L173
_isTerritoryCaptured =
{
private ["_location", "_index"];
_location = _this;
_index = currentTerritoryDetails findIf { (_x select 0) == _location };
_friendlyUnits = [];
_friendlyPlayers = 0;
_friendlyNPCs = 0;
_enemyPlayers = 0;
_enemyNPCs = 0;
{
if (alive _x && {_x isKindOf "CAManBase" && {!(_x call A3W_fnc_isUnconscious) && _x inArea _location}}) then
{
if (FRIENDLY_CONDITION) then
{
if (isPlayer _x) then
{
_friendlyPlayers = _friendlyPlayers + 1;
_friendlyUnits pushBack _x;
}
else
{
_friendlyNPCs = _friendlyNPCs + 1;
};
}
else
{
if (isPlayer _x) then
{
_enemyPlayers = _enemyPlayers + 1;
}
else
{
if (side _x != sideLogic) then
{
_enemyNPCs = _enemyNPCs + 1;
};
};
};
};
} forEach allUnits;

missionNamespace setVariable [format ["%1_friendlyUnits", _location], _friendlyUnits];
missionNamespace setVariable [format ["%1_friendlyPlayers", _location], _friendlyPlayers];
missionNamespace setVariable [format ["%1_friendlyNPCs", _location], _friendlyNPCs];
missionNamespace setVariable [format ["%1_enemyPlayers", _location], _enemyPlayers];
missionNamespace setVariable [format ["%1_enemyNPCs", _location], _enemyNPCs];

(currentTerritoryDetails select _index select 2) == playerSide
};

// #L290 - #L300
if (!isNil "_lastSpawn") then
{
_spawnCooldown = if (["TERRITORY_", _location] call fn_startsWith) then { TERRITORY_SPAWN_COOLDOWN } else { TOWN_SPAWN_COOLDOWN };
_remaining = _spawnCooldown - (diag_tickTime - _lastSpawn);

if (_spawnCooldown > 0 && _remaining > 0) then
{
_textStr = _textStr + format ["[<t color='#ffff00'>%1</t>] ", _remaining call fn_formatTimer];
_cooldown = true;
};
};

// #L345 - #L354
{
_pos = markerPos _location;
if (["TERRITORY_", _location] call fn_startsWith) then
{
_data = [3, _location];
} else
{
_data = [1, _location];
};
};

// #L418
_locType lbAdd "Territories";

// #L427 - #L432
showBeacons = switch (_curSel) do
{
case 0: { "Town" };
case 1: { "Beacon" };
case 2: { "Territory" };
};

// #L447
showBeacons = "Town";

// #L472 Removed 2 lines
// #L474 Removed 1 line

// #L487 - #L495
_territories = [];
{
private "_friendlyPlayers";
_territory = _x select 0;
if (_territory call _isTerritoryCaptured) then
{
_territories pushBack _territory;
};
} forEach (call compile preprocessFileLineNumbers "mapConfig\territories.sqf");

// #L508 - #L510
if (count _towns > 0 && count _beacons == 0 && showBeacons == "Towns") then { _locType lbSetCurSel 0 };
if (count _beacons > 0 && count _towns == 0 && showBeacons == "Beacons") then { _locType lbSetCurSel 1 };
if (count _territories > 0 && count _beacons == 0 && showBeacons == "Territories") then { _locType lbSetCurSel 2 };

// #L514 - #L528
_locations = switch (showBeacons) do
{
case "Town":
{
[_towns, [], {_x call _getPlayerThreshold}, "DESCEND"] call BIS_fnc_sortBy
};
case "Territory":
{
[_territories, [], {_x call _getPlayerThreshold}, "DESCEND"] call BIS_fnc_sortBy
};
case "Beacon":
{
[_beacons, [], {_x call _getBeaconDistance}, "ASCEND", {alive _x}] call BIS_fnc_sortBy
};
};

// #L546 - #L556
_citiesTerritories = call cityList;
_citiesTerritories append (call compile preprocessFileLineNumbers "mapConfig\territories.sqf");
_index = _citiesTerritories findIf { _x select 0 == _location };
if (["TERRITORY_", _location] call fn_startsWith) then
{
_text = _citiesTerritories select _index select 1;
} else
{
_text = _citiesTerritories select _index select 2;
};
_data = str _location;

// #L558 Removed 1 line

// #L587 - #L590
_spawnCooldown = if (["TERRITORY_", _location] call fn_startsWith) then { _territorySpawnCooldown } else { _townSpawnCooldown };
_remaining = _spawnCooldown - (diag_tickTime - _lastSpawn);

if (_spawnCooldown > 0 && _remaining > 0) then
--- End code ---

client\functions\spawnAction.sqf

--- Code: --- switch (_switch) do
{
case 1: { _data call spawnInTown };
case 2: { _data call spawnOnBeacon };
case 3: { _data call spawnOnTerritory }; // skydive
default { _data call spawnRandom };
};
--- End code ---

client\functions\clientCompile.sqf

--- Code: ---spawnOnTerritory = "client\functions\spawnOnTerritory.sqf" call mf_compile;
--- End code ---

server\default_config.sqf

--- Code: ---A3W_territorySpawnCooldown = 2.5*60;
--- End code ---

client\functions\spawnOnTerritory.sqf

--- Code: ---// ******************************************************************************************
// * This project is licensed under the GNU Affero GPL v3. Copyright © 2014 A3Wasteland.com *
// ******************************************************************************************
// @file Version: 1.0
// @file Name: spawnOnTerritory.sqf
// @file Author: Leon

private ["_marker", "_height", "_index", "_territories", "_preload", "_pos", "_rad", "_territoryName", "_notInArea", "_playerPos"];
_marker = _this select 0;
_preload = param [1, false, [false]];

_height = (["A3W_spawnBeaconSpawnHeight", 0] call getPublicVar) max 0;
_territories = (call compile preprocessFileLineNumbers "mapConfig\territories.sqf");
_index = _territories findIf { _x select 0 == _marker };
_rad = selectMax (markerSize _marker);
_territoryName = _territories select _index select 1;

_pos = getMarkerPos _marker;
_playerPos = _pos;
_notInArea = true;
while { _notInArea } do
{
_playerPos = [_pos,5,_rad,1,0,0,0] call findSafePos;
if (_playerPos inArea _marker) then
{
_notInArea = false;
};
};
_playerPos set [2, if (_height < 25) then { 0 } else { _height }];
if (_preload) then { waitUntil {sleep 0.1; preloadCamera _playerPos} };
waitUntil {!isNil "bis_fnc_init" && {bis_fnc_init}};
player setPos _playerPos;

player setVariable [_marker + "_lastSpawn", diag_tickTime];
[player, _marker] remoteExecCall ["A3W_fnc_updateSpawnTimestamp", 2];

respawnDialogActive = false;
closeDialog 0;

_territoryName spawn
{
_territoryName = _this;
sleep 1;

_hour = date select 3;
_mins = date select 4;
["Wasteland", _territoryName, format ["%1:%3%2", _hour, _mins, if (_mins < 10) then {"0"} else {""}]] spawn BIS_fnc_infoText;
};

--- End code ---

leogoss:

GriffinZS:
First: you are genious!  :D

I changed/added small things to fit better to my mission:


Respawn with captured territory
I also changed the height of the spawn from 0 to 1000. Here comes a suggestion to improve the scipt:

Respawn with captured territory
The picture below is when using a halojump script, we have. Maybe it's possible to edit yours?
I tired to add a flyby sound of a chopper but failed. As usual  ;D
Here is the code:


--- Code: ---/*
   File: fn_halo.sqf
   Version: 2.1

   Author(s): cobra4v320 - effects adapted from old halo.sqs, sounds from freesound.org

   Description: HALO jumping (works with AI soldiers). Set the altitude of the HALO, add a chemlight,
   auto open your parachute at 150m, and save your backpack with its contents, then attach a backpack
   to the front of your unit.

   Parameters:
   0: UNIT - (object) the unit that will be doing the HALO
   1: (optional) ALTITUDE  - (number) the altitude where the HALO will start from
   2: (optional) CHEMLIGHT - (boolean) true if the units will use chemlights
   3: (optional) AUTOOPEN -(boolean) true to auto open parachute at 150m
   4: (optional) SAVELOADOUT - (boolean) true to save backpack and its contents, and add a "fake" backpack to the front of the unit.

   Example(s):
   [this] call COB_fnc_HALO
   [this, 4000, true, true, true] call COB_fnc_HALO
*/
//if (!isServer || isDedicated) exitWith {};

//Parameters
private ["_unit","_altitude","_chemLight","_autoOpen","_saveLoadOut"];
_unit          = [_this, 0, objNull, [objNull]] call BIS_fnc_param;
_altitude      = [_this, 1, 3000, [3000]] call BIS_fnc_param;
_chemLight     = [_this, 2, false, [false]] call BIS_fnc_param;
_autoOpen      = [_this, 3, false, [false]] call BIS_fnc_param;
_saveLoadOut = [_this, 4, true, [true]] call BIS_fnc_param;

//Validate parameters
if (isNull _unit) exitWith {"Unit parameter must not be objNull. Accepted: OBJECT" call BIS_fnc_error};
if (_altitude < 500) exitWith {"Altitude is too low for HALO. Accepted: 500 and greater." call BIS_fnc_error};

//create a log entry
["HALO function has started"] call BIS_fnc_log;

//add immersion effects and sound
if (isPlayer _unit) then {
   hint parseText format ["<t size='2' color='#77b300'>%1</t><br/><br/>%2","PARACHUTE","You ordered a parachute. Now click somewhere on the map and enjoy the flight.<br/>The parachute will open automatically at 120 meters."];
   haloed = true;
   haloAtl=_altitude;
   openMap true;
   onMapSingleClick {
       onMapSingleClick "";
       {
           if (!isPlayer _x && local _x && player distance _x < 40) then {
               _x setPos [(_pos select 0)-30+random 60, (_pos select 1)-30+random 60, haloAtl];
               [_x,haloAtl,true,true,true] call COB_Fn_Halo;
           };
       } foreach units player;

       player setPos [(_pos select 0), (_pos select 1), haloAtl];
       haloed = false;
       hint parseText format ["<t size='2' color='#77b300'>%1</t><br/><br/>%2","PARACHUTE","If you want to open your parachute before 120 meters, just press V.<br/>We hope, you enjoyed the service and we'll see you soon again."];
       openMap false;
   };
   waitUntil{!haloed};


   cutText ["", "BLACK FADED",999];
   [_unit] spawn {
       private "_unit";
       _unit = _this select 0;

       sleep 1;

       "dynamicBlur" ppEffectEnable true;   
       "dynamicBlur" ppEffectAdjust [6];   
       "dynamicBlur" ppEffectCommit 0;     
       "dynamicBlur" ppEffectAdjust [0.0]; 
       "dynamicBlur" ppEffectCommit 5; 

       cutText ["", "BLACK IN", 2];

       //private "_heliNear";
       //_heliNear = nearestObjects [_unit, ["helicopter"], 50];
       //if (count _heliNear == 0) then {playSound "C130_exit"};

       while {animationState _unit != "para_pilot" && alive _unit} do {
           //playSound "flapping"; //play flapping sound
           sleep 4.2;
       };
   };
};

//add a chemlight to helmet
if (_chemLight) then {
   [_chemLight,_unit] spawn {
       private ["_chemlight","_unit","_light"];
       _chemLight = _this select 0;
       _unit       = _this select 1;

       _light = "chemlight_red" createVehicle [0,0,0]; //create the chemlight
       if (headgear _unit != "") then {
           _light attachTo [_unit,[-0.07,0.1,0.25],"head"]; //attach light to helmet
           _light setVectorDirAndUp [[0,1,-1],[0,1,0.6]]; //set vector dir and up
       } else {
           _light attachTo [_unit,[0,-0.07,0.06],"LeftShoulder"];
       };

       waitUntil {animationState _unit == "para_pilot"};

       if (headgear _unit != "") then {
           _light attachTo [vehicle _unit,[0,0.14,0.84],"head"];
           _light setVectorDirAndUp [[0,1,-1],[0,1,0.6]];
       } else {
           _light attachTo [vehicle _unit,[-0.13,-0.09,0.56],"LeftShoulder"]; 
           _light setVectorDirAndUp [[0,0,1],[0,1,0]];
       };

       waitUntil {isTouchingGround _unit || (getPos _unit select 2) < 1};
       detach _light;
       deleteVehicle _light; //delete the chemlight
   };
};

//save the backpack and its contents, also adds fake pack to front of unit
if (_saveLoadOut && !isNull (unitBackpack _unit) && (backpack _unit) != "b_parachute") then {
   private ["_pack","_class","_magazines","_weapons","_items","_helmet"];
   _pack       = unitBackpack _unit;
   _class       = typeOf _pack;
   _magazines = getMagazineCargo _pack;
   _weapons   = getWeaponCargo _pack;
   _items       = getItemCargo _pack;
   _helmet       = headgear _unit;

   removeBackpack _unit; //remove the backpack
   _unit addBackpack "b_parachute"; //add the parachute

   [_unit,_class,_magazines,_weapons,_items,_helmet,_altitude] spawn {
       private ["_unit","_class","_magazines","_weapons","_items","_helmet","_altitude"];
       _unit        = _this select 0;
       _class        = _this select 1;
       _magazines    = _this select 2;
       _weapons     = _this select 3;
       _items         = _this select 4;
       _helmet        = _this select 5;
       _altitude   = _this select 6;

       private "_packHolder";
       _packHolder = createVehicle ["groundWeaponHolder", [0,0,0], [], 0, "can_collide"];
       _packHolder addBackpackCargoGlobal [_class, 1];

       waitUntil {animationState _unit == "HaloFreeFall_non"};
       _packHolder attachTo [_unit,[-0.12,-0.02,-.74],"pelvis"];
       _packHolder setVectorDirAndUp [[0,-1,-0.05],[0,0,-1]];

       waitUntil {animationState _unit == "para_pilot"};
       _packHolder attachTo [vehicle _unit,[-0.07,0.67,-0.13],"pelvis"];
       _packHolder setVectorDirAndUp [[0,-0.2,-1],[0,1,0]];

       waitUntil {isTouchingGround _unit || (getPos _unit select 2) < 1};
       detach _packHolder;
       deleteVehicle _packHolder; //delete the backpack in front

       _unit addBackpack _class; //return the backpack
       clearAllItemsFromBackpack _unit; //clear all gear from new backpack
       if (_altitude > 3040 && _helmet != "" && _helmet != "H_CrewHelmetHeli_B") then {(unitBackpack _unit) addItemCargoGlobal [_helmet, 1]}; //(not complete) do a check to see if there is available space

       for "_i" from 0 to (count (_magazines select 0) - 1) do {
           (unitBackpack _unit) addMagazineCargoGlobal [(_magazines select 0) select _i,(_magazines select 1) select _i]; //return the magazines
       };
       for "_i" from 0 to (count (_weapons select 0) - 1) do {
           (unitBackpack _unit) addWeaponCargoGlobal [(_weapons select 0) select _i,(_weapons select 1) select _i]; //return the weapons
       };
       for "_i" from 0 to (count (_items select 0) - 1) do {
           (unitBackpack _unit) addItemCargoGlobal [(_items select 0) select _i,(_items select 1) select _i]; //return the items
       };
   };
} else {
   if ((backpack _unit) != "b_parachute") then {_unit addBackpack "B_parachute"}; //add the parachute if unit has no backpack
};

if (_altitude > 3040 && (headgear _unit) != "H_CrewHelmetHeli_B") then {_unit addHeadgear "H_CrewHelmetHeli_B"};
_unit setPos [(getPos _unit select 0), (getPos _unit select 1), _altitude]; //Set the altitude of the HALO jump

if (!isPlayer _unit) then {
   _unit allowDamage FALSE; //god mode :)
   _unit switchMove "HaloFreeFall_non"; //place the AI into the free fall animation
   _unit disableAI "ANIM"; //disable the AI animation so they cant switch back to standing
};

if (isPlayer _unit) then {
   [_unit,_autoOpen] spawn {
       private ["_unit","_autoOpen"];
       _unit       = _this select 0;
       _autoOpen = _this select 1;

       if (_autoOpen) then {
           waitUntil {(getPos _unit select 2) < 120 || animationState _unit == "para_pilot" && alive _unit};
           _unit action ["OpenParachute", _unit]; //open parachute if 150m above ground
       };

       waitUntil {animationState _unit == "para_pilot"};

       // Parachute opening effect for more immersion
       //playSound "open_chute"; //play chute opening sound
       setAperture 0.05;
       setAperture -1;
       "DynamicBlur" ppEffectEnable true; 
       "DynamicBlur" ppEffectAdjust [8.0]; 
       "DynamicBlur" ppEffectCommit 0.01;
       sleep 1;
       "DynamicBlur" ppEffectAdjust [0.0];
       "DynamicBlur" ppEffectCommit 3;
       sleep 3;
       "DynamicBlur" ppEffectEnable false;
       "RadialBlur" ppEffectAdjust [0.0, 0.0, 0.0, 0.0];
       "RadialBlur" ppEffectCommit 1.0;
       "RadialBlur" ppEffectEnable false;

       while {(getPos _unit select 2) > 2} do {
           //playSound "para_pilot";
           sleep 4.2;
       };
   };
};

[_unit] spawn {
   private "_unit";
   _unit = _this select 0;

   waitUntil {isTouchingGround _unit || (getPos _unit select 2) < 1 && alive _unit};

   if (!isPlayer _unit) then {
       _unit enableAI "ANIM";  //enable the animations
       _unit setPos [(getPos _unit select 0), (getPos _unit select 1), 0]; //this removes the unit from the parachute
       _unit setVelocity [0,0,0]; //set speed to zero
       _unit setVectorUp [0,0,1]; //set the unit upright
       sleep 1;
       _unit allowDamage TRUE; //allow unit to be damaged again
   } else {   
       // Parachute closing effect for more immersion
       //playSound "close_chute";//play chute closing sound
       cutText ["", "BLACK FADED", 999];
       sleep 2;
       cutText ["", "BLACK IN", 2];

       _unit setDamage 0; //heal the unit to 100% in case of injury
   };
};

//create a log
["HALO function has completed"] call BIS_fnc_log;

//Return Value
_unit; 
--- End code ---

And last: .. one error. When playerside is Blufor or Opfor, all works great. Fantastic! But when Indy players want to us this feature, they don't have the option for territory.

Respawn with captured territory

LeonZ:
First, im not using fn_haloJump,sqf so you gotta connect it somehow, here is the territory spawn solution for the indi player, also available for download below

client\systems\playerMenu\dialog\loadRespawnDialog.sqf line 172 to line 180

--- Code: --- _playerGroup = group player;
_territoryOwner = currentTerritoryDetails select _index select 2;
if (_territoryOwner isEqualType grpNull) then
{
(_playerGroup == _territoryOwner)
} else
{
(playerSide == _territoryOwner)
};
--- End code ---

GriffinZS:
Great!! Gonna test  when I come back from Germany.

Honestly .. this script is a game changer! Now the terries are not only for payout..
Weil done!!  8)

Navigation

[0] Message Index

[#] Next page

Go to full version