Jump to content
Sign in to follow this  
Fumbles88

Teleport location using a secondary script [No Marker]

Recommended Posts

[sOLVED!]

Hi guys,

Very sorry if something like this has been posted before - I have searched and there are an insurmountable amount of teleport threads but of the many I looked at I could not find one that matched my problem/criteria.

I am making a mission that is to be used for practice/teaching unit members how to navigate and get their bearings without being able to see their location on the map or use a GPS. The idea is that the instructor can go up to a placed flagpole, at base, and select 'set location' - at this point I have a script that will randomly assign a location that is within a 1.5~2Km radius from the "Objective" marker. At the Objective marker is a small 'base' which they must make their way to in order to successfully complete the training.

Once this has been done, each individual can click on 'teleport' on the flagpole and will be spawned to the same location until, once again, someone selects 'set location' which will create yet another random location for everyone else to spawn to.

I have had tried what feels like several thousand versions of this script and the closest I have been able to get is each person teleporting to completely different locations - despite the fact 'set location' had only been set once. I've done several teleport scripts before but never one that predetermines a completely random location, to which all players must teleport, without a marker.

Any and all help will be most gratefully accepted. Below is the code.

location.sqf

//setPos.sqf by 2Lt M Henderson
//For patrolling MkI
//PNCOTC 6thAD

//Gets a random position to spawn units in at a range of between 1500~2000

//Declare private variables
private ["_radius","_randomLocation","_location"];

if (!isServer) exitWith {};

//Set radius for spawn
_radius = random(2000);
while {_radius < 1500} do
	{
		_radius = random(2000);
	};

_location = getMarkerPos "Objective";

//Generate a random location
_randomLocation = [(_location select 0) + _radius * sin(random 359), (_location select 1) + _radius * cos(random 359), (_location select 2) + 0];


//Send result to global variable 'finalLocation'
finalLocation = _randomLocation;

teleport.sqf

//setPos.sqf by 2Lt M Henderson
//For patrolling MkI
//PNCOTC 6thAD

private ["_pole","_unit"];


_pole = _this select 0;
_unit = _this select 1;


//Spawn Player
_unit setPos finalLocation;

Edited by Fumbles88
Solved

Share this post


Link to post
Share on other sites

Well your problem is apparent: every client gets another location to spawn to - what you have to do hower is to assign one public variable with the location, not a global one :D

//setPos.sqf by 2Lt M Henderson
//For patrolling MkI
//PNCOTC 6thAD

//Gets a random position to spawn units in at a range of between 1500~2000

//Declare private variables
private ["_radius","_location"];

if (isServer) then
{
//Set radius for spawn
_radius = 0;
while {_radius < 1500} do
{
	_radius = random(2000);
};

_location = getMarkerPos "Objective";

waituntil {!isnil "bis_fnc_init"};
finalLocation = [getMarkerPos "Objective", _radius, random 360] call BIS_fnc_relPos;

publicVariable "finalLocation";
};

//setPos.sqf by 2Lt M Henderson
//For patrolling MkI
//PNCOTC 6thAD

private ["_pole","_unit"];

_pole = _this select 0;
_unit = _this select 1;


//Spawn Player
waitUntil {!isNil "finalLocation"};
_unit setPos finalLocation;

Share this post


Link to post
Share on other sites

Didn't work I'm afraid :( Clicked set location without any issue however when we then clicked 'teleport' nothing happened - any ideas?

Share this post


Link to post
Share on other sites

So you execute the first code if someone clicks "Set Location" and the second code when someone clicks "teleport"?

Well if yes, that's your answer for your problem: remove the if-query around your first script and it will work.

Use some hint's to output "finalLocation" if you're unsure if the variable is set.

Share this post


Link to post
Share on other sites

Sorry for not responding quicker, I cannot comment on whether or not this has fixed the issue 100% yet (Although logically looking at the code it should have) - once we test it properly during the training, hopefully later today, I will report back here as to whether or not this issue is solved and can be closed.

Share this post


Link to post
Share on other sites

The BIS-functions are part of the modules.pbo which is normally loaded into ArmA2 (OA) automatically on mission start when the Functions Module is placed into your mission.

Unfortunately the documentation in the BIKI is limited to a few commands in the site you already meantioned.

If you want to dig out more of the BIS-functions, either call BIS_fnc_help and use the GUI to traverse through the functions or (what I'm usually doing) get into Arma2/Common/modules.pbo/functions/ and brows through the sqf's or look into the cfgFunctions.hpp for a detailed listing.

Share this post


Link to post
Share on other sites

Sorry guys, still have not been able to test due to dedi server issues - will keep everyone posted.

Share this post


Link to post
Share on other sites

Right guys, sorry for the delay however we tested this out yesterday with several of us and it worked.

Thank you very much for your time Animus - it has all been very very much appreciated :)!

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  

×