Home   Help Search Login Register  

Author Topic: simple move group to random marker script  (Read 2098 times)

0 Members and 1 Guest are viewing this topic.

Offline twisted

  • Members
  • *
  • I'm a llama!
simple move group to random marker script
« 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.

Code: [Select]
//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";


Offline Sparticus76

  • Members
  • *
Re: simple move group to random marker script
« Reply #1 on: 13 Feb 2009, 10:11:07 »

How about this?

Code: [Select]
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.

Offline Rommel92

  • Members
  • *
Re: simple move group to random marker script
« Reply #2 on: 13 Feb 2009, 11:01:31 »
Switches are more specific, if he wanted this to be more easily editable, a array containing all markers is much better setup.

Code: [Select]
//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;

Offline twisted

  • Members
  • *
  • I'm a llama!
Re: simple move group to random marker script
« Reply #3 on: 13 Feb 2009, 16:48:46 »
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.

Offline Trexian

  • Members
  • *
Re: simple move group to random marker script
« Reply #4 on: 19 Feb 2009, 16:03:59 »
Out of curiosity, do you want them to be moved to those specific markers, or a random distance/vector from those markers?

:)
Sic semper tyrannosauro.

Offline twisted

  • Members
  • *
  • I'm a llama!
Re: simple move group to random marker script
« Reply #5 on: 22 Feb 2009, 04:21:58 »
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-
« Last Edit: 22 Feb 2009, 09:14:05 by h- »

Offline Rommel92

  • Members
  • *
Re: simple move group to random marker script
« Reply #6 on: 22 Feb 2009, 07:14:53 »
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
Code: [Select]
execVM "markersript.sqf"
« Last Edit: 22 Feb 2009, 07:16:49 by Rommel92 »