OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: twisted on 12 Feb 2009, 23:10:08
-
Hi.
I am trying to write a simple script that'll move selected groups to one of a selection of random markers on the map. i have a script that i have yet to test (don't have arma on this machine) but i cannot figure how to make sure the group doesn't teleport onto the exact same spot.
i was thinking of using a trigger to initialize this script.
//simple script to move a group to a random marker
if !(isServer) exitWith {};
private ["_groups", "_groupchosen", "_markers", "_totalmarkers", "i", "_chosenmarker", "_units"];
_groups = ["west1","east1"];
_groupchosen = _groups select 0;
_markers = ["1start","2start","3start"];//defined in editor
_totalmarkers = count _markers;
_i = random _totalmarkers;
_chosenmarker = _markers select _i;
_groupchosen setPos (getPos _chosenmarker);
{_units = _x; _x setPos (getPos _chosenmarker);
} forEach units _groupchosen;
_groupchosen setCombatMode "YELLOW";
_groupchosen setSpeedMode "FULL";
_groupchosen setFormation "LINE";
-
How about this?
if !(isServer) exitWith {};
private ["_group", "_markers", "_totalmarkers", "_i", "_chosenmarker", "_units"];// your _i was incorrect in your example
_group = west1;
_i = round (random 2);//you know that you have three markers
switch (_i) do
{
case "0":
{
_chosenmarker = "1start";
};
case "1":
{
_chosenmarker = "2start";
};
case "2":
{
_chosenmarker = "3start"";
};
};
_group move (getpos _chosenmarker);//the whole group will move to chosen marker, no need to then send each individual in the group
_group setCombatMode "YELLOW";
_group setSpeedMode "FULL";
_group setFormation "LINE";
I'm not the most experienced guy here by any means, but I think this should work fine, and I love using switch when I can, it just seems so tidy and quick.
-
Switches are more specific, if he wanted this to be more easily editable, a array containing all markers is much better setup.
//simple script to move a group to a random marker
if !(isserver) exitwith {};
private ["_groups","_markers"];
_groups = ["west1","east1"];
_markers = ["1start","2start","3start"];
{
private"_i";
_i = ceil (random (count _markers)) -1;
{
_x setPos getPos (_markers select _i);
} foreach units _x;
_markers = _markers - [_markers select _i];
_x setCombatMode "YELLOW";
_x setSpeedMode "FULL";
_x setFormation "LINE";
} foreach _groups;
-
thanks! arma's scripting seems to allow a lot to happen with few lines if you know what you are doing. the switch solution is interesting Sparticus76 and i didn't know they existed - definetly very clean solution, but the array solution is the most easily modable for my needs.
cheers again Rommel92.
-
Out of curiosity, do you want them to be moved to those specific markers, or a random distance/vector from those markers?
:)
-
well , first to those markers. but ultimately a little off the markers so the AI don't all spawn at exact same spot.
One thing that's a bit embarressing (other than my spelling skills) is that i am not sure if i am calling the script correctly via a trigger using [] exec "markersript.sqf"
#EDIT: No need to quote the entire previous post you're replying to.. h-
-
not sure if i am calling the script correctly via a trigger using [] exec "markersript.sqf"
That will work fine; however exec should be execVM; the array is also not necessary considering you could call the script with no parameters. ie
execVM "markersript.sqf"