Difference between revisions of "Script Snippets"

From ALiVE Wiki
Jump to: navigation, search
(Spawn Group Script By Jman)
(Spawn Group Script By Jman)
Line 18: Line 18:
 
* _group -> String. CfgGroups name  
 
* _group -> String. CfgGroups name  
 
* _faction -> String. CfgGroups faction
 
* _faction -> String. CfgGroups faction
 
+
 
* Optional Params:
 
* Optional Params:
 
* _debug -> Boolean. Enable debug output
 
* _debug -> Boolean. Enable debug output
Line 58: Line 58:
 
if (!isServer) exitWith {};
 
if (!isServer) exitWith {};
 
// ====================================================================================
 
// ====================================================================================
 
+
 
// SCOPE -------------------------------------------------------------------------------------
 
// SCOPE -------------------------------------------------------------------------------------
 
private["_spawnposition","_spawnExactLocation","_destinationPosition","_faction","_profile","_profiles","_profileWaypoint","_group","_debug",
 
private["_spawnposition","_spawnExactLocation","_destinationPosition","_faction","_profile","_profiles","_profileWaypoint","_group","_debug",
 
"_waypointPlacementRadius","_waypointType","_waypointMovement","_waypointCompletionRadius","_waypointTimeoutCounters","_waypointFormation",
 
"_waypointPlacementRadius","_waypointType","_waypointMovement","_waypointCompletionRadius","_waypointTimeoutCounters","_waypointFormation",
"_waypointCombatMode","_waypointBehaviour","_waypointDescription"];
+
"_waypointCombatMode","_waypointBehaviour","_waypointDescription","_groupName", "_groupName","_config"];
 +
_config = [];
 
// SCOPE -------------------------------------------------------------------------------------
 
// SCOPE -------------------------------------------------------------------------------------
 
+
 
waitUntil {!isNil "ALIVE_profileSystemInit"};
 
waitUntil {!isNil "ALIVE_profileSystemInit"};
+
 
// PARMS -------------------------------------------------------------------------------------
 
// PARMS -------------------------------------------------------------------------------------
 
_spawnPosition = _this select 0;
 
_spawnPosition = _this select 0;
Line 75: Line 76:
 
_debug = if(count _this > 5) then {_this select 5} else {false};
 
_debug = if(count _this > 5) then {_this select 5} else {false};
 
_waypointPlacementRadius = if(count _this > 6) then {_this select 6} else {0};
 
_waypointPlacementRadius = if(count _this > 6) then {_this select 6} else {0};
_waypointType = if(count _this > 7) then {_this select 7} else {"Move"}; // NOTE: at the moment only MOVE is supported by the profiler
+
_waypointType = if(count _this > 7) then {_this select 7} else {"Move"};
 
_waypointMovement = if(count _this > 8) then {_this select 8} else {"Full"};
 
_waypointMovement = if(count _this > 8) then {_this select 8} else {"Full"};
 
_waypointCompletionRadius = if(count _this > 9) then {_this select 9} else {0};
 
_waypointCompletionRadius = if(count _this > 9) then {_this select 9} else {0};
Line 84: Line 85:
 
_waypointDescription = if(count _this > 14) then {_this select 14} else {""};
 
_waypointDescription = if(count _this > 14) then {_this select 14} else {""};
 
// PARMS -------------------------------------------------------------------------------------
 
// PARMS -------------------------------------------------------------------------------------
 
+
 
// DEBUG -------------------------------------------------------------------------------------
 
// DEBUG -------------------------------------------------------------------------------------
 
if(_debug) then {
 
if(_debug) then {
  ["ALIVE_spawnProfileGroup-> _spawnPosition: %1, _spawnExactLocation: %2, _destinationPosition: %3, _group: %4, _faction: %5,  
+
  ["ALIVE_spawnProfileGroup -> _spawnPosition: %1, _spawnExactLocation: %2, _destinationPosition: %3, _group: %4, _faction: %5,  
 
  _debug: %6, _waypointPlacementRadius: %7, _waypointType: %8, _waypointMovement: %9, _waypointCompletionRadius: %10,  
 
  _debug: %6, _waypointPlacementRadius: %7, _waypointType: %8, _waypointMovement: %9, _waypointCompletionRadius: %10,  
 
  _waypointTimeoutCounters: %11, _waypointFormation: %12, _waypointCombatMode: %13, _waypointBehaviour: %14,  
 
  _waypointTimeoutCounters: %11, _waypointFormation: %12, _waypointCombatMode: %13, _waypointBehaviour: %14,  
Line 95: Line 96:
 
};
 
};
 
// DEBUG -------------------------------------------------------------------------------------
 
// DEBUG -------------------------------------------------------------------------------------
 
+
 
// MAIN -------------------------------------------------------------------------------------
 
// MAIN -------------------------------------------------------------------------------------
 
_profiles = [_group, _spawnposition, random(360), _spawnExactLocation, _faction] call ALIVE_fnc_createProfilesFromGroupConfig;
 
_profiles = [_group, _spawnposition, random(360), _spawnExactLocation, _faction] call ALIVE_fnc_createProfilesFromGroupConfig;
_profile = _profiles select 0;
+
 
 +
_groupData = [ALIVE_groupConfig, _group] call ALIVE_fnc_hashGet;
 +
_config = (configFile >> "CfgGroups");
 +
for "_i" from 0 to count _groupData -2 do {_config = _config select (_groupData select _i);};
 +
_groupName = getText(_config >> "name");
 +
 
 +
if(_debug) then { ["ALIVE_spawnProfileGroup -> _groupData: %1, _config: %2, _groupName: %3", _groupData, _config, _groupName] call ALIVE_fnc_dump; };
 
_profileWaypoint = [_destinationPosition, _waypointPlacementRadius, _waypointType, _waypointMovement, _waypointCompletionRadius,  
 
_profileWaypoint = [_destinationPosition, _waypointPlacementRadius, _waypointType, _waypointMovement, _waypointCompletionRadius,  
 
  _waypointTimeoutCounters,_waypointFormation, _waypointCombatMode, _waypointBehaviour, _waypointDescription] call ALIVE_fnc_createProfileWaypoint;
 
  _waypointTimeoutCounters,_waypointFormation, _waypointCombatMode, _waypointBehaviour, _waypointDescription] call ALIVE_fnc_createProfileWaypoint;
 +
 +
if (_groupName == "Infantry") then {_profile = _profiles select 0; } else { _profile = _profiles;};
 
[_profile, "addWaypoint", _profileWaypoint] call ALIVE_fnc_profileEntity;
 
[_profile, "addWaypoint", _profileWaypoint] call ALIVE_fnc_profileEntity;
 
// MAIN -------------------------------------------------------------------------------------
 
// MAIN -------------------------------------------------------------------------------------
+
 
// ====================================================================================
 
// ====================================================================================
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 13:26, 6 February 2014

Spawn Group Script By Jman

/* 
* Filename:
* fnc_spawnProfileGroup.sqf 
*
* Locality:
* Runs on server
*
* Description:
* Spawns a group faction and sends them to a waypoint.
* 
* Params:
* _spawnPosition  -> Array. Position to spawn group
* _spawnExactLocation -> Boolean. Set to false if you want to spawn it in an exact position.
* _destinationPosition -> Array. Position of waypoint destination.
* _group -> String. CfgGroups name 
* _faction -> String. CfgGroups faction
 
* Optional Params:
* _debug -> Boolean. Enable debug output
* _waypointPlacementRadius -> Scalar. Random placement radius. http://community.bistudio.com/wiki/Mission_Editor:_Waypoints#Placement_Radius
* _waypointType -> String. Type of waypoint. NOTE: at the moment only MOVE is supported by the profiler. http://community.bistudio.com/wiki/Mission_Editor:_Waypoints#Select_Type
* _waypointMovement -> String. Speed of waypoint movement. http://community.bistudio.com/wiki/Mission_Editor:_Waypoints#Speed
* _waypointCompletionRadius -> Scalar. Completion radius of waypoint. http://community.bistudio.com/wiki/Mission_Editor:_Waypoints#Completion_Radius
* _waypointTimeoutCounters -> Array.  Timeout counters. http://community.bistudio.com/wiki/Mission_Editor:_Waypoints#Timeout_Counters
* _waypointFormation -> String. Formation type. http://community.bistudio.com/wiki/Mission_Editor:_Waypoints#Formation
* _waypointCombatMode -> String. Combat mode. http://community.bistudio.com/wiki/Mission_Editor:_Waypoints#Combat_Mode
* _waypointBehaviour -> String. Behaviour type. http://community.bistudio.com/wiki/Mission_Editor:_Waypoints#Behaviour
* _waypointDescription -> String. Description. http://community.bistudio.com/wiki/Mission_Editor:_Waypoints#Description
* 
*
* Usage:
*
* init.sqf:
* ALIVE_spawnProfileGroup = compile (preprocessFileLineNumbers "fnc_spawnProfileGroup.sqf");
*
* Create a trigger or call in script:
*
* Syntax:
* [array, boolean, array, string, string, boolean, scalar, string, string, scalar, array, string, string, string, string] call ALIVE_spawnProfileGroup;
*
* Example(s):
* [getMarkerPos "nmeGrp01_spawn_pos", false, getMarkerPos "nmeGrp01_dest_pos", "10_men_ME", "caf_ag_me"] call ALIVE_spawnProfileGroup;
* [getMarkerPos "nmeGrp01_spawn_pos", false, getMarkerPos "nmeGrp01_dest_pos", "10_men_ME", "caf_ag_me", 
  true, 0, "Move", "Full", 0, [0,0,0], "Delta", "Open Fire, Engage At Will", "Aware", ""] call ALIVE_spawnProfileGroup;
* 
* Credits: ALiVE functions: The ALiVE team. Web: http://www.alivemod.com
* Script Created by [KH]Jman
* Creation date: 06/02/2014
* Email: jman@kellys-heroes.eu
* Web: http://www.kellys-heroes.eu
* 
*
* */
// ====================================================================================
if (!isServer) exitWith {};
// ====================================================================================
 
// SCOPE -------------------------------------------------------------------------------------
private["_spawnposition","_spawnExactLocation","_destinationPosition","_faction","_profile","_profiles","_profileWaypoint","_group","_debug",
"_waypointPlacementRadius","_waypointType","_waypointMovement","_waypointCompletionRadius","_waypointTimeoutCounters","_waypointFormation",
"_waypointCombatMode","_waypointBehaviour","_waypointDescription","_groupName", "_groupName","_config"];
_config = [];
// SCOPE -------------------------------------------------------------------------------------
 
waitUntil {!isNil "ALIVE_profileSystemInit"};
 
// PARMS -------------------------------------------------------------------------------------
_spawnPosition = _this select 0;
_spawnExactLocation = _this select 1;  
_destinationPosition = _this select 2;
_group = _this select 3;
_faction = _this select 4;
_debug = if(count _this > 5) then {_this select 5} else {false};
_waypointPlacementRadius = if(count _this > 6) then {_this select 6} else {0};
_waypointType = if(count _this > 7) then {_this select 7} else {"Move"};
_waypointMovement = if(count _this > 8) then {_this select 8} else {"Full"};
_waypointCompletionRadius = if(count _this > 9) then {_this select 9} else {0};
_waypointTimeoutCounters  = if(count _this > 10) then {_this select 10} else {[0,0,0]};
_waypointFormation = if(count _this > 11) then {_this select 11} else {"Delta"};
_waypointCombatMode = if(count _this > 12) then {_this select 12} else {"Open Fire, Engage At Will"};
_waypointBehaviour = if(count _this > 13) then {_this select 13} else {"Aware"};
_waypointDescription = if(count _this > 14) then {_this select 14} else {""};
// PARMS -------------------------------------------------------------------------------------
 
// DEBUG -------------------------------------------------------------------------------------
if(_debug) then {
 ["ALIVE_spawnProfileGroup -> _spawnPosition: %1, _spawnExactLocation: %2, _destinationPosition: %3, _group: %4, _faction: %5, 
 _debug: %6, _waypointPlacementRadius: %7, _waypointType: %8, _waypointMovement: %9, _waypointCompletionRadius: %10, 
 _waypointTimeoutCounters: %11, _waypointFormation: %12, _waypointCombatMode: %13, _waypointBehaviour: %14, 
 _waypointDescription: %15,", _spawnPosition,_spawnExactLocation,_destinationPosition,_group,_faction,_debug,_waypointPlacementRadius,
 _waypointType,_waypointMovement,_waypointCompletionRadius,_waypointTimeoutCounters,_waypointFormation,_waypointCombatMode,
 _waypointBehaviour,_waypointDescription] call ALIVE_fnc_dump;
};
// DEBUG -------------------------------------------------------------------------------------
 
// MAIN -------------------------------------------------------------------------------------
_profiles = [_group, _spawnposition, random(360), _spawnExactLocation, _faction] call ALIVE_fnc_createProfilesFromGroupConfig;
 
_groupData = [ALIVE_groupConfig, _group] call ALIVE_fnc_hashGet;
_config = (configFile >> "CfgGroups");
for "_i" from 0 to count _groupData -2 do {_config = _config select (_groupData select _i);};
_groupName = getText(_config >> "name");
 
if(_debug) then { ["ALIVE_spawnProfileGroup -> _groupData: %1, _config: %2, _groupName: %3", _groupData, _config, _groupName] call ALIVE_fnc_dump; };
_profileWaypoint = [_destinationPosition, _waypointPlacementRadius, _waypointType, _waypointMovement, _waypointCompletionRadius, 
 _waypointTimeoutCounters,_waypointFormation, _waypointCombatMode, _waypointBehaviour, _waypointDescription] call ALIVE_fnc_createProfileWaypoint;
 
if (_groupName == "Infantry") then {_profile = _profiles select 0; } else { _profile = _profiles;};
[_profile, "addWaypoint", _profileWaypoint] call ALIVE_fnc_profileEntity;
// MAIN -------------------------------------------------------------------------------------
 
// ====================================================================================