Forum Jump :

Author Message


Posts: 25
Rank:


Level: Member

Country: us
Location: In the dungeon to hell!
Occupation:
Age: 31
In-game name:

 
#1 Posted at 2016-06-22 21:09        
     
So far the script works flawlessly in single player. But I'm having trouble with it in Multiplayer it, what it does is I think it spawns multiple helicopters (like one heli per player that connects to the server). which in turn blows up all of them right a the start of my mission and then it says the loser ending. so you can't even play the mission in multiplayer. Please help, below is the script. I need it to work for both Single player and Multiplayer.

//////////////////////////////////////////////////////////////////////////////////////
// Script by ThePlague1988
//////////////////////////////////////////////////////////////////////////////////////
// Usage:
// null = [group player, "markerSpawn", "markerLZ"] execVM "scripts\insertion.sqf";
//////////////////////////////////////////////////////////////////////////////////////

private ["_group","_spawn","_lz","_vehArray","_helipad","_wp1","_wp2"];

_group = _this select 0;
_spawn = _this select 1;
_lz = _this select 2;
vehArray = [];

vehArray = [getMarkerPos _spawn, 180, "B_Heli_Transport_01_F", WEST] call BIS_fnc_spawnVehicle;
transporthelo = vehArray select 0;
heloGroup = vehArray select 2;
publicVariable "transporthelo";

{
	_x assignAsCargo transporthelo;
	_x moveInCargo transporthelo;
} forEach units _group;

_helipad = "Land_HelipadEmpty_F" createVehicle getMarkerPos _lz;

_wp = heloGroup addWaypoint [getMarkerPos _lz, 0];
_wp setWaypointType "TR UNLOAD";
_wp setWaypointStatements ["true", ""];
_wp2 = heloGroup addWaypoint [getMarkerPos _spawn, 0];
_wp2 setWaypointType "MOVE";
_wp2 setWaypointStatements ["true", "moveDone = true; publicVariable ""moveDone"";"];

waitUntil {moveDone};

{
	deleteVehicle _x;
} forEach (crew transporthelo) + [transporthelo,_helipad];

EDIT: Everything is working but, JIP players connect and the chopper blows up, what could I be doing wrong... Does that mean it is spawning 2 helicopters or something??

This post was edited by theplague1988 (2016-06-28 23:21, ago)

Philip "5n4k3" Simonson

Author Message


Posts: 29
Rank:


Level: Member

Country: de
Location: Berlin, Germany
Occupation:
Age:
In-game name:

 
#2 Posted at 2016-06-23 11:53        
     
add this as first line before ur private command to ur script
if(!isServer) exitWith {true};
or ensure somwhere else that ur script is run by server only.
another thing I see is ur parameter handling. its a bit obsolete. use params command instead like this:
params ["_group","_spawn","_lz"]
private ["_vehArray","_helipad","_wp1","_wp2"];

vehArray = [];
.
.
.

params will privatize the arguments and put it in the local variables by order as in the origin parameter array. You could also do some neat checks and initializing with params but the basic function is as written above.
params

next thing is your waypoint statements. its not neccessary to use publicVariable there because ur script should run on server only.
and the last I see is ur waitUntil. actually it runs at every frame. thats not neccessary for those check. I would put a sleep of 5 seconds in it as this:
waitUntil {sleep 5; moveDone};

Another last thing is that I would never use such simple variable names as moveDone for a global variable. the reason is that it could be that BI creates a command like this in future or if u use other script or mods that this variable name is used by them already.
You should add a unique phrase to ur global variables like thePlague_moveDone

This post was edited by sarogahtyp (2016-06-23 12:30, ago)

Sarogahtyps Spawn Script Creator - SSSC
the easy way to cache ur units, vehicles and their waypoints

Advertisement


Author Message


Posts: 25
Rank:


Level: Member

Country: us
Location: In the dungeon to hell!
Occupation:
Age: 31
In-game name:

 
#3 Posted at 2016-06-23 17:21        
     
Thanks I'll update it as you suggest and let you know if it works properly...

EDIT: Okay everything works properly except, it doesn't put other players in the chopper when they join the game. Nobody is in the chopper when it's a dedicated server.

EDIT: The changed code...
//////////////////////////////////////////////////////////////////////////////////////
// Script by ThePlague1988
//////////////////////////////////////////////////////////////////////////////////////
// Usage:
// null = [group player, "markerSpawn", "markerLZ"] execVM "scripts\insertion.sqf";
//////////////////////////////////////////////////////////////////////////////////////

if (!isServer) exitWith {true};

params ["_group","_spawn","_lz"];
private ["_vehArray","_heloGroup","_helipad","_wp1","_wp2"];

_vehArray = [];

_vehArray = [getMarkerPos _spawn, 180, "B_Heli_Transport_01_F", WEST] call BIS_fnc_spawnVehicle;
transporthelo = _vehArray select 0;
_heloGroup = _vehArray select 2;
publicVariable "transporthelo";

{
	_x assignAsCargo transporthelo;
	_x moveInCargo transporthelo;
} forEach units _group;

_helipad = "Land_HelipadEmpty_F" createVehicle getMarkerPos _lz;

_wp1 = _heloGroup addWaypoint [getMarkerPos _lz, 0];
_wp1 setWaypointType "TR UNLOAD";
_wp1 setWaypointStatements ["true", ""];
_wp2 = _heloGroup addWaypoint [getMarkerPos _spawn, 0];
_wp2 setWaypointType "MOVE";
_wp2 setWaypointStatements ["true", "ThePlague_moveDone = true;"];

waitUntil {sleep 5; ThePlague_moveDone};

{
	deleteVehicle _x;
} forEach (crew transporthelo) + [transporthelo,_helipad];

This post was edited by theplague1988 (2016-06-23 17:40, ago)

Philip "5n4k3" Simonson

Author Message


Posts: 29
Rank:


Level: Member

Country: de
Location: Berlin, Germany
Occupation:
Age:
In-game name:

 
#4 Posted at 2016-06-23 18:33        
     
ok. u ve to assign and moveIn each player themself by using the file onPlayerRespawn.sqf and/or initPlayerLocal.sqf

these r event scripts which run automatically on an event. look here:

Event Scripts

Sarogahtyps Spawn Script Creator - SSSC
the easy way to cache ur units, vehicles and their waypoints

Author Message


Posts: 25
Rank:


Level: Member

Country: us
Location: In the dungeon to hell!
Occupation:
Age: 31
In-game name:

 
#5 Posted at 2016-06-23 20:32        
     
This is what I have in my initPlayerLocal.sqf but it doesn't work for some reason.

waitUntil {sleep 1; !(isNull helo && ThePlague_moveDone)};
(_this select 0) assignAsCargo helo;
(_this select 0) moveInCargo helo;

What would I put in there??

Philip "5n4k3" Simonson

Author Message


Posts: 25
Rank:


Level: Member

Country: us
Location: In the dungeon to hell!
Occupation:
Age: 31
In-game name:

 
#6 Posted at 2016-06-25 04:04        
     
Here is a test mission where I've done everything you said and it doesn't work properly on a dedicated server. I'm try it on a "dedicated server". But no luck. Please help someone. Thanks in advance, still trying to get the helicopter insertion script to work... but it fails works no problem in Single player though.

Test Mission (Stratis)

EDIT: Oops, crap I double posted. Sorry, forgot to edit that last instead.

Philip "5n4k3" Simonson

Author Message


Posts: 29
Rank:


Level: Member

Country: de
Location: Berlin, Germany
Occupation:
Age:
In-game name:

 
#7 Posted at 2016-06-25 11:00        
     
The thing is that u cant just write a script for SP and expect it would work on MP.
If u know that ur script is needed for MP at some time then you have to ask u for every line of code where and when it has to be executed. If u dont do that work at first then u ve to write ur script twice.

And thats what u have todo now. Write it a second time. Ask u what has to be executed on each client and what on server only. Also you have to think about if a variable is known on the machine where ur code needs it and if not how to get it known.

Try to read some MP tutorials, try to write that script and ask for help if u get stucked.
I m sorry for that unsatisfying answer but Ive currently no time to rewrite ur script completely.

A rough guideline how I would do it is that I would do the spawn stuff and waypoint setting and vehicle deletion server side and that stuff corresponding to players as assigning and moving into vehicle client side.

Sarogahtyps Spawn Script Creator - SSSC
the easy way to cache ur units, vehicles and their waypoints

Author Message


Posts: 25
Rank:


Level: Member

Country: us
Location: In the dungeon to hell!
Occupation:
Age: 31
In-game name:

 
#8 Posted at 2016-06-25 15:19        
     
ok one more quick question, what is the best way to check for server and client would it be..

if (isServer) then {
   // server stuff
} else {
   // client stuff
};

Or something else?

Philip "5n4k3" Simonson

Author Message


Posts: 29
Rank:


Level: Member

Country: de
Location: Berlin, Germany
Occupation:
Age:
In-game name:

 
#9 Posted at 2016-06-25 15:44        
     
u can do it that way but i think its better to look for an event script matching the situation u have. look at my first posts link.
if there is no event script where u can start from then the best way is to look for an event handler that does the job. only if nothing of that matches ur need then u can do it with isServer or hasInterface or isDedicated.
the best way is to write a script for server or client only and exit the script if it detects wrong machine.

if (isServer) exitWith{_return_value};
return value could be true or false or nil or a value u wanna return at this point.

Sarogahtyps Spawn Script Creator - SSSC
the easy way to cache ur units, vehicles and their waypoints

Author Message


Posts: 25
Rank:


Level: Member

Country: us
Location: In the dungeon to hell!
Occupation:
Age: 31
In-game name:

 
#10 Posted at 2016-06-26 08:43        
     
Okay, I have tried everything I could find on creating a public global variable.

...
publicVariable "varname";
something setVariable ["testVar",true];
something getVariable "testVar";

But for some reason or another none of that works. By the way if it helps any at the top of my script I have a line like.
if (!isServer) exitWith {true};

So my last question is how do I go about creating a public global (across all computers even server) variable. With that information I could finish this script. Thanks in advance for any and all advice that leads to a solution.

EDIT: Okay I found out how to script it almost working perfectly now. Except when you first start the mission in a dedicated server it does not put the player who first joins the dedicated and starts the mission. But, after the mission has started if other players join they are put into the helicopter. Or if you host dedicated then login to the server and start the mission, then abort the mission and rejoin you'll start the mission in the helicopter. My question now is how do I make it to where everyone no matter when they join, how can I put them in the helo?

Here is the new code...
insertion.sqf:
if (!isServer) exitWith {};
// Declare everything.
_unit = _this select 0; // who called it.
_chopperType = "B_Heli_Transport_01_camo_F";  // Type of transport.
_start = _this select 1;  // location of start/spawn/delete location.
_end = _this select 2;  // location of drop off.

// message letting them know insertion started
hintSilent "Insertion commencing!";

ch = [[getMarkerPos _start select 0,getMarkerPos _start select 1, 0], 0, _chopperType, side _unit] call BIS_fnc_spawnVehicle;

// Name the helo globally so that waypoint orders work
"transporthelo" addPublicVariableEventHandler
{
	private ["_vehicle"];
	_vehicle = _this;
	_vehicle setVehicleVarName "transporthelo";
};
transporthelo = ch select 0;
publicVariable "transporthelo";

_chGroup = ch select 2;
_chGroup setBehaviour "CARELESS";
transporthelo setCaptive true;

{
	_x assignAsCargo transporthelo;
	_x moveInCargo transporthelo;
} forEach (units group b1);

_lzPickup = "B_HelipadEmpty_F" createVehicle getMarkerPos _end;

// Give the helo a waypoint
_wp0 = _chGroup addWaypoint [getMarkerPos _end, 0];
_wp0 setWaypointType "TR UNLOAD";
_wp0 setWaypointStatements ["true", ""];

_wp1 = _chGroup addWaypoint [getMarkerPos _start, 0];
_wp1 setWaypointType "MOVE";
_wp1 setWaypointStatements ["true", "{deleteVehicle _x;} forEach (crew transporthelo)+[transporthelo]; ThePlague_moveDone = true; publicVariable ""ThePlague_moveDone"";"];

waitUntil {ThePlague_moveDone};
deleteVehicle _lzPickup;

initPlayerLocal.sqf:
waitUntil {!isNull transporthelo};
if (!isNull transporthelo) then
{
	(_this select 0) assignAsCargo transporthelo;
	(_this select 0) moveInCargo transporthelo;
};

This post was edited by theplague1988 (2016-06-27 07:32, ago)

Philip "5n4k3" Simonson

Author Message


Posts: 29
Rank:


Level: Member

Country: de
Location: Berlin, Germany
Occupation:
Age:
In-game name:

 
#11 Posted at 2016-06-27 08:07        
     
okay, I ll look at deeper at ur script if Im at work and hopefully have time for it.

but here is what I saw with a fast look:

u r trying to broadcast a vehicles variable name. the best way to do that is posted by killzone kid here:
setVehicleVarName and remoteexec?

this has no sense if it is executed on a dedicated server because it will never be shown:
hintSilent "Insertion commencing!";

u have this in the script which is executed by server:
{
	_x assignAsCargo transporthelo;
	_x moveInCargo transporthelo;
} forEach (units group b1);
but why? you r doing the same in initPlayerLocal.sqf. I also think u shouldnt use initPlayerLocal but onPlayerRespawn.sqf for it because its executed on player spawn when mission starts and on every respawn.

EDIT:
Maybe group b1 is an AI group. in this case its correct to do it server side (if they r local on server)

another thing I already told u r ur global variable names... b1 and transportheli for example. just tag them with ur name to ensure they r unique.

Sarogahtyps Spawn Script Creator - SSSC
the easy way to cache ur units, vehicles and their waypoints

Author Message


Posts: 25
Rank:


Level: Member

Country: us
Location: In the dungeon to hell!
Occupation:
Age: 31
In-game name:

 
#12 Posted at 2016-06-27 19:45        
     
Okay changed the script like you said to, but still the same problem on a dedicated server. Client that starts the mission read from data bank is not in the helo. But any and all players that join after the mission was already started, are in the chopper. New code below.

insertion.sqf:
PRS_fnc_setVehicleName = {
	params ["_veh", "_name"];
	missionNamespace setVariable [_name, _veh, true];
	[_veh, _name] remoteExec ["setVehicleVarName", 0, _veh];
};
publicVariable "PRS_fnc_setVehicleName";

if (!isServer) exitWith {true};

params ["_unit", "_start", "_end"];
private ["_chopperType", "_ch", "_chGroup", "_helipad", "_wp0", "_wp1"];

_chopperType = "B_Heli_Transport_01_camo_F";  // Type of transport.

_ch = [[getMarkerPos _start select 0, getMarkerPos _start select 1, 0], 0, _chopperType, side _unit] call BIS_fnc_spawnVehicle;

// Name the helo globally so that waypoint orders work
_helo = _ch select 0;
[_helo, "transporthelo"] call PRS_fnc_setVehicleName;

_chGroup = _ch select 2;
_chGroup setBehaviour "CARELESS";
transporthelo setCaptive true;

{
	_x assignAsCargo transporthelo;
	_x moveInCargo transporthelo;
} forEach (units group _unit);

_lzPickup = "B_HelipadEmpty_F" createVehicle getMarkerPos _end;
missionNamespace setVariable ["ThePlague_moveDone", false, true];

// Give the helo a waypoint
_wp0 = _chGroup addWaypoint [getMarkerPos _end, 0];
_wp0 setWaypointType "TR UNLOAD";
_wp0 setWaypointStatements ["true", ""];

_wp1 = _chGroup addWaypoint [getMarkerPos _start, 0];
_wp1 setWaypointType "MOVE";
_wp1 setWaypointStatements ["true", "{deleteVehicle _x;} forEach (crew transporthelo)+[transporthelo]; ThePlague_moveDone = true; publicVariable ""ThePlague_moveDone"";"];

waitUntil {ThePlague_moveDone};
deleteVehicle _lzPickup;

initPlayerLocal.sqf:
waitUntil {!isNull transporthelo || ThePlague_moveDone};
if (!isNull transporthelo && !ThePlague_moveDone) then
{
	(_this select 0) assignAsCargo transporthelo;
	(_this select 0) moveInCargo transporthelo;
};

Thanks for all the help so far. What could be causing the problem I explained above (any idea)?

Philip "5n4k3" Simonson

Author Message


Posts: 29
Rank:


Level: Member

Country: de
Location: Berlin, Germany
Occupation:
Age:
In-game name:

 
#13 Posted at 2016-06-28 09:46        
     
upto now I ve no idea whats causing the problem.

where and how do u execute insertion.sqf?

Added 4 hours 23 minutes later:

maybe that you global variable is nil at the time u want to insert the player. maybe nil is not null and therefore the waitUntil is passed...
try to substitute this:
waitUntil {!isNull transporthelo || ThePlague_moveDone};

with that:
waitUntil {sleep 0.5; !isNil "transporthelo"};
waitUntil {sleep 0.5; !isNull transporthelo || ThePlague_moveDone};

This post was edited by sarogahtyp (2016-06-28 14:10, ago)

Sarogahtyps Spawn Script Creator - SSSC
the easy way to cache ur units, vehicles and their waypoints

Author Message


Posts: 25
Rank:


Level: Member

Country: us
Location: In the dungeon to hell!
Occupation:
Age: 31
In-game name:

 
#14 Posted at 2016-06-28 14:32        
     
here is where I execute the insertion.sqf file...

init.sqf:
null = [b1,"spawnHelo","lZone1"] execVM "scripts\insertion.sqf";
null = [] execVM "scripts\ammo_init.sqf";

execVM "briefing.sqf";

NOTE: grpAlpha is a group of playable units I placed in the editor, b1,b2,b3,b4... b1 is the leader. spawnHelo is a marker, and so is lZone1.

EDIT: Ahh finally, it works perfectly.. when I changed that one statement
to this...

waitUntil {sleep 0.5; !isNil "transporthelo"};
waitUntil {sleep 0.5; !isNull transporthelo || ThePlague_moveDone};

Thank you very much for the help. Oh how do I mark this as solved now?

This post was edited by theplague1988 (2016-06-28 14:48, ago)

Philip "5n4k3" Simonson

Author Message


Posts: 29
Rank:


Level: Member

Country: de
Location: Berlin, Germany
Occupation:
Age:
In-game name:

 
#15 Posted at 2016-06-28 15:19        
     
cool that it works now. idk how to mark a topic solved. i never created one :-)

Sarogahtyps Spawn Script Creator - SSSC
the easy way to cache ur units, vehicles and their waypoints