Skip to content

Commit

Permalink
Function for vehicle spawning
Browse files Browse the repository at this point in the history
"If you write it twice, put it in a function"
  • Loading branch information
Wyqer committed May 3, 2018
1 parent 2babeac commit d402f49
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 74 deletions.
27 changes: 4 additions & 23 deletions Missionframework/modules/01_core/fnc/fn_core_spawnPotato.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
File: fn_core_spawnPotato.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2017-05-01
Last Update: 2018-05-01
Last Update: 2018-05-04
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Description:
Expand All @@ -22,34 +22,15 @@
if (isNull KPLIB_core_potato01 || !(alive KPLIB_core_potato01)) then {
// Position for the spawn.
private _spawnPos = getPosATL KPLIB_eden_potatospawn;
// Create Potato 01 at the spawn position with a slight height offset.
KPLIB_core_potato01 = createVehicle [KPLIB_preset_potato, [_spawnPos select 0, _spawnPos select 1, (_spawnPos select 2) + 0.1], [], 0, "NONE"];

// Disable damage handling and simulation.
KPLIB_core_potato01 allowDamage false;
KPLIB_core_potato01 enableSimulationGlobal false;

// Repositioning of Potato 01 to make sure it'll be where it should be.
KPLIB_core_potato01 setDir (getDir KPLIB_eden_potatospawn);
KPLIB_core_potato01 setPosATL [_spawnPos select 0, _spawnPos select 1, (_spawnPos select 2) + 0.1];

// Clear all cargo.
clearWeaponCargoGlobal KPLIB_core_potato01;
clearMagazineCargoGlobal KPLIB_core_potato01;
clearItemCargoGlobal KPLIB_core_potato01;
clearBackpackCargoGlobal KPLIB_core_potato01;
// Create Potato 01 at the spawn position with a slight height offset.
KPLIB_core_potato01 = [KPLIB_preset_potato, [_spawnPos select 0, _spawnPos select 1, (_spawnPos select 2) + 0.1], getDir KPLIB_eden_potatospawn, true] call KPLIB_fnc_core_spawnVehicle;

// Declare as ace medical vehicle (can also be set if ACE is not used)
KPLIB_core_potato01 setVariable ["ace_medical_medicClass", 1, true];

// Add event handler to call this script again if we have a "Potato down". Will run only on the server.
KPLIB_core_potato01 addMPEventHandler ["MPKilled", {if (isServer) then {[] spawn KPLIB_fnc_core_spawnPotato;};}];

// Small delay to prevent issues with activated damage handling and activate the simulation again.
sleep 0.2;
KPLIB_core_potato01 enableSimulationGlobal true;
KPLIB_core_potato01 setDamage 0;
KPLIB_core_potato01 allowDamage true;
KPLIB_core_potato01 addMPEventHandler ["MPKilled", {if (isServer) then {[] call KPLIB_fnc_core_spawnPotato;};}];
};

true
48 changes: 5 additions & 43 deletions Missionframework/modules/01_core/fnc/fn_core_spawnStartVeh.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
File: fn_core_spawnStartVeh.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2017-05-01
Last Update: 2018-05-01
Last Update: 2018-05-03
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Description:
Expand All @@ -23,28 +23,9 @@ for [{_i=0}, {!isNil ("KPLIB_eden_littlebird_" + str _i)}, {_i = _i + 1}] do {
private _spawnPoint = missionNamespace getVariable ("KPLIB_eden_littlebird_" + str _i);
// Current position for the spawn.
private _spawnPos = getPosATL _spawnPoint;
// Vehicle created at the spawn position with a slight height offset.
private _vehicle = createVehicle [KPLIB_preset_addHeli, [_spawnPos select 0, _spawnPos select 1, (_spawnPos select 2) + 0.1], [], 0, "NONE"];

// Disable damage handling and simulation.
_vehicle allowDamage false;
_vehicle enableSimulationGlobal false;

// Repositioning of the vehicle to make sure it'll be where it should be.
_vehicle setDir (getDir _spawnPoint);
_vehicle setPosATL [_spawnPos select 0, _spawnPos select 1, (_spawnPos select 2) + 0.1];

// Clear all cargo of the start vehicle.
clearWeaponCargoGlobal _vehicle;
clearMagazineCargoGlobal _vehicle;
clearItemCargoGlobal _vehicle;
clearBackpackCargoGlobal _vehicle;

// Small delay to prevent issues with activated damage handling and activate the simulation again.
sleep 0.2;
_vehicle enableSimulationGlobal true;
_vehicle setDamage 0;
_vehicle allowDamage true;
// Spawn the vehicle at the spawn position with a slight height offset.
[KPLIB_preset_addHeli, [_spawnPos select 0, _spawnPos select 1, (_spawnPos select 2) + 0.1], getDir _spawnPoint] call KPLIB_fnc_core_spawnVehicle;
};

// Go through the available markers for the rubber dinghy spawn. Adapts to the amount of placed markers.
Expand All @@ -53,28 +34,9 @@ for [{_i=0}, {!isNil ("KPLIB_eden_boat_" + str _i)}, {_i = _i + 1}] do {
private _spawnPoint = missionNamespace getVariable ("KPLIB_eden_boat_" + str _i);
// Current position for the spawn.
private _spawnPos = getPosATL _spawnPoint;
// Vehicle created at the spawn position with a slight height offset.
private _vehicle = createVehicle [KPLIB_preset_addBoat, [_spawnPos select 0, _spawnPos select 1, (_spawnPos select 2) + 0.1], [], 0, "NONE"];

// Disable damage handling and simulation.
_vehicle allowDamage false;
_vehicle enableSimulationGlobal false;

// Repositioning of the vehicle to make sure it'll be where it should be.
_vehicle setDir (getDir _spawnPoint);
_vehicle setPosATL [_spawnPos select 0, _spawnPos select 1, (_spawnPos select 2) + 0.1];

// Clear all cargo of the start vehicle.
clearWeaponCargoGlobal _vehicle;
clearMagazineCargoGlobal _vehicle;
clearItemCargoGlobal _vehicle;
clearBackpackCargoGlobal _vehicle;

// Small delay to prevent issues with activated damage handling and activate the simulation again.
sleep 0.2;
_vehicle enableSimulationGlobal true;
_vehicle setDamage 0;
_vehicle allowDamage true;
// Spawn the vehicle at the spawn position with a slight height offset.
[KPLIB_preset_addBoat, [_spawnPos select 0, _spawnPos select 1, (_spawnPos select 2) + 0.1], getDir _spawnPoint] call KPLIB_fnc_core_spawnVehicle;
};

true
52 changes: 52 additions & 0 deletions Missionframework/modules/01_core/fnc/fn_core_spawnVehicle.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
KPLIB_fnc_core_spawnVehicle
File: fn_core_spawnVehicle.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2017-05-03

This comment has been minimized.

Copy link
@veteran29

veteran29 May 3, 2018

Member

Wrong year I think 😜

This comment has been minimized.

Copy link
@Wyqer

Wyqer May 4, 2018

Author Member

Ups :D

Last Update: 2018-05-03
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Description:
Spawning of a vehicle at given position with given direction.
Parameter(s):
0: STRING - Classname of the vehicle which should be spawned.
1: POSITION - Position ATL where the vehicle should be spawned.
2: NUMBER - OPTIONAL - Heading for the vehicle from 0 to 360. (Default: random direction)
2: BOOL - OPTIONAL - True for return the spawned vehicle as object, false for return only true on success. (Default: false)
Returns:
OBJECT / BOOL - Depends on 3rd parameter. True -> returns object, False -> return true on success.
*/

params ["_classname", "_spawnPos", ["_spawnDir", random 360], ["_returnVeh", false]];

// Return variable
private _return = true;

// Vehicle created at the spawn position with a slight height offset.
private _vehicle = createVehicle [_classname, _spawnPos, [], 0, "CAN_COLLIDE"];

// Disable damage handling and simulation.
_vehicle allowDamage false;
_vehicle enableSimulationGlobal false;

// Repositioning of the vehicle to make sure it'll be where it should be.
_vehicle setDir _spawnDir;
_vehicle setPosATL _spawnPos;

// Clear all cargo of the start vehicle.
clearWeaponCargoGlobal _vehicle;
clearMagazineCargoGlobal _vehicle;
clearItemCargoGlobal _vehicle;
clearBackpackCargoGlobal _vehicle;

// Activate the simulation again.
_vehicle enableSimulationGlobal true;
_vehicle setDamage 0;
_vehicle allowDamage true;

if (_returnVeh) then {_return = _vehicle;};

_return
15 changes: 9 additions & 6 deletions Missionframework/modules/01_core/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
File: functions.hpp
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2017-10-28
Last Update: 2018-01-05
Last Update: 2018-05-04
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Description:
Expand All @@ -29,15 +29,18 @@ class core {
// Start the intro cinematic
class core_intro {};

// Opens the redeploy/spawn dialog
class core_redeploy {};

// The spawn camera sequence
class core_spawnCam {};

// Spawning of the Potato 01 helicopter
class core_spawnPotato {};

// Spawning of the start vehicles
class core_spawnStartVeh {};

// Opens the redeploy/spawn dialog
class core_redeploy {};

// The spawn camera sequence
class core_spawnCam {};
// Spawning of a vehicle at given position with given direction
class core_spawnVehicle {};
};
4 changes: 2 additions & 2 deletions Missionframework/modules/01_core/initModule.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ call compile preprocessFileLineNumbers "modules\01_core\globals.sqf";

// Server section (dedicated and player hosted)
if (isServer) then {
[] spawn KPLIB_fnc_core_spawnStartVeh;
[] spawn KPLIB_fnc_core_spawnPotato;
[] call KPLIB_fnc_core_spawnStartVeh;
[] call KPLIB_fnc_core_spawnPotato;
};

// HC section
Expand Down

0 comments on commit d402f49

Please sign in to comment.