Jump to content
  • 0

Multiple Cursor Target Options?


Mochan

Question

So I am making a fast travel system, I tried using a action menu style system, but it never worked, so I thought if I add all the conditions into the self actions as different parts it will add each bit? 

//########################### Fast Travel Start! Start #############################################
if ( cursorTarget isKindOf "SatPhone" && (player distance cursorTarget) < 2 ) then {
	if (s_player_Phone < 0) then {
    	s_player_Phone = player addaction[("<t color=""#0000ff"">" + ("Fast Travel Info!") +"</t>"),"fasttravel\info.sqf","",5,false,true,"", ""];
    };
} else {
	player removeAction s_player_Phone;
	s_player_Phone = -1;
};

if ( cursorTarget isKindOf "SatPhone" && (player distance cursorTarget) < 2 ) then {
	if (s_player_Phone1 < 0) then {
    	s_player_Phone1 = player addaction[("<t color=""#0000ff"">" + ("Stary Trader!") +"</t>"),"fasttravel\stary.sqf","",5,false,true,"", ""];
    };
} else {
	player removeAction s_player_Phone1;
	s_player_Phone1 = -1;
};

if ( cursorTarget isKindOf "SatPhone" && (player distance cursorTarget) < 2 ) then {
	if (s_player_Phone2 < 0) then {
    	s_player_Phone2 = player addaction[("<t color=""#0000ff"">" + ("Bash Trader!") +"</t>"),"fasttravel\bash.sqf","",5,false,true,"", ""];
    };
} else {
	player removeAction s_player_Phone2;
	s_player_Phone2 = -1;
};

if ( cursorTarget isKindOf "SatPhone" && (player distance cursorTarget) < 2 ) then {
	if (s_player_Phone 3< 0) then {
    	s_player_Phone3 = player addaction[("<t color=""#0000ff"">" + ("Klen Trader") +"</t>"),"fasttravel\klen.sqf","",5,false,true,"", ""];
    };
} else {
	player removeAction s_player_Phone3;
	s_player_Phone3 = -1;
};

if ( cursorTarget isKindOf "SatPhone" && (player distance cursorTarget) < 2 ) then {
	if (s_player_Phone4 < 0) then {
    	s_player_Phone4 = player addaction[("<t color=""#0000ff"">" + ("Hero Trader!") +"</t>"),"fasttravel\hero.sqf","",5,false,true,"", ""];
    };
} else {
	player removeAction s_player_Phone4;
	s_player_Phone4 = -1;
};

if ( cursorTarget isKindOf "SatPhone" && (player distance cursorTarget) < 2 ) then {
	if (s_player_Phone5 < 0) then {
    	s_player_Phone5 = player addaction[("<t color=""#0000ff"">" + ("Kamenka Town!") +"</t>"),"fasttravel\kamenka.sqf","",5,false,true,"", ""];
    };
} else {
	player removeAction s_player_Phone5;
	s_player_Phone5 = -1;
};

if ( cursorTarget isKindOf "SatPhone" && (player distance cursorTarget) < 2 ) then {
	if (s_player_Phone6 < 0) then {
    	s_player_Phone6 = player addaction[("<t color=""#0000ff"">" + ("Elektro!") +"</t>"),"fasttravel\elektro!.sqf","",5,false,true,"", ""];
    };
} else {
	player removeAction s_player_Phone6;
	s_player_Phone6 = -1;
};

if ( cursorTarget isKindOf "SatPhone" && (player distance cursorTarget) < 2 ) then {
	if (s_player_Phone7 < 0) then {
    	s_player_Phone7 = player addaction[("<t color=""#0000ff"">" + ("Prig!") +"</t>"),"fasttravel\prig.sqf","",5,false,true,"", ""];
    };
} else {
	player removeAction s_player_Phone7;
	s_player_Phone7 = -1;
};

if ( cursorTarget isKindOf "SatPhone" && (player distance cursorTarget) < 2 ) then {
	if (s_player_Phone < 0) then {
    	s_player_Phone = player addaction[("<t color=""#0000ff"">" + ("Berezino") +"</t>"),"fasttravel\berezino.sqf","",5,false,true,"", ""];
    };
} else {
	player removeAction s_player_Phone;
	s_player_Phone = -1;
};

if ( cursorTarget isKindOf "SatPhone" && (player distance cursorTarget) < 2 ) then {
	if (s_player_Phone9 < 0) then {
    	s_player_Phone9 = player addaction[("<t color=""#0000ff"">" + ("test travel") +"</t>"),"fasttravel\test.sqf","",5,false,true,"", ""];
    };
} else {
	player removeAction s_player_Phone9;
	s_player_Phone9 = -1;
};
//########################### Fast Travel Stop!##############################################

But now when I look at the satphone I don#t even get a option? 

 

~mochan

Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

My self actions never seem to work unless i set the player speed to less than 5

Something like this

if ( cursorTarget isKindOf "SatPhone" && (player distance cursorTarget) < 2  && (speed player <= 1)) then {
    if (s_player_Phone6 < 0) then {
    s_player_Phone6 = player addaction[("<t color=""#0000ff"">" + ("Elektro!") +"</t>"),"fasttravel\elektro!.sqf","",5,false,true,"", ""];
};
} else {
    player removeAction s_player_Phone6;
    s_player_Phone6 = -1;
};

also why not try this: (Keep in mind im still really new at arma scripting)

 

 

fastTravel\init.sqf 

_phone = "SatPhone"

if ((cursorTarget == _phone ) and  ((player distance _phone) < 5)) 
then
{
 _phone addaction[("<t color=""#ff0000"">" + ("Fast Travel!") +"</t>"),"fasttravel\menu.sqf",0,false,true,"", ""];
}

fasttravel\menu.sqf

path = "fasttravel\"; 
exstr = 'player execVM "'+path+'%1"';


Travel = 
[
["",true],
["---Fast Travel---", [-1], "", -5, [["expression", ""]], "1", "0"],
["", [-1], "", -5, [["expression", ""]], "1", "0"],
    ["Klen Trader!", [],  "", -5, [["expression", format[exstr,"klen.sqf"]]], "1", "1"],
    ["Hero Trader!", [],  "", -5, [["expression", format[exstr,"hero.sqf"]]], "1", "1"], 
    ["Exit", [], "", -3, [["expression", ""]], "1", "1"]  //no comma at the last one!
];
showCommandingMenu "#USER:Travel";
};
 

I'm actually on the search for something and came across this. Thought i might be able to help others or OP

Link to comment
Share on other sites

  • 0

It's always good to keep everything short as possible.

//fn_selfactions
if (cursorTarget isKindOf "??????" and (player distance cursorTarget) < 5) then {
	if (s_player_travel < 0) then {
    	s_player_travel = player addaction ["Fast Travel","travel_menu.sqf","",5,false,true,"", ""];
    };
} else {
	player removeAction s_player_travel;
	s_player_travel = -1;
};


//travel_menu.sqf
travelmenu =
[
    ["",true],
        ["Choose Your Destination:", [-1], "", -5, [["expression", ""]], "1", "0"],
            ["", [-1], "", -5, [["expression", ""]], "1", "0"],
			["Bash Trader", [2],  "", -5, [["expression", "['Bash Trader',[4018.4233, 11678.521, 0.02]] execVM 'fast_travel.sqf'"]], "1", "1"],
			["Klen Trader", [3],  "", -5, [["expression", "['Klen Trader',[11396.401, 11368.146, 0.02]] execVM 'fast_travel.sqf'"]], "1", "1"],
            ["", [-1], "", -5, [["expression", ""]], "1", "0"],
        ["Exit", [-1], "", -3, [["expression", ""]], "1", "1"]
];
showCommandingMenu "#USER:travelmenu";


//fast_travel.sqf
_place = _this select 0;
_coords = _this select 1;

if ("??????" in magazines player) then {
	player removeMagazine "?????";
	titleText [format["Flying to %1...",_place],"BLACK OUT",1];
	sleep 5;
	player setPosATL _coords;
	titleText ["","WHITE IN",1];
	titleText [format["You have arrived to %1!",_place],"PLAIN DOWN"];
} else {
	cutText ["You need ??????? to fast travel!", "PLAIN DOWN"];	
};
Link to comment
Share on other sites

  • 0

no, thats the stupidest thing i ever heard ... typeOf will return the classname and he aparently wants to compare that (wich btw is case sensitive) rather than using isKindOf.

yes it would fix it, because that's exactly what he wants - to check classname against the object in front of cursor. Stop trolling and give some actual code or advice instead of bashing someone

Link to comment
Share on other sites

  • 0

yes it would fix it, because that's exactly what he wants - to check classname against the object in front of cursor. Stop trolling and give some actual code or advice instead of bashing someone

 

Sukkaed already posted code pretty much how i would have written it (i think he read my mind) ... only thing i would have done diffrent from that, would be to set cursortarget to a variable before the if statement, to ensure its same in both statements.

 

what you said was wrong, isKindOf works for any object and will recognize exact class- or a base-class name, not to mention it is not case sensitive.

Link to comment
Share on other sites

  • 0

Sukkaed already posted code pretty much how i would have written it (i think he read my mind) ... only thing i would have done diffrent from that, would be to set cursortarget to a variable before the if statement, to ensure its same in both statements.

 

what you said was wrong, isKindOf works for any object and will recognize exact class- or a base-class name, not to mention it is not case sensitive.

That's more like it. Yes you are correct, it works for base class names, apologies for misleading info, I didn't mean those 2 specific classes, but classes like those in general. Afaik, isKindOf is also quite limited

Link to comment
Share on other sites

  • 0

We could short this all in one file but is it good idea to make any unnecessary public variables?

travel = 
{
	_place = _this select 0;
	_coords = _this select 1;
	if ("??????" in magazines player) then {
		player removeMagazine "?????";
		titleText [format["Flying to %1...",_place],"BLACK OUT",1];
		sleep 5;
		player setPosATL _coords;
		titleText ["","WHITE IN",1];
		titleText [format["You have arrived to %1!",_place],"PLAIN DOWN"];
	} else {
		cutText ["You need ??????? to fast travel!", "PLAIN DOWN"];	
	};
};
travelmenu =
[
    ["",true],
        ["Choose Your Destination:", [-1], "", -5, [["expression", ""]], "1", "0"],
            ["", [-1], "", -5, [["expression", ""]], "1", "0"],
			["Bash Trader", [2],  "", -5, [["expression", "['Bash Trader',[4018.4233, 11678.521, 0.02]] spawn travel"]], "1", "1"],
			["Klen Trader", [3],  "", -5, [["expression", "['Klen Trader',[11396.401, 11368.146, 0.02]] spawn travel"]], "1", "1"],
            ["", [-1], "", -5, [["expression", ""]], "1", "0"],
        ["Exit", [-1], "", -3, [["expression", ""]], "1", "1"]
];
showCommandingMenu "#USER:travelmenu";
Link to comment
Share on other sites

  • 0

 

We could short this all in one file but is it good idea to make any unnecessary public variables?

 

go with the script option instead of the function ... you have nothing you need to return anyway and imho i dont think it matter if its a little slower.

 

also sukkaed you example will load the function each time you run the script, in such case you can speed up the process significantly (wont change much in this exact case tho, but usually) by just checking if the variable isnil and if not then no need to load the function again.

Link to comment
Share on other sites

  • 0

Good point. Like this?

if (isnil ("travel")) then {
	travel = 
	{
		_place = _this select 0;
		_coords = _this select 1;
		if ("??????" in magazines player) then {
			player removeMagazine "?????";
			titleText [format["Flying to %1...",_place],"BLACK OUT",1];
			sleep 5;
			player setPosATL _coords;
			titleText ["","WHITE IN",1];
			titleText [format["You have arrived to %1!",_place],"PLAIN DOWN"];
		} else {
			cutText ["You need ??????? to fast travel!", "PLAIN DOWN"];	
		};
	};
};
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...