Dev scripts I use

ArmA 2 editing; configs, modeling, missions, textures, terrain etc.

Moderators: Snake Man, Lone Wolf

Post Reply
T_Rex
FreeFalcon
Posts: 848
Joined: 2001-03-04, 11:01:01 PM
Location: here

Dev scripts I use

Post by T_Rex » 2009-12-03, 04:24:33 PM

If anyone is interested, I have a series (continually in development) of scripts I use to dev stuff. Most of them are quite simple, but I can post the code if you are interested.

I. Mission testing
........
JTD_intCam.sqf
JTD_intCamInit.sqf
- these initiate an internal camera from an addaction
- usage - initiate addaction, then mapclick, then it selects the nearest unit for the internal camera
........
JTD_remCam.sqf
JTD_remCamInit.sqf
- these initiate a remote free camera from an addaction
- usage - initiate addaction, then mapclick, then it selects the nearest object to start a free camera
........
JTD_heloCall.sqf
JTD_heloCallInit.sqf
- these spawn a UH-1Y from an addaction
- usage - initiate addaction, then mapclick, then it selects an appropriate area to spawn a UH-1Y
........
JTD_teleport.sqf
- simple script, from an addaction, to teleport to location of mapclick
........


II. Mission functions
........
JTD_fnc_dirNormal.sqf
- normalizes a number to a 0-360 degree reference
........
JTD_fnc_randPos.sqf
- selects a random position from a center point, optionally in a specific direction
........
JTD_fnc_randVector.sqf
- selects random vector within offset from given vector
........
JTD_fnc_randGroup.sqf
- spawns random group from specified faction at specified position from config type
........

I'll post the code to this last one - it is pretty slick, if I do say so myself.

Code: Select all

/*
JTD_fnc_randGroup.sqf
by Trexian

Purpose: spawn a random group from specified config types at specified location.

Implementation: from a call.

ooooooooooooooooooooooooooooooooooooooooooooooooooo
Credit:
Spooner's config posts -  http://www.ofpec.com/forum/index.php?topic=31961.0
DM for math
OFPEC

ooooooooooooooooooooooooooooooooooooooooooooooooooo
Information

Elements received:
0 = position (pos array)
1 = faction (Str faction) - default is CIV
2 = type (String or Array of strings)?  Maybe just array

Return:
spawned group

ooooooooooooooooooooooooooooooooooooooooooooooooooo
Version history
01a -
proof of concept


ooooooooooooooooooooooooooooooooooooooooooooooooooo
TTD


*/

private ["_pos", "_faction", "_types", "_cfgGroups", "_side", "_cfgPath", "_grpPath", "_i", "_class", "_groupR", "_ret"];

// get initial stuff
_pos = _this select 0;
_faction = _this select 1;
_types = _this select 2;

_cfgGroups = [];
// error checking -- need to make sure types are valid?
if !(_faction in ["USMC", "CDF", "RU", "INS", "GUE", "CIV"]) then
{
	_faction = "CIV";  // spawns civ if faction is invalid
};


if (count _types == 0) then
{
	_types = ["Infantry"];	// defaults to infantry if nothing specified
};


// set up config path

switch (_faction) do 
{
	case "USMC":
	{
  _side = west;
  _cfgPath = configFile >> "cfgGroups" >> "West";
	};
	case "CDF":
	{
  _side = west;
  _cfgPath = configFile >> "cfgGroups" >> "West";
	};
	case "RU":
	{
  _side = east;
  _cfgPath = configFile >> "cfgGroups" >> "East";
	};
	case "INS":
	{
  _side = east;
  _cfgPath = configFile >> "cfgGroups" >> "East";
	};
	case "GUE":
	{
  _side = resistance;
  _cfgPath = configFile >> "cfgGroups" >> "Guerilla";
	};
	case "CIV":
	{
  _side = civilian;
  _cfgPath = configFile >> "cfgGroups" >> "Civilian";
	};
	default
	{
  _side = civilian;
  _cfgPath = configFile >> "cfgGroups" >> "Civilian";
	};
};

// Compile pool of the types
{
	//Find all groups defined for various subtypes.
	_grpPath = _cfgPath >> _faction >> _x;
//diag_log text format ["path = %1", _grpPath];
	for "_i" from 0 to ((count _grpPath) - 1) do 
	{
  _class = _grpPath select _i;
  
  //Only take actual classes.
  if (isClass (_class)) then 
  {
  	_cfgGroups = _cfgGroups + [_class];
  };
	};
} forEach _types;

//diag_log text format ["count types = %1", count _cfgGroups];

_groupR = _cfgGroups call BIS_fnc_selectRandom;
_ret = [_pos, _side, _groupR, [], [], [], []] call BIS_fnc_spawnGroup;
// return the groupInfo, which should represent the names of the various groups
_ret
So, if in a script I have (having already preprocessed the function):
_groupR = [_pos, "INS", ["Infantry", "Motorized", "Mechanized"]] call JTD_fnc_rGrp;

It will spawn a random group of Insurgent infantry, motorized, or mechanized groups. :)
Sic Semper tyrannosauro.

Snake Man
Commander-In-Chief
Posts: 8561
Joined: 2000-07-31, 10:01:01 PM
Gaming Interests: ArmA, ArmA 2, Falcon 4.0 and OFP.
Editing Interests: All, I (try) to edit everything.
Location: PMC

Re: Dev scripts I use

Post by Snake Man » 2010-08-19, 06:58:30 AM

T_Rex wrote:If anyone is interested, I have a series (continually in development) of scripts I use to dev stuff. Most of them are quite simple, but I can post the code if you are interested.
I am interested :)

Would be great if you could post the scripts here. If you do, when you write the bbcodes into forum, you can use:

code=php

inside the [ ] things, that puts the code block into PHP syntax highlighting thing, its very nice to read.
PMC since 1984

Editing knowledge, visit PMC Editing Wiki
Addon manuals, visit PMC addons/mods online manuals
View our videos in PMC Youtube channel.

PMC Tactical forum Advanced Search is power.

T_Rex
FreeFalcon
Posts: 848
Joined: 2001-03-04, 11:01:01 PM
Location: here

Re: Dev scripts I use

Post by T_Rex » 2010-08-19, 01:15:47 PM

Ok, been awhile since I've looked at these, so some may need updating, but they work for me. :) These all require you, in a mission init or unit init, to create addactions that reference the init scripts.

Like in the mission init, I usually have something like:

Code: Select all

// @@ dev addactions
_JTD_teleport = player addAction ["teleport", "JTD_teleport.sqf","",10,false,false,""];
_JTD_intCam = player addAction ["Sel int cam", "JTD_intCamInit.sqf","",10,false,false,""];
_JTD_remCam = player addAction ["Remote cam", "JTD_remCamInit.sqf","",10,false,false,""];
_JTD_heloCall = player addAction ["Helo call", "JTD_heloCallInit.sqf","",10,false,false,""];

onTeamSwitch "selectPlayer (leader _from); {_x doFollow leader _from} foreach units _from; selectPlayer _to;";
// end dev addactions
 
Spawns a helo on a mapclick-
Init - is referenced in an addaction

Code: Select all

/*
Ver. history
01
proof of concept

02
use mapclick for center, but use findEmptyPosition to actually place

03
automagically open map
*/

titleText["Select location for helo", "PLAIN"];

//open map
openMap true;

onMapSingleClick "[_pos] execVM 'JTD_heloCall.sqf'; onMapSingleClick ''; true;";
 
The actual spawning:

Code: Select all

/*
Ver. history
01
proof of concept

02
use mapclick for center, but use findEmptyPosition to actually place

03
close map?
*/

_pos = _this select 0;

_loc = _pos findEmptyPosition [20, 100, "UH1Y"];
hint format ["loc %1", _loc];
sleep 1;
    _helo = 'UH1Y' createVehicle _loc;
    _helo setDir (random 360);
// added to close the map
 
These 2 are pretty cool camera scripts.
Remote camera:
init-

Code: Select all

titleText["Select Position for Remote Camera", "PLAIN"];
//open map
openMap true;
onMapSingleClick "[_pos] execVM 'JTD_remCam.sqf'; onMapSingleClick ''; true;";
 
camera create

Code: Select all

private ["_pos", "_unitPL", "_list", "_cam"];

_pos = _this select 0;

_unitPL = player;
_list = nearestObjects [[_pos select 0, _pos select 1, 0], [], 50];
_cam = _list select 0;
//hint format ["CAMERA %1 %2", _cam, count _list];
_cam exec 'camera.sqs';
 
Camera that is actually the internal camera for AI near the mapclick:
init-

Code: Select all

titleText["Select Internal Cam Position", "PLAIN"];
// try to close the map?

// _JTD_intCam = player addAction ["Sel int cam", "JTD_internalCam.sqf","",10,false,false,""];

// can return "_unit"?  That's the units selected by the player from his group
// _manlist = (player) nearEntities [["Man"], 1000];
//tweak nearEntities radius
/*
new idea:
From the onMapSingleClick, trigger a new sqf.
In that one, waituntil (inputaction "v") then transfer back to the player internal.
*/
//open map
openMap true;
onMapSingleClick "[_pos] execVM 'JTD_intCam.sqf'; onMapSingleClick ''; true;";
 
camera create

Code: Select all


private ["_pos", "_list", "_cam"];

_pos = _this select 0;

_list = nearestObjects [_pos, ["MAN"], 100];
if (count _list > 0) then
    {
    //hint format ["list = %1", _list];
    _cam = _list select 0;
    _cam switchCamera "INTERNAL";
    // hit 0 or buldozer camera reset to exit
    waitUntil {inputAction "buldResetCamera" > 0};
    player switchCamera "INTERNAL";
    };
 
Are you interested in the group spawning stuff, too?
Sic Semper tyrannosauro.

Snake Man
Commander-In-Chief
Posts: 8561
Joined: 2000-07-31, 10:01:01 PM
Gaming Interests: ArmA, ArmA 2, Falcon 4.0 and OFP.
Editing Interests: All, I (try) to edit everything.
Location: PMC

Re: Dev scripts I use

Post by Snake Man » 2010-08-19, 01:29:24 PM

Looking good, thanks for posting those.

Hmm what ground spawning, wasn't it already there in first post or you mean something else?
PMC since 1984

Editing knowledge, visit PMC Editing Wiki
Addon manuals, visit PMC addons/mods online manuals
View our videos in PMC Youtube channel.

PMC Tactical forum Advanced Search is power.

T_Rex
FreeFalcon
Posts: 848
Joined: 2001-03-04, 11:01:01 PM
Location: here

Re: Dev scripts I use

Post by T_Rex » 2010-08-19, 01:42:50 PM

Oh yeah, I played around with spawning groups of units, and vehicles. But, that was somewhat redundant of the BIS function that spawns groups, too. :)
Sic Semper tyrannosauro.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest