OFPEC Forum
Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: Trexian on 10 Jul 2009, 02:36:53
-
Hey guys!
In various activities with ArmA, and now ArmA2, I've found myself thinking, "Gee, I wish I could do ..." something, but I always got along without doing it. In an effort to make things easier for myself in ArmA2 work, I decided to go ahead and write these scripts.
They are:
- teleport
- switch the camera to the nearest AI to a point on a mapclick
- start camera sqs at a point near a mapclick
- make a helo appear at a mapclick
Now, these are primarily for devs - people may want to tweak them to "taste." And, there's basically no error catching. If it doesn't work, it is because it didn't find what it was looking for. Which may help in and of itself. :D
Anyway, here they are, in case anyone else finds them useful. And comments/suggestions are always welcome.
First, the implementation. In the init, I have a section where I do the addactions (and fix the groups-not-moving-on-teamswitch issue).
// @@ 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_intCam = player addAction ["Remote cam", "JTD_remCamInit.sqf","",10,false,false,""];
_JTD_heloCall = player addAction ["Helo call", "JTD_heloCall.sqf","",10,false,false,""];
onTeamSwitch "selectPlayer (leader _from); {_x doFollow leader _from} foreach units _from; selectPlayer _to;";
// end dev addactions
The simple/tweaked teleport:
hint "Click on MAP to Teleport";
onmapsingleclick "player setpos _pos";
Next, the internal cam init. Basically, it passes the position of the mouseclick to a script:
titleText["Select Internal Cam Position", "PLAIN"];
onMapSingleClick "[_pos] execVM 'JTD_intCam.sqf'; onMapSingleClick ''; true;";
Then the cam code, it puts you into the unit nearest the point within 100m, and hit the buldozer exit to exit (default is numpad 0):
private ["_pos", "_list", "_cam"];
_pos = _this select 0;
_list = nearestObjects [_pos, ["MAN"], 100];
if (count _list > 0) then
{
_cam = _list select 0;
_cam switchCamera "INTERNAL";
// hit 0 or buldozer camera reset to exit
waitUntil {inputAction "buldResetCamera" > 0};
player switchCamera "INTERNAL";
};
Next is the remote camera, which also requires an init to send the position to a script:
titleText["Select Position for Remote Camera", "PLAIN"];
onMapSingleClick "[_pos] execVM 'JTD_remCam.sqf'; onMapSingleClick ''; true;";
Then the remote camera code. It finds anything within 50m and uses it to launch the camera, use the buldozer exit (default numpad 0) to exit:
private ["_pos", "_list", "_cam"];
_pos = _this select 0;
_list = nearestObjects [[_pos select 0, _pos select 1, 0], [], 50];
_cam = _list select 0;
_cam exec 'camera.sqs';
And finally, a simple script to conjure a helo to a map position.
titleText["Select location for helo", "PLAIN"];
onmapsingleclick "
_helo = 'UH1Y' createVehicle _pos;
_helo setDir (random 360);
onMapSingleClick '';
true;
";
hehe
Thanks to everyone here for all the wisdom you impart to us n00bs on a daily basis. And to all past members who've posted stuff I've found while searching! I am often amazed at the body of knowledge present here.
:clap:
-
nice work..
any chance of getting a demo.. for the rest of us noobers?
:)
-
Oh... like a mission?
Sure - I'll post my generic test mission in the next day or so.
(Got a 8800 GT vidcard from a buddy that I need to install.) ;)
Added a demo "mission" - no real object to it.
-
Here's a new one I came up with today - didn't bother with a demo mission, though. Soz.
This little baby spawns a random group from the config entries of the given type(s). Borrows heavily from a couple BI scripts in the ACM and SOM modules.
JTD_fnc_randGroup.sqf
/*
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 (Array of strings)
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;
I'll get a random group of Insurgent infantry, motorized, or mechanized groups. :)