Jump to content
Sign in to follow this  
falconx1

Random player start locations script help

Recommended Posts

In my map i have 3 markers named StartLocation1, StartLocation2,StartLocation3

I'm trying to test this script before i add in into my map etc but i cant get the script to work.

I'm testing the code in the init.sqf but it hasn't worked, don't know what I'm doing wrong.

// Pick Start Location /
_StartLoc = round ((random 3) + 0.5); // 



if (_StartLoc  == 1) then 
{
    player setPos StartingLocation1;
	player setdir 180;
};

if (_StartLoc  == 2) then 
{
    player setPos StartingLocation2;
	player setdir 180;
};

if (_StartLoc  == 3) then 
{
    player setPos StartingLocation3;
	player setdir 180;
};

Edited by falconx1

Share this post


Link to post
Share on other sites

This player setPos StartingLocation1; should be

like this player setpos getmarkerpos StartingLocation1; ect.

Also add a hint to check the number is correct

hint str _StartLoc;

Share this post


Link to post
Share on other sites

tested it, the hint works, but it still don't move me to a random area

here is the marker class = from my mission.sqm

class Markers
{
	items=3;
	class Item0
	{
		position[]={1837.527,5.5,5641.125};
		name="StartingLocation1";
		type="Empty";
	};
	class Item1
	{
		position[]={4306.4438,223.05334,3838.8472};
		name="StartingLocation2";
		type="Empty";
	};
	class Item2
	{
		position[]={3156.4524,3.6717255,5906.5928};
		name="StartingLocation3";
		type="Empty";
	};
};
};

Share this post


Link to post
Share on other sites

sorry forgot the obvious maker is a string so needs quotes

player setpos getmarkerpos "StartingLocation1";

Share this post


Link to post
Share on other sites

works! thanks a lot man:), as funny as this sounds i been working on this about 4 hours with about 100 different syntax variations haha

Thanks again!:yay:

Share this post


Link to post
Share on other sites

there's also this way.

_location= ["StartingLocation1","StartingLocation2","StartingLocation3"] call BIS_fnc_selectrandom;

player setpos getmarkerpos _location;// without quotes

Share this post


Link to post
Share on other sites

Does the Second way need a certain functions module or just for amra2? I'm of course designing for Arma3 Beta

Share this post


Link to post
Share on other sites

I thought the function module wasn't needed anymore but I can't remember if I tried it or not.

Share this post


Link to post
Share on other sites
there's also this way.

_location= ["StartingLocation1","StartingLocation2","StartingLocation3"] call BIS_fnc_selectrandom;

player setpos getmarkerpos _location;// without quotes

How would one go about doing this with over 100 spawn locations? In the format of respawn_civilian, respawn_civilian_1, respawn_civilian_2 etc out to over 100.

Edited by Trauma.au

Share this post


Link to post
Share on other sites

@falconx1

There is no need to script this if you dont want to.

Place the player at a position you would like to spawn at, create 2 markers at each of the other locations. Group both these markers to the player.

When you start you will randomly spawn at the player placement or one of the other markers.

@Trauma.au

_randPos = (floor (random 100)) + 1;
_markerName = format ["respawn_civilian_%1",_randPos];
player setPosATL getMarkerPos _markerName;

Edited by Larrow

Share this post


Link to post
Share on other sites

Thx Larrow.

I took that format and added random bearing to it.

_randPos = (floor (random 100)) + 1;
_markerName = format ["respawn_civilian_%1",_randPos];
player setPosATL getMarkerPos _markerName;
_randbearing = (floor (random 360)) + 1;
_markerName = format ["respawn_civilian_%1",_randbearing];
player setdir _randbearing;

Slowly learning this stuff, can I ask why it has to be layed out as (floor (random #)) + 1; I understand that it wont work other wise and what floor does, but why must it be layed out like that and what doe the +1 at the end do?

Thx.

Edited by Trauma.au

Share this post


Link to post
Share on other sites
floor (random 100)

results in 0-99. The +1 just adds one to give you a range of 1-100 in whole numbers rather than the full output of random which might be something like 0.123141 or 98.343 or something funky.

Share this post


Link to post
Share on other sites
floor (random 100)

results in 0-99. The +1 just adds one to give you a range of 1-100 in whole numbers rather than the full output of random which might be something like 0.123141 or 98.343 or something funky.

Ah of course, cuz it starts at 0 not 1, thx.

Share this post


Link to post
Share on other sites

As kylania said random gives you a number between 0 and upto but not including the number you pass it (I think to five decimal places - If i remember properly from testing it several times) so 0-99.99999. Floor takes it down to the nearest integer (whole number) 0-99, +1 to give you a range of 1-100.

_randbearing = (floor (random 360)) + 1;
_markerName = format ["respawn_civilian_%1",_randbearing];
player setdir _randbearing;  

Edit : Ok reread lines, Why the _markerName = format ["respawn_cvilian_%1,_randbearing]? As its not being used.

You can just use

player setDir (random 360)

This will set your direction between 0-359.99999 degrees, as 360 and 0 are the same heading there is no need for the floor or the +1.

Edited by Larrow

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  

×