Jump to content
Sign in to follow this  
Dr_Cox1911

Random spawn with marker

Recommended Posts

Greetings,

I´m trying to spawn a soldier randomly at a marker. For this purpose I wrote this little SQF-script:

_cap = _this select 0;

_ranPos = floor(random 2);

switch (_ranPos) do
{
case 0:
{
	_capPos=getMarkerPos "cap_pos0";
	_z=3;
	hint "0";
};
case 1:
{
	_capPos=getMarkerPos "cap_pos1";
	_z=0;
	hint "1";
};
};

_cap setPos [_capPos select 0, _capPos select 1, (getPos _cap select 2) + _z];
_cap setCaptive true;

The soldier has this in his init-line:

_null = [this] execVM "captive.sqf"

Can anybody tell me the error in this script? It seems that only the "setCaptive" command works but nothing else:mad:

Share this post


Link to post
Share on other sites

I have a function for that mate..

Give me ten minutes to find it!

Share this post


Link to post
Share on other sites
_cap = _this select 0;

_ranPos = ["cap_pos0","cap_pos1"] call BIS_fnc_selectRandom;

_cap setPos [getMarkerPos _ranPos select 0, getMarkerPos _ranPos select 1, (getMarkerPos _ranPos select 2) + 3];
_cap setCaptive true;

Share this post


Link to post
Share on other sites

_cap = _this select 0;
_ranPos = floor random 2;
_capPos = getMarkerPos format ["cap_pos%1", _ranPos];
hint format ["%1", _ranPos];
_capPos set [2, 0];
_cap setPosATL _capPos;
_cap setCaptive true;

Try that one, some space saving techniques (that's assuming it works, of course; untested ;))

Edited by dwringer
change to setposatl

Share this post


Link to post
Share on other sites

The original script probably isn't working because it's defining variables within the switch scope and as a result won't be seen outside the scope.

placing this at the begining of the script may get it working but Cobra's is simpler.

private ["_capPos","_z"];

Share this post


Link to post
Share on other sites

Use the code below to create fnc_location...

// location function


 private ["_pos","_locations","_closest"];

 _pos = _this;
 if (typename _pos == typename objNull) then {_pos = getpos _pos};
 _locations = [["NameCityCapital","NameCity","NameVillage"],[_pos,1000]] call BIS_fnc_locations;
 _closest = objNull;

 if (count _locations > 0) then {
   _closest = _locations select 0;
   {
     if (_x distance _pos < _closest distance _pos) then {
       _closest = _x;
     };
   } foreach _locations;
 };
 _closest

Then call it with this code...

		_loc = getmarkerpos "marker";
	_houseDist = 10;
	for "_i" from 0 to 100 do

		{
		_dist = random 250;
		_dir = random 360;
		_loc = [(_loc select 0) + (sin _dir) * _dist, (_loc select 1) + (cos _dir) * _dist, 0];
		if (!(surfaceIsWater _loc) && (count (nearestObjects [_loc,["House"],_houseDist]) == 0)) exitWith  { _i = 100};
		};
		player setpos _loc call BIS_fnc_findSafePos;

			loc = player call fnc_location;

[str (format ["%1, you are in", name player]), str(loc getvariable "name")] spawn BIS_fnc_infoText;

I compiled it in the init.sqf file using this

fnc_location = compile preprocessFile "complies\fnc_location.sqf"; // location

I used it mainly for Cherno, cannot see why it wont work though..

Share this post


Link to post
Share on other sites

Thanks guys!

I use the solution from cobra4v320, works like a charm:cool:

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×