Jump to content

Recommended Posts

Essentially i'm try to make my own take on an invade and annex server thats team oriented. currently im working on adding a flagpole teleportation mechanic that will teleport you to your squad leader if you have a squad leader and will get you in the fight faster. so ive spent the better part of the day doing this....

 

Quote

this addAction ["<t color= '#FFFF00'>Teleport to Squad Leader</t>", {
 
 if ((SquadLeader_1) == (_this select 1)) then{
 hint "You are the Squad Leader, Figure out a ride for your squad!";}
 else{
  if ((SquadLeader_2) == (_this select 1))
  then{
  hint "You are the Squad Leader, Figure out a ride for your squad!"
  }
  else{
   if(group (_this select 1) == group SquadLeader_1)
   then{
   hint "You will be teleported in 10 seconds.";
   sleep 1;
   hint "You will be teleported in 9 seconds.";
   sleep 1;
   hint "You will be teleported in 8 seconds.";
   sleep 1;
   hint "You will be teleported in 7 seconds.";
   sleep 1;
   hint "You will be teleported in 6 seconds.";
   sleep 1;
   hint "You will be teleported in 5 seconds.";
   sleep 1;
   hint "You will be teleported in 4 seconds.";
   sleep 1;
   hint "You will be teleported in 3 seconds.";
   sleep 1;
   hint "You will be teleported in 2 seconds.";
   sleep 1;
   hint "You will be teleported in 1 second.";
   sleep 1;
   
   (_this select 1) setPos (getMarkerPos "SquadTeleportLocation_1")
   }
   else{ 
    if(group (_this select 1) == group SquadLeader_2) 
    then{
    hint "You will be teleported in 10 seconds.";
    sleep 1;
    hint "You will be teleported in 9 seconds.";
    sleep 1;
    hint "You will be teleported in 8 seconds.";
    sleep 1;
    hint "You will be teleported in 7 seconds.";
    sleep 1;
    hint "You will be teleported in 6 seconds.";
    sleep 1;
    hint "You will be teleported in 5 seconds.";
    sleep 1;
    hint "You will be teleported in 4 seconds.";
    sleep 1;
    hint "You will be teleported in 3 seconds.";
    sleep 1;
    hint "You will be teleported in 2 seconds.";
    sleep 1;
    hint "You will be teleported in 1 second.";
    sleep 1;
    
    (_this select 1) setPos (getMarkerPos "SquadTeleportLocation_2")
    } 
    else{
     if(group (_this select 1) == group COC
     ) 
     then{hint "You're an officer. Just order your own ride."
     } 
     else{
      if (group (_this select 1) == group Pilot) 
      then{hint "Why dont you go take your helicopter?"} 
      else {
       if(group (_this select 1) == group Recon)
       then{hint "You're Recon, Right? Looks like your humping it  in."}
       else{hint "Theres no squad leader on right now"}
      };
     };
    };
   };
  };
 };
}]

im sure some of you are gagging at that, sorry im not very proficient in eden editor....or anything particularily...

nonetheless this works as intended except it'll throw an error if there is nobody playing the character with their specific variable attached IE; SquadLeader_1, SquadLeader_2, Pilot, COC, Recon. for what i intend that's fine but i'd like to clean it up and offer a "Teleportation is down right now" for the characters that can teleport atleast. i've been trying to find some way to integrate try throw catch, but cant seem to find a way to set it up proper.

 

any tips?

Share this post


Link to post
Share on other sites
Spoiler

this addAction ["<t color= '#FFFF00'>Teleport to Squad Leader</t>", {
	params[ "_target", "_caller", "_ID", "_args" ];

	_fnc_teleport = {
		params[ "_unit", "_marker" ];

		for "_count" from 10 to 1 step -1 do {
			hint format[ "You will be teleported in %1 seconds", _count ];
			sleep 1;
		};
		_unit setPos getMarkerPos _marker;
	};

	switch ( true ) do {
		case ( !isNil "SquadLeader_1" && { !isNull SquadLeader_1 } && { SquadLeader_1 == _caller } ) : {
			hint "You are the Squad Leader, Figure out a ride for your squad!";
		};
		case ( !isNil "SquadLeader_2" && { !isNull SquadLeader_2 } && { SquadLeader_2 == _caller } ) : {
			hint "You are the Squad Leader, Figure out a ride for your squad!";
		};
		case ( !isNil "SquadLeader_1" && { !isNull SquadLeader_1 } && { group _caller == group SquadLeader_1 } ) : {
			[ _caller, "SquadTeleportLocation_1" ] spawn _fnc_teleport;
		};
		case ( !isNil "SquadLeader_2" && { !isNull SquadLeader_2 } && { group _caller == group SquadLeader_2 } ) : {
			[ _caller, "SquadTeleportLocation_2" ] spawn _fnc_teleport;
		};
		case ( !isNil "COC" && { !isNull COC } && { group _caller == group COC } ) : {
			hint "You're an officer. Just order your own ride."
		};
		case ( !isNil "Pilot" && { !isNull Pilot } && { group _caller == group Pilot } ) : {
			hint "Why dont you go take your helicopter?";
		};
		case ( !isNil "Recon" &&{ !isNull Recon } && { group _caller == group Recon } ) : {
			hint "You're Recon, Right? Looks like your humping it in.";
		};
		default { hint "Theres no squad leader on right now"; };
	};
}];

 

 

!isNil "SquadLeader_1" && { !isNull SquadLeader_1 } && { SquadLeader_1 == _caller }

If the variable exist ( !isNil "SquadLeader_1" ) then and only then( {  } Lazy Evaluation ) make sure the value is not a null object( a player has joined and then left the position SquadLeader_1 ) compare the _caller against the variable

  • Like 1

Share this post


Link to post
Share on other sites

Hi. welcome to the forum!

 

2 advices:

 

1) Organize your Code

description.ext:

class CfgFunctions
{
  class JF
  {
    class Scripts
    {
      class SetPos {file = "SetPos.sqf"};
    }
  }
}

initPlayerLocal.sqf

player addAction
[
  "<t color= '#FFFF00'>Teleport to Squad Leader</t>",
  {[player] spawn JF_fnc_SetPos}
]

SetPos.sqf

params ["_unit"];

private _counter =
{
  for "_i" from 10 to 1 step -1 do
  {
    hint format ["You will be teleported in %1 seconds.", _i];
    sleep 1;
  };
};

private _isLeader = 0;

switch (_unit) do
{
  case SquadLeader_1: {hint "You are the Squad Leader, Figure out a ride for your squad!"; _isLeader = 1};
  case SquadLeader_2: {hint "You are the Squad Leader, Figure out a ride for your squad!"; _isLeader = 1};
};

if (_isLeader != 1) then
{
  switch (group _unit) do
  {
    case (group SquadLeader_1): {[] call _counter; _unit setPos (getMarkerPos "SquadTeleportLocation_1"); hint "0"};
    case (group SquadLeader_2): {[] call _counter; _unit setPos (getMarkerPos "SquadTeleportLocation_2"); hint "0"};
    case (group COC): {hint "You're an officer. Just order your own ride."};
    case (group Pilot): {hint "Why dont you go take your helicopter?"};
    case (group Recon): {hint "You're Recon, Right? Looks like your humping it  in."};
  };
};

//i know, it`s awful

 

2) Read some documentations about MP scripting

Your code is fine, but it isn`t ready for MP.

You said that you get an error when you want to spawn on the unit:

That`s the case because most likely you do not play with the leader as an ai unit. 

 

For Example:

Your leader`s name is SquadLeader_1. If this unit isn`t played by ai or a player it simply does not exist!

You Script wants to compare the group of the player with the group of a non existing unit. That can`t work!

So double check and rethink your code.

In the beginning it`s really difficult!

Share this post


Link to post
Share on other sites
12 minutes ago, Larrow said:
  Reveal hidden contents


this addAction ["<t color= '#FFFF00'>Teleport to Squad Leader</t>", {
	params[ "_target", "_caller", "_ID", "_args" ];

	_fnc_teleport = {
		params[ "_unit", "_marker" ];

		for "_count" from 10 to 1 step -1 do {
			hint format[ "You will be teleported in %1 seconds", _count ];
			sleep 1;
		};
		_unit setPos getMarkerPos _marker;
	};

	switch ( true ) do {
		case ( !isNil "SquadLeader_1" && { !isNull SquadLeader_1 } && { SquadLeader_1 == _caller } ) : {
			hint "You are the Squad Leader, Figure out a ride for your squad!";
		};
		case ( !isNil "SquadLeader_2" && { !isNull SquadLeader_2 } && { SquadLeader_2 == _caller } ) : {
			hint "You are the Squad Leader, Figure out a ride for your squad!";
		};
		case ( !isNil "SquadLeader_1" && { !isNull SquadLeader_1 } && { group _caller == group SquadLeader_1 } ) : {
			[ _caller, "SquadTeleportLocation_1" ] spawn _fnc_teleport;
		};
		case ( !isNil "SquadLeader_2" && { !isNull SquadLeader_2 } && { group _caller == group SquadLeader_2 } ) : {
			[ _caller, "SquadTeleportLocation_2" ] spawn _fnc_teleport;
		};
		case ( !isNil "COC" && { !isNull COC } && { group _caller == group COC } ) : {
			hint "You're an officer. Just order your own ride."
		};
		case ( !isNil "Pilot" && { !isNull Pilot } && { group _caller == group Pilot } ) : {
			hint "Why dont you go take your helicopter?";
		};
		case ( !isNil "Recon" &&{ !isNull Recon } && { group _caller == group Recon } ) : {
			hint "You're Recon, Right? Looks like your humping it in.";
		};
		default { hint "Theres no squad leader on right now"; };
	};
}];

 

 


!isNil "SquadLeader_1" && { !isNull SquadLeader_1 } && { SquadLeader_1 == _caller }

If the variable exist ( !isNil "SquadLeader_1" ) then and only then( {  } Lazy Evaluation ) make sure the value is not a null object( a player has joined and then left the position SquadLeader_1 ) compare the _caller against the variable

Didn`t refresh the page and @Larrow was faster 🙂

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

×