Saftdraft 0 Posted October 3, 2022 Hello everyone, I was hoping to find some help here. I just recently started tinkering with scripts to make missions for me and my friends to play. I want to implement a Huron that will fly to one randomly selected marker from an array of markers and place a cargo container, then fly off. The heli should start after a given time after mission start. For that I have a script that works in singleplayer, but not in multiplayer. 1) I have a systemchat message that displays when the script runs but it only shows on my machine. What do I need to do here? the relevant code is: systemChat str(format ["You can hear a Helicopter in the distance."]); 2) If I launch the mission in Editor MP, the debug message informs me that the variable _heli for my huron is "undefined variable in expression". I don't understand why it considers it "undefined". the relevant code is this: _heli_spawn = [_spawn, 0, _heli_class, West] call BIS_fnc_spawnVehicle; _heli = _heli_spawn select 0; ---------------------------------------------------------- Whole script is this (taken from some guy in the forum and slightly edited for my needs): Spoiler //_delay = 1200 + random 600; // 20min plus 0-10min delay //sleep _delay; if (!isServer) exitWith {}; // pull class names from arguments passed through execVM call { _heli_class = _this select 0; _cargo_class = _this select 1; }; // marker positions _spawn = [0,0,0];//_this select 2; _spawn = getMarkerPos _spawn; systemChat str(format ["You can hear a Helicopter in the distance."]); _destination = selectRandom ["Marker_1","Marker_2","Marker_3","Marker_4","Marker_5","Marker_6","Marker_7"]; _destination = getMarkerPos _destination; systemChat str(format ["Destination: %1",_destination]); // how often to run _delay = 1; // spawn invisble helipad object for heli to target _helipad_obj = "Land_HelipadEmpty_F" createVehicle _destination; // spawn heli _heli_spawn = [_spawn, 0, _heli_class, West] call BIS_fnc_spawnVehicle; _heli = _heli_spawn select 0; // safeguard it _heli setCaptive True; _heli allowDamage false; // create cargo and slingload it _cargo = createVehicle [_cargo_class, [0,0,50], [], 0, ""]; _cargo addAction ["Inspect","juggernaut_equipment.sqf"]; sleep 0.5; _cargo_Mass = getMass _cargo; _cargo setMass [1,0]; _heli setSlingLoad _cargo; sleep 0.5; // get heli's crew and assign waypoints _heli_grp = group (driver _heli); //systemChat str(format ["Heli Group: %1",_heli_grp]); _heli_grp setFormation "WEDGE"; _heli_grp setBehaviour "SAFE"; _heli_grp setSpeedMode "NORMAL"; // delete all of heli crews' waypoints while {(count (wayPoints (_heli_grp) )) > 0} do { deleteWaypoint ((wayPoints (_heli_grp)) select 0); sleep 0.5; }; // tell heli to move to and attempt to land at the destination _mvWP = _heli_grp addWaypoint [_destination,1]; _mvWP setWaypointType "UNHOOK"; // grab the time for use later _time = serverTime; //Pause script and wait for heli to fly to destination or until 60 seconds pass to prevent endless wait // grab the time again for use in next endless wait prevention _time = serverTime; // Pause script until the cargo is less than 1m off the deck or until 15 seconds pass to prevent endless wait WaitUntil {((((position _cargo) select 2) < 0.6) || (serverTime > _time + 15))}; // delete everything if something happened and heli never made it to the destination if ((_heli distance2D _helipad_obj) > 25) then { deleteVehicle _cargo; {deleteVehicle _x} forEach crew _heli; deleteVehicle _heli; systemChat str(format ["Something went wrong! heli, crew, and cargo deleted. Trying again in %1 seconds.",_delay]); } else { //detatch the cargo _heli setSlingLoad ObjNull; //prevent cargo from being destroyed _cargo SetVelocity [0,0,-3]; sleep 0.5; _cargo setPos [((position _cargo) select 0), ((position _cargo) select 1), 1]; _cargo SetVelocity [0,0,0]; _cargo setMass [_cargo_mass,0]; systemChat "The helicopter dropped something off, it might prove useful."; //create task to inspect sleep 2; _tsk2 = ["task2", true, ["Secure the cargo.","Find the dropped cargo and secure it.",""],nil, "ASSIGNED", 0, true, true,"",true] call BIS_fnc_setTask; // give heli a new waypoint back to spawn & set it to current while {(count (wayPoints (_heli_grp) )) > 0} do { deleteWaypoint ((wayPoints (_heli_grp)) select 0); sleep 0.5; }; _dieWP = _heli_grp addWaypoint [_spawn,1]; _dieWP setWaypointType "MOVE"; _heli flyInHeight 60; _heli_grp setCurrentWayPoint [_heli_grp,1]; // grab time one last time for same reason as before _time = serverTime; // Pause script until the Heli is within 100m of spawnpoint or until 30 seconds pass to prevent endless wait WaitUntil {(((_heli distance2D _spawn) < 100) || (serverTime > _time + 30))}; //systemChat "Cargo delivered and Heli is back at spawn, cleaning up."; {deleteVehicle _x} forEach crew _heli + [_heli]; }; P.S. i have the following in the init file: 0 = ["B_Heli_Transport_03_F","Land_Cargo10_military_green_F","spawn","destination",10] execVM "slingload.sqf"; Thank you guys in advance. Share this post Link to post Share on other sites
major-stiffy 269 Posted October 3, 2022 6 minutes ago, Saftdraft said: systemChat str(format ["You can hear a Helicopter in the distance."]); Try: ["Your text here"] remoteExec ["systemChat", _eachHumamPlayer]; Share this post Link to post Share on other sites
Saftdraft 0 Posted October 3, 2022 2 minutes ago, major-stiffy said: Try: ["Your text here"] remoteExec ["systemChat", _eachHumamPlayer]; and I would have to define _eachHumanPlayer as this? _eachHumanPlayer = allPlayers; ["You can hear a Helicopter in the distance."] remoteExec ["systemChat", _eachHumanPlayer]; Share this post Link to post Share on other sites
Stormmy1950 41 Posted October 3, 2022 No need for _eachHumanPlayer var all you need to do is this: ["You can hear a Helicopter in the distance."] remoteExec ["systemChat"]; Also you can check more how remoteExec works more here :https://community.bistudio.com/wiki/remoteExec and for multiplayer scripting you can check here:https://community.bistudio.com/wiki/Multiplayer_Scripting 1 Share this post Link to post Share on other sites
Larrow 2801 Posted October 3, 2022 Spoiler //slingload.sqf if ( !isServer ) exitWith { [ _this, "slingload.sqf" ] remoteExec[ "execVM", 2 ]; }; // pull class names and spawn marker from arguments passed through execVM params[ "_heli_class", "_cargo_class", "_spawn_mkr" ]; "You can hear a Helicopter in the distance." remoteExec[ "systemChat", [ 0, -2 ] select isDedicated ]; //[ 0, -2 ] select isDedicated //all clients( 0 ) or all clients minus the server if dedicted( -2 ) _spawn = getMarkerPos _spawn_mkr; _destination = selectRandom[ "Marker_1", "Marker_2", "Marker_3", "Marker_4", "Marker_5", "Marker_6", "Marker_7" ]; format[ "Destination: %1", _destination ] remoteExec[ "systemChat", [ 0, -2 ] select isDedicated ]; _destination = getMarkerPos _destination; // delay before retrying on failure _delay = 1; // spawn invisble helipad object for heli to target _helipad_obj = "Land_HelipadEmpty_F" createVehicle _destination; // spawn heli facing destination [ _spawn, _spawn getDir _destination, _heli_class, west ] call BIS_fnc_spawnVehicle params[ "_heli", "_heli_crew", "_heli_grp" ]; // safeguard it _heli setCaptive true; _heli allowDamage false; // create cargo and slingload it _cargo = createVehicle[ _cargo_class, [0,0,50], [], 0, "" ]; _cargo_Mass = getMass _cargo; _cargo setMass 1; _cargo allowDamage false; //stop cargo being destroyed _heli setSlingLoad _cargo; //_heli_grp setFormation "WEDGE"; _heli_grp setBehaviour "SAFE"; _heli_grp setSpeedMode "NORMAL"; // tell heli to move to and attempt to unhook at the destination _mvWP = _heli_grp addWaypoint[ _destination, 0 ]; _mvWP setWaypointType "UNHOOK"; // grab the time for use later _time = serverTime; // Pause script until the cargo is less than 1m off the deck or until 15 seconds pass to prevent endless wait waitUntil{ getPosATL _cargo select 2 < 0.6) || serverTime > ( _time + 15 ) }; //15 seconds to move and unhook seems rather short? // delete everything if something happened and heli never made it to the destination if ( _heli distance2D _helipad_obj > 25 ) exitWith { deleteVehicle _cargo; { deleteVehicle _x }forEach ( _heli_crew + [ _heli ] ); deleteGroup _heli_grp; //delete the group as well format[ "Something went wrong! heli, crew, and cargo deleted. Trying again in %1 seconds.", _delay ] remoteExec[ "systemChat", [ 0, -2 ] select isDedicated ]; sleep _delay; _this execVM "slingload.sqf"; //rerun script }; //detatch the cargo _heli setSlingLoad objNull; _cargo setMass _cargo_Mass; "The helicopter dropped something off, it might prove useful." remoteExec[ "systemChat", [ 0, -2 ] select isDedicated ]; //create task to inspect [ "task2", true, [ "Secure the cargo.", "Find the dropped cargo and secure it.", "" ], nil, "ASSIGNED", 0, true, true, "", true ] call BIS_fnc_setTask; _cargo addAction[ "Inspect", "juggernaut_equipment.sqf" ]; // give heli a new waypoint back to spawn _dieWP = _heli_grp addWaypoint[ _spawn, 0 ]; _dieWP setWaypointType "MOVE"; _heli flyInHeight 60; // grab time one last time for same reason as before _time = serverTime; // Pause script until the Heli is within 100m of spawnpoint or until 30 seconds pass to prevent endless wait waitUntil{ _heli distance2D _spawn < 100 || serverTime > ( _time + 30 ) }; { deleteVehicle _x }forEach ( _heli_crew + [_heli] ); deleteGroup _heli_grp; //initServer.sqf //[ heli_class, _cargo_class, _spawn_mkr ] [ "B_Heli_Transport_03_F", "Land_Cargo10_military_green_F", "spawn" ] execVM "slingload.sqf"; Untested. 1 Share this post Link to post Share on other sites
Harzach 2507 Posted October 3, 2022 4 hours ago, Saftdraft said: systemChat str(format ["You can hear a Helicopter in the distance."]); Tangential to the topic, but important for clarity: the commands str and format are unnecessary here. You are already supplying a string to systemChat, so the str is redundant (and will result in quoted text, which looks odd in this context). You are not doing any formatting, so format is wasted. If, for example, different types of vehicles could be on the way, you might do something like: systemChat format ["You can hear a %1 in the distance.", _vehicle call BIS_fnc_objectType]; As for the actual script, there's a lot that doesn't make sense. // marker positions _spawn = [0,0,0];//_this select 2; _spawn = getMarkerPos _spawn; //later... // spawn heli _heli_spawn = [_spawn, 0, _heli_class, West] call BIS_fnc_spawnVehicle; _heli = _heli_spawn select 0; What's happening: _spawn is defined as [0,0,0] _spawn, if it were a marker (which it is not) is then redefined as its own position (don't do that), so getMarkerPos returns nothing and _spawn remains defined as [0,0,0] _spawn is defined by the third param if using the commented code, so if no third param is passed, that would explain _spawn being undefined _heli is being defined as _spawn, which breaks the script further down where _heli is assumed to be the spawned helicopter Clearly, that third param (a markerName) is supposed to be used. Today's standard would see this at the top of your script: // pull class names from arguments passed through execVM params = ["_heli_class", "_cargo_class", "_spawn"]; As usual, see @Larrow's script for an example of what to do. 1 Share this post Link to post Share on other sites