Jump to content
Sign in to follow this  
Bulldog Six

remove radio from a unit, run a script once for a connecting player, AND OTHER ISSUES

Recommended Posts

_players_that_see_the_radio_trigger = [unit1, unit2];
{
if (_x == player) then {
	1 setRadioMsg "Alpha Radio wich is shown with this text";
} else {
	// alpha radio not shown.
	1 setRadioMsg "NULL";
};
} foreach [b]|#|[/b]_players_that_see_the_radio_trigger;

for a SP mission you can do this:

...

I need it for MP. I tried the code in a trigger's condition and on activation as well, was'nt accepted ("local variable in global area" at the |#|).

:confused:

Share this post


Link to post
Share on other sites

I think its better to save it as a script and run it from init.sqf to handle JIP also, not 100% sure how that whole thing works.

when using code directly in triggers, you cannot use comments or local variables.

a workaround using local variables is to use spawn:

_null = [] spawn {
_players_that_see_the_radio_trigger = [unit1, unit2];
{
	if (_x == player) then {
		1 setRadioMsg "Alpha Radio wich is shown with this text";
	} else {
		1 setRadioMsg "NULL";
	};
} foreach _players_that_see_the_radio_trigger;
};

btw, some info:

_local_with_underscore_infront = something;

global_with_no_underscore_infront = something;

so you can also simply remove the underscore infront of the _players_that_see_the_radio_trigger as long as you make sure that nothing else is using same name.

Share this post


Link to post
Share on other sites

hey, you're right! it works like a charm when run from a script. thx a lot!

but I still have another tentative draft that needs some attention:

I've got a flying airplane (An2) with a couple playable units set to ride in it's cargo. at mission start the plane follows a couple waypoints and lands at the eastern base to drop off the units (if available - if not he just flies over the base and then moves on to the next WP where it's out of sight where I would love him to unspawn - not exactly sure how to do that).

question: ..is it possible to spawn the vehicle once a player chooses to be one of the units set to be in cargo WITH the unit then being in cargo? (or would the unit just be on the ground and THEN would the plane spawn?

it'd we great if you could show me a way to spawn the plane with the player in cargo, make it follow a couple waypoints or markers via script so it can land at the eastern base to drop off the units in cargo (the current "transport unload" waypoint does this so far automatically). after dropping the units I need it to take-off, fly to another waypoint/marker and unspawn itself there until the next player wants to be one of those units in cargo at which point the flight begins from the beginning.

I also need to disable the ability to switch to the pilot seat and also the ability to bail out. maybe a trigger with timeout so after 2 minutes of flight they can get out?

Edited by Bulldog Six

Share this post


Link to post
Share on other sites

allright, lots of stuff to take into account for this to work properly, it is currently a WIP.

This is just somewhat tested only in MP editor.

place a marker called deletePlane where you want plane to move to for delete after insertion.

ive placed down a empty plane (and NAMED IT important)and moved in my player side pilot into the driver seat using assignAsDriver and moveInDriver.

make the last wp where the plane has a good approach to the airport.

add the wps to the pilot and put this in the plane initline:

_null = this execVM "start.sqf";

place this in the last wp, this will land it at the desired airport, 1 is here the South airport in takistan:

this landAt 1; {unassignVehicle _x} foreach crew this;

start.sqf

if (!isServer) exitWith {};

// here is the name of the players that will make use of the plane insertion at start.
_units = [unit1,unit2];
_plane = _this;

_copyWp_to_placeHolder_Group = {
if (!isServer) exitWith {};
// here we create a new placeholder group for the waypoints.
_newGrp = createGroup (side (driver _this));
// and copy the waypoints to the placeholder group.
_newGrp copyWaypoints (group (driver _this));
_newGrp
};

_track_JIP = {
if (!isServer) exitWith {};
_plane = _this select 0;
_units = _this select 1;
_runIt = true;
while {_runIt} do {
	{
		if (isPlayer _x AND !isNull _x AND !(_x in _plane) AND (_x getVariable ["planeInsertion", true])) then {
			_x assignAsCargo _plane; _x moveInCargo _plane;
			_x setVariable ["planeInsertion", false, true]
		};
	} foreach _units;
	if (isNull _plane OR (_plane getVariable ["planeInsertion", false])) then {_runIt = false};
	sleep 0.01;
};
};

_land_etc = {
if (!isServer) exitWith {};
_plane = _this select 0;
_cnt = _this select 1;

_pilot = driver _plane;
_grp = group _pilot;

// here we wait for the plane to land and the pilot to exit.
waitUntil {!(_pilot in _plane)};

// here we auto kick out anyone still inside the plane.
_plane lock false;
waitUntil {!(locked _plane)};
{unassignVehicle _x; _x action ["getOut", _plane]} forEach crew _plane;

// set another name to the vehicle.
_VarName = format["%1_%2",(vehicleVarName _plane),_cnt];
_plane SetVehicleVarName _VarName;
_plane Call Compile Format ["%1=_This ; PublicVariable ""%1""",_VarName];

// here we wait until all is out then get the pilot back in and make him fly to the marker called deletePlane.
waitUntil {(count (crew _plane)) == 0};
_pilot assignAsDriver _plane;
[_pilot] orderGetIn true;
waitUntil {_pilot in _plane};
_pilot doMove (getMarkerPos "deletePlane");
_grp setSpeedMode "FULL";

// here we wait until the plane is near the marker, then delete it and its pilot and the group.
waitUntil {(_plane distance (getMarkerPos "deletePlane")) < 500};
_pilot setPos (getPos _plane);
{deleteVehicle _x} foreach [_pilot,_plane];
deleteGroup _grp;
};

_type = typeOf _plane;
_typeP = typeOf _pilot;
_pos = getPos _plane;
_name = vehicleVarName _plane;
_cnt = 0;

waitUntil {!isNull (driver _plane)};

// here we run the functions on the first plane (the one placed in editor).
_null = [_plane,_units] spawn _track_JIP;
_null = [_plane,_cnt] spawn _land_etc;
_newGrp = _plane call _copyWp_to_placeHolder_Group;

// after 30 seconds, delete pilot, plane, and group if no players active in the _units array.
sleep 30;
if ( ({isplayer _x} count _units) == 0 ) then {
_pilot = driver _plane;
_grp = group _pilot;
_pilot setPos (getPos _plane);
{deleteVehicle _x} foreach [_pilot,_plane];
deleteGroup _grp;
};
_name = vehicleVarName _plane;
waitUntil {isNull _plane OR (vehicleVarName _plane) != _name};

while {true} do {
// wait until there are players in the units that have not been inserted and the plane has departed from the airport to delete point.
waitUntil {({isplayer _x AND (_x getVariable ["planeInsertion", true])} count _units) != 0 AND (isNull _plane OR (vehicleVarName _plane) != _name)};

// here we recreate the plane.
_plane = createVehicle [_type,_pos,[], 0, "FLY"];
_plane SetVehicleVarName _name;
_plane Call Compile Format ["%1=_This ; PublicVariable ""%1""",_name];

// here we recreate the pilot in the placeholder group and move him into the plane and he should start on first wp.
_pilot = _newGrp createUnit [_typeP, [0,0,200], [], 0, "NONE"];
_pilot assignAsDriver _plane; _pilot moveInDriver _plane;

// make sure pilot is driving before continuing.
waitUntil {(driver _plane) == _pilot};

// here we spawn a code to run to check and add the other units if they join while we are flying.
_null = [_plane,_units] spawn _track_JIP;

// here we run the code for the landing and deleting.
_cnt = _cnt + 1;
_null = [_plane,_cnt] spawn _land_etc;

// here we create a new placeholder group for the next plane.
_newGrp = _plane call _copyWp_to_placeHolder_Group;

// wait 1 second then start over at top.
sleep 1;
};

note: this might work for removing already inserted units from the script:

place in initline of all the units that will use the plane on JIP.

not sure what happens when a uplayer leaves a game, will the variables set to the unit be removed? if so, then all is good, else we need another workaround.

_idx = this addMPEventHandler ["MPRespawn", {
if ((_this select 0) getVariable ["planeInsertion", true]) then {(_this select 0) setVariable ["planeInsertion", false, true]};
}];

Edited by Demonized

Share this post


Link to post
Share on other sites

allright, I've tested it!

spawning the plane with the player in cargo works! :yay:

but can't we just use transport unload at one of the waypoints to make the plane land and drop off everyone in cargo? so the pilot wouldn't have to get out of the plane and get back in again?

anyways, the plane does not take off again after the pilot get's back in :( it moves a couple of meters and then hesitates and stops. he does that a couple of times until at some point he doesn't move forward anymore. so it never flies to the delete point. but the deletion of the airplane (and probably of the AI-pilot as well) works :yay: I flew it myself to the marker and the plane disappeared. "AAAAAAAAAaaaaaaaa.....!!!" *pht!*

also, should I lock the plane?

does that disable the ability to jump out prematurely?

and how should I prevent the player from switching to the pilot seat?

if you like I can upload my mission somewhere and give you the download link so you can check it out if that helps. let me know if you'd take a look at it and I'll upload it with some info on who, what, when and how.

well, many thanks for your help so far mate! I know to appreciate it and I'm eager to read your reply soon! :)

p.s.: is knowledge about linux-code helpful in scripting for the game? I recently started to learn and use linux and some code seemed similar to the game code/language. are you a linux user?

Share this post


Link to post
Share on other sites

hey m8, no i have no idea of linux coding, or any other coding for that matter :D

yes, lock the plane at first, that will prevent players stealing driver seat and ejecting, the spawned planes do it automatically in the script, just forgot to specify it on the editor placed plane.

edit: seems i added the umlock when landed, but forgot to actually lock it in the posted script:

add this after the createVehicle part:

_plane lock true;

did you place the deletemarker and changed the markername to the correct one in the script?

that is what the pilot is moving towards after landing.

If you use TU waypoints, there was atleast in my tests, pilot fly to base, then fly back a long way to get landing aproach and then landed. anoyying as hell.

using the landat command make it seem real, simple test to get correct number since all maps have it.

place this landat x in planes initline where x is number from 0 to how many airports there are on map.

place a AI pilot and yourself in the cargo, no take a ride and figure out wich aiport to use.

btw the numbers are already posted on landAt wiki for the vanilla maps.

Share this post


Link to post
Share on other sites
hey m8, no i have no idea of linux coding, or any other coding for that matter :D

yes, lock the plane at first, that will prevent players stealing driver seat and ejecting, the spawned planes do it automatically in the script, just forgot to specify it on the editor placed plane.

edit: seems i added the umlock when landed, but forgot to actually lock it in the posted script:

add this after the createVehicle part:

_plane lock true;

did you place the deletemarker and changed the markername to the correct one in the script?

that is what the pilot is moving towards after landing.

If you use TU waypoints, there was atleast in my tests, pilot fly to base, then fly back a long way to get landing aproach and then landed. anoyying as hell.

using the landat command make it seem real, simple test to get correct number since all maps have it.

place this landat x in planes initline where x is number from 0 to how many airports there are on map.

place a AI pilot and yourself in the cargo, no take a ride and figure out wich aiport to use.

btw the numbers are already posted on landAt wiki for the vanilla maps.

Sorry for my late responce, I've been quite busy building up a linux system.

Yes, I did as you told me. I placed the waypoint and named it like you told me. I'll test the additional changes and get back to you.

About the Transport Unload waypoint: I've had some experience with it and found out that airplane's autopilot landing always takes a certain approach. The only trick is to place the TU waypoint far enough away (~1000m) from the airport to give the plane enough time to make the landing approach you mentioned [this is planes only, since helo's don't require a certain angle to land somewhere, i.e. takeoff & landing strips]. It seems that it will always land on the closest airport available. So one shouldn't place a TU waypoint exactly on the airport but about a km away from it [for planes, that is]. The plane will merge with the autopilot landing approach and drop the passengers after the landing.

Share this post


Link to post
Share on other sites

if I set the plane to be locked in the editor the player is never kicked out (one can hear the attempt to "open the door", but the plane is still locked). the first plane won't be unlocked in the script (only a recreated plane I assume).

I'll upload you my mission so you can have a look. you'll get the download link in a PM.

Share this post


Link to post
Share on other sites

I ran into the same problems. I finally gave up and left the plane unlocked till the player was out. If they wanted to break the mission more power to them I guess.

Share this post


Link to post
Share on other sites

well, my mission in near to completion. need to run some playtesting with enough people and see how it works. thank you folks so far! your thrones in the everlasting intro credits hall-of-fame are a certainty! your nicknames won't be forgotten :)

here it is:

http://forums.bistudio.com/showthread.php?p=2023519#post2023519

Edited by Bulldog Six

Share this post


Link to post
Share on other sites

I'm trying to modify the plane insertion script Demonized posted earlier so it would work for a insertion helo as well. but I failed in combining some of the code with kylanias planned extraction script where he managed to drop off units without the crew leaving the helo.. ..dunno how to get this to work. (I'll post an excerpt of kylanias script at the end of this post)

this is how I modified it so far:

if (!isServer) exitWith {};

// here is the name of the players that will make use of the helo insertion at start.
_units = [baf_1,baf_2,baf_3];
_helo = _this;

_copyWp_to_placeHolder_Group = {
if (!isServer) exitWith {};
// here we create a new placeholder group for the waypoints.
_newGrp = createGroup (side (driver _this));
// and copy the waypoints to the placeholder group.
_newGrp copyWaypoints (group (driver _this));
_newGrp
};

_track_JIP = {
if (!isServer) exitWith {};
_helo = _this select 0;
_units = _this select 1;
_runIt = true;
while {_runIt} do {
	{
		if (isPlayer _x AND !isNull _x AND !(_x in _helo) AND (_x getVariable ["heloInsertion", true])) then {
			_x assignAsCargo _helo; _x moveInCargo _helo;
			_x setVariable ["heloInsertion", false, true]
		};
	} foreach _units;
	if (isNull _helo OR (_helo getVariable ["heloInsertion", false])) then {_runIt = false};
	sleep 0.01;
};
};

_land_etc = {
if (!isServer) exitWith {};
_helo = _this select 0;
_cnt = _this select 1;

_pilot = driver _helo;
_grp = group _pilot;

_helo lock true;
// here we wait for the helo to land and the pilot to exit.
//	waitUntil {!(_units in _helo)};
waitUntil {this and ((getpos (thislist select 0)) select 2 < 1)};
//	this and ((getpos (thislist select 0)) select 2 < 1)

// here we auto kick out anyone still inside the helo.
_helo lock false;
waitUntil {!(locked _helo)};
waitUntil{{_x in _helo} count units group _units == 0};
{unassignVehicle _units; _units action ["getOut", _helo]} forEach _units _helo;

// set another name to the vehicle.
_VarName = format["%1_%2",(vehicleVarName _helo),_cnt];
_helo SetVehicleVarName _VarName;
_helo Call Compile Format ["%1=_This ; PublicVariable ""%1""",_VarName];

// here we wait until all is out then get the pilot back in and make him fly to the marker called deleteHelo.
//	waitUntil{{_x in _helo} count units group _units == 0};
//	waitUntil {(count (crew _helo)) == 4};
//	_pilot assignAsDriver _helo;
//	[_pilot] orderGetIn true;
//	waitUntil {_pilot in _helo};
_pilot doMove (getMarkerPos "deleteHelo");
_grp setSpeedMode "FULL";

// here we wait until the helo is near the marker, then delete it and its pilot and the group.
waitUntil {(_helo distance (getMarkerPos "deleteHelo")) < 80};
_pilot setPos (getPos _helo);
{deleteVehicle _x} foreach [_pilot,_helo];
deleteGroup _grp;
};

_type = typeOf _helo;
_typeP = typeOf _pilot;
_pos = getPos _helo;
_name = vehicleVarName _helo;
_cnt = 0;

waitUntil {!isNull (driver _helo)};

// here we run the functions on the first helo (the one placed in editor).
_null = [_helo,_units] spawn _track_JIP;
_null = [_helo,_cnt] spawn _land_etc;
_newGrp = _helo call _copyWp_to_placeHolder_Group;

// after 30 seconds, delete pilot, helo, and group if no players active in the _units array.
sleep 30;
if ( ({isplayer _x} count _units) == 0 ) then {
_pilot = driver _helo;
_grp = group _pilot;
_pilot setPos (getPos _helo);
{deleteVehicle _x} foreach [_pilot,_helo];
deleteGroup _grp;
};
_name = vehicleVarName _helo;
waitUntil {isNull _helo OR (vehicleVarName _helo) != _name};

while {true} do {
// wait until there are players in the units that have not been inserted and the helo has departed from the airport to delete point.
waitUntil {({isplayer _x AND (_x getVariable ["heloInsertion", true])} count _units) != 0 AND (isNull _helo OR (vehicleVarName _helo) != _name)};

// here we recreate the helo.
_helo = createVehicle [_type,_pos,[], 0, "FLY"];
_helo lock true;
_helo SetVehicleVarName _name;
_helo Call Compile Format ["%1=_This ; PublicVariable ""%1""",_name];

// here we recreate the pilot in the placeholder group and move him into the helo and he should start on first wp.
_pilot = _newGrp createUnit [_typeP, [0,0,200], [], 0, "NONE"];
_pilot assignAsDriver _helo; _pilot moveInDriver _helo;

// make sure pilot is driving before continuing.
waitUntil {(driver _helo) == _pilot};

// here we spawn a code to run to check and add the other units if they join while we are flying.
_null = [_helo,_units] spawn _track_JIP;

// here we run the code for the landing and deleting.
_cnt = _cnt + 1;
_null = [_helo,_cnt] spawn _land_etc;

// here we create a new placeholder group for the next helo.
_newGrp = _helo call _copyWp_to_placeHolder_Group;

// wait 1 second then start over at top.
sleep 1;
};

could someone please check the part where the player is supposed to get out of the helo?

what I can't get to work is:

-helo (chinook) lands at transport unload waypoint (keeps engines running)

-helo unlocks at touchdown (or 1m height)

-all players are autokicked out of helo (not the crew)

-helo takes off again to the deleteHelo marker where it's deleted

so far the helo lands, shuts the engine off, the tailgunner gets out, gets in as copilot and the chinook stays on the ground forever.

can anyone find the errors in the script?

I commented some stuff out because I wanted the crew to stay inside, but the tailgunner still gets out. (total helo crew is 4, because the helo is a chinook; pilot, gunner left, gunner right and tailgunner).

Cheers

excerpt of kylanias planned extraction script:

// ... off we go by setting a TRANSPORT UNLOAD waypoint.  
// It'll auto boot the leader once there, but he'll have to tell the others to get out.
wp1 = _chGroup addwaypoint [_end, 20];
wp1 setwaypointtype "TR UNLOAD";
wp1 setWaypointStatements ["","transportHelo land ""GET OUT"""];

// Wait till the player's group is out of the helo.
waitUntil{{_x in transporthelo} count units group _unit == 0};

// Once they are out, set a waypoint back to the start and clean up by deleting the helo and landing pads.
wp2 = _chGroup addwaypoint [_start, 20];
wp2 setwaypointtype "MOVE";
wp2 setWaypointStatements ["true","{deleteVehicle _x} forEach crew transporthelo; deletevehicle transporthelo;"];
deleteVehicle _lzPickup;
deleteVehicle _lzDropOff;

Edited by Bulldog Six

Share this post


Link to post
Share on other sites

This probably is nothing to do with it but is this correct?

{unassignVehicle _units; _units action ["getOut", _helo]} forEach _units _helo;

Shouldn't it be

{unassignVehicle _x; _x action ["getOut", _helo]} forEach units _units;

As you say they're getting out so that probably isn't it but I've never seen it written as you have it.

I just re-read and only the tail gunner gets out, this may be why then.

Edited by F2k Sel

Share this post


Link to post
Share on other sites
This probably is nothing to do with it but is this correct?

{unassignVehicle _units; _units action ["getOut", _helo]} forEach _units _helo;

Shouldn't it be

{unassignVehicle _x; _x action ["getOut", _helo]} forEach units _units;

As you say they're getting out so that probably isn't it but I've never seen it written as you have it.

I just re-read and only the tail gunner gets out, this may be why then.

you're right, I've altered that part from Demonized's code for the plane insertion of OPFOR units (which is similar to your code):

{unassignVehicle _x; _x action ["getOut", _plane]} forEach crew _plane;

I tried to alter in it a way so that the pilot stays in the plane while everyone else get's kicked out. I'm still a noob regarding scripting so I was experimenting with it but I got some things wrong appearantly so my altered version didn't work.

I grew tired of trying to learn this language so I give up. I know what would be a good mission design but unfortunately I lack the coding skills to realize what I'm aiming for. It would be much easier if I had a good scripter with whom I could talk via skype or teamspeak about what I need done in coding instead of having to put it into writing in this forum - or if I could code it myself for that matter. But this code language is beyond my understanding. I'll just leave it as is until I find another way to do it.

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  

×