Jump to content
Sign in to follow this  
wiggum2

Very strange problem with teleport script

Recommended Posts

Hi !

This is my teleport script:

private ["_canteleport1","_canteleport2"];

_canteleport1 = nil;
_canteleport2 = nil;
setPosDone = 0;
openMap true;

onMapSingleClick { 
   onMapSingleClick {};
   teleportloc = _pos;     
   setPosDone = 1; 
};
waitUntil {setPosDone == 1};

// If color is blue then check if position is inside marker area
if (getMarkerColor "re1" == "ColorBlue") then {
   _canteleport1 = [teleportloc,"re1"] call Check_Pos;
};
if (getMarkerColor "re2" == "ColorBlue") then {
   _canteleport2 = [teleportloc,"re2"] call Check_Pos;
};

hint format["%1", _canteleport1];

// If no position available then exit
if (isNil "_canteleport1" && isNil "_canteleport2") exitWith {
   hint "No positions for teleport !";
   openMap false;
};

// If position is correct then teleport else show fail hint
if ((_canteleport1) || (_canteleport2)) then {
   player setpos teleportloc;
   openMap false;
} else {
   hint "Wrong position for teleport !";
   openMap false;
};

As you can see i want to be able to check if the mapclick position is inside a trigger area (thats what Check_Pos does) and then teleport the player there if the marker color is blue. If no area marker is blue then a hint will be shown.

If at least one area marker is blue but the player clicks at another location not inside the marker area then a hint is also shown.

Should work...but does not.

As you can see i use a hint format to check if _canteleport1 is true.

This works perfectly fine !

My problem is the last if condition that for some strange reason refuses to work...

I mean, what wrong with it ?

The funny thing is that if i remove the getMarkerColor check infront of both _canteleport then it works... :936:

I already spent to much time with this, maybe you can help me with this.

Thanks !

EDIT:

_canteleport1 = nil;

_canteleport2 = nil;

This is not the error, i tried it with and without !

Share this post


Link to post
Share on other sites

I think it is

_canteleport1 = nil;

_canteleport2 = nil;

You are mixing false/true with nil in the final condition

if only one is true the other is nil and that is wrong in this check as your checking for true or false.

if ((_canteleport1) || (_canteleport2))

private ["_canteleport1","_canteleport2"];

_canteleport1 = false;
_canteleport2 = false;
setPosDone = 0;
openMap true;

onMapSingleClick { 
   onMapSingleClick {};
   teleportloc = _pos;     
   setPosDone = 1; 
};
waitUntil {setPosDone == 1};

// If color is blue then check if position is inside marker area
if (getMarkerColor "re1" == "ColorBlue") then {
   _canteleport1 = [teleportloc,"re1"] call Check_Pos;
};
if (getMarkerColor "re2" == "ColorBlue") then {
   _canteleport2 = [teleportloc,"re2"] call Check_Pos;
};
hint format["%1", _canteleport1];

// If no position available then exit
if (!_canteleport1 && !_canteleport2) exitWith {
   hint "No positions for teleport !";
   openMap false;
};

// If position is correct then teleport else show fail hint
if  ((_canteleport1) or (_canteleport2)) then {
   player setpos teleportloc;
   openMap false;
} else {
   hint "Wrong position for teleport !";
   openMap false;
}; 

I could be wrong though, also will the the else ever run. I think the exitwith will prevent that part ever working.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Thanks F2k Sel, that solved my problem ! :)

@ Giallustio

I think thats not possible because you cant use local variables inside the onMapSingleClick.

Share this post


Link to post
Share on other sites

onMapSingleClick 
{ 
if (getMarkerColor "re1" == "ColorBlue") then 
{
	if (_pos distance getMarkerPos "red1" < 250) then
	{
		player setpos _pos;
	}
	else
	{
		hint "Wrong position for teleport !";
	};
};
if (getMarkerColor "re2" == "ColorBlue") then 
{
	if (_pos distance getMarkerPos "red2" < 250) then
	{
		player setpos _pos;
	}
	else
	{
		hint "Wrong position for teleport !";
	};
};
if (getMarkerColor "re1" != "ColorBlue" && getMarkerColor "re2" != "ColorBlue") then
{
	hint "You can't teleport or whatever u want";
};
};

Not tested but should work. :)

That's possible :p

Share this post


Link to post
Share on other sites
I think thats not possible because you cant use local variables inside the onMapSingleClick.

Hi,

Yes it is perfectly possible, why wouldn't it?

_neo_

Share this post


Link to post
Share on other sites
Not tested but should work. :)
That's possible :p[/quote]

Are you also able to pass paramters to onMapSingleClick? Like

[code]_FireMissionPos = [];
onMapSingleClick {_FireMissionPos = _pos};

_FireMissionPos = [_FireMissionPos select 0, _FireMissionPos select 1, getTerrainHeightASL _FireMissionPos];
execute ARTY MODULE firemission

Share this post


Link to post
Share on other sites

Do you really need to?

onMapSingleClick 
{
  _FireMissionPos = _pos;
  _FireMissionPos set [2, getTerrainHeightASL _FireMissionPos];
  //execute ARTY MODULE firemission
};

If you do, then just use global variables instead.

_neo_

Share this post


Link to post
Share on other sites

@ neokika

Thats what i was talking about.

Its not possible to pass local variables in or out of the onMapSingleClick, you have to use globals for that.

Share this post


Link to post
Share on other sites
@ neokika

Thats what i was talking about.

Its not possible to pass local variables in or out of the onMapSingleClick, you have to use globals for that.

My code doesn't work? You don't need to pass any arg to the onMapSingleClick, just work around...

Share this post


Link to post
Share on other sites
Do you really need to?

onMapSingleClick 
{
  _FireMissionPos = _pos;
  _FireMissionPos set [2, getTerrainHeightASL _FireMissionPos];
  //execute ARTY MODULE firemission
};

If you do, then just use global variables instead.

_neo_

for this particular instance yes, because the arty module is dynamically created and removed (and so appending global variables is too cumbersome for me) also, i need to be able to detect if more than one mortar team is present, to allow the ability to work for other teams.

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  

×