Jump to content
Sign in to follow this  
ange1u5

Dedicated server loadout script problem...

Recommended Posts

I have a slight problem with player loadouts on dedicated servers. Basically when you spawn into the mission, the loadout is not present. But once you respawn, the loadout will then work. This issue is not present in local multiplayer hosting. Now I have two seperate SQF's for local and dedicated hosting, so I imagine the problem is here somewhere.

First I have init.sqf which runs the following in this order:

null = [] execVM "randomWeather2.sqf"; //Executes weather script - does not seem to work otherwise if placed in other init files
null = [] execVM "initplayer.sqf"; //This is for regular multiplayer hosting
null = [] execVM "initdedi.sqf"; //This is for dedicated server hosting
null = [] execVM "eos\OpenMe.sqf"; //Executes EOS script

sleep 0.15;

In initplayer.sqf the files I'm referencing here begin at the top with the following before proceeding with the rest of the code in the script:

waitUntil {!isNull player};
[] execVM "player_markers.sqf";  //Executes player markers script so players can see their relative real time positions on the map
null = [player] execVM "RespawnLoadout.sqf"; //Executes player loadout script

In initdedi.sqf the code reads more like this:

if (!isDedicated) exitWith {};

[] spawn {
{
	if (isPlayer _x) then {
		null = [] execVM "player_markers.sqf";  //Executes player markers script so players can see their relative real time positions on the map
		null = [player] execVM "RespawnLoadout.sqf"; //Executes player loadout script
	};
}forEach allUnits;
};

In the RespawnLoadout.sqf itself is the following code:

_target = _this select 0;

if(side _target == WEST) then {
null = [_target] execVM "competitorLoadout.sqf";
};

if(side _target == Civilian) then {
null = [_target] execVM "civLoadout.sqf";
};

//Arcade Mode (All Damage Off) - If this is turned on, allowdamage false is executed after respawn otherwise players become vulnerable to injury again
if ((paramsarray select 7) == 3) then {
null = [] execVM "invul2.sqf";
};

So after all that my question becomes, why is the loadout not working on that initial spawn into dedicated but DOES work after you respawn? All help appreciated!

Share this post


Link to post
Share on other sites

It shouldn't work. On a dedi server the "player" variable/command is always objNull. Besides the dedicated server can't assign items to non-local objects most of the time. In init player you should add a respawn eventhandler to execute the scripts. Dedicated shouldn't be trying to assign loadouts unless it's the absolute first thing that happens for an object (called from init)

---------- Post added at 02:19 PM ---------- Previous post was at 02:17 PM ----------

*player loadouts

Share this post


Link to post
Share on other sites

I don't quite understand initdedi.sqf. It checks if the cycled unit is a player, and then attempts to use the player command, which refers to the object controlled by the current client, which on a dedicated server is null. You should switch player to _x (the object being cycled by forEach allUnits) in this case.

However, since initplayer.sqf already has a waitUntil {!isNull player}; check, I'm not sure what's the point of initdedi.sqf in the first place. Could you post the contents of competitorLoadout.sqf or civLoadout.sqf? Maybe something in those is the issue.

Share this post


Link to post
Share on other sites

That all looks like a bit of a headache ...

Here's a way out of the woods:

Server stuff

1. Copy and paste your init.sqf, in the same directory.

2. Rename the copy "initServer.sqf". Herein goes all your Server Stuff.

3. Clear out the new file, make it empty. Then,

Put this into "initServer.sqf":

null = [] execVM "randomWeather2.sqf"; //Executes weather script - does not seem to work otherwise if placed in other init files
null = [] execVM "eos\OpenMe.sqf"; //Executes EOS script

Player Stuff

1. Again, copy and paste your init.sqf into the same directory. With the copy, rename it "initPlayerLocal.sqf"

2. In there goes all your Player Stuff.

3. Clear out the new file, make it empty. Then,

Put this into "initPlayerLocal.sqf"

[] execVM "player_markers.sqf";  //Executes player markers script so players can see their relative real time positions on the map
null = [player] execVM "RespawnLoadout.sqf"; //Executes player loadout script  
respawnLoadout = player addEventHandler ["Respawn",{[player] execVM "RespawnLoadout.sqf";}];

Now, go back to your "init.sqf", select everything and press Backspace on your keyboard! Your init.sqf should then be empty.

At that point you are done, give it a try.

Forget about the initdedi thing, looks useless. :)

Share this post


Link to post
Share on other sites

Hmm ok, perhaps I should post the full contents of all 3 files I have, because all 3 of them are full of stuff well beyond the bits I've posted. Before you ask, I'm not a natural programmer, I've been getting help with this all the way through, so if half of this looks like 'why the f**k is he doing it like that?" my answer is because it seems to be working so I don't want to mess with what isn't broken :D

init.sqf

//Init file must be split for multiplayer hosting purposes.

//Hides all the EOS script zones from the map, as this is not a conquest mission, players do not need to see the zones.

{_x setMarkerAlphaLocal 0} foreach ["civzone1","civzone2","civzone3","civzone4","civzone5","civzone6","civzone7","civzone8","civzone9","civzone10","civzone11","civzone12","civzone13","civzone14","civzone15","civzone16","civzone17","civzone18","civzone19","civzone20","civzone21","civzone22","civzone23","civzone24","civzone25","civzone26","civzone27","civzone28","civzone29","civzone30","civzone31","civzone32","civzone33","civzone34","civzone35","civzone36","civzone37","civzone38","civzone39","civzone40","civzone41","civzone42","civzone43","civzone44","civzone45","civzone46","civzone47","civzone48","civzone49","civzone50","civzone51","civzone52","civzone53","civzone54","civzone55","civzone56","civzone57","civzone58","civzone59","civzone60","kavalazone","pyrgoszone","paroszone","athirazone","graviazone","rodopolizone","sofiazone","neochorizone","fereszone","stavroszone","lakkazone","therisazone","syrtazone","oreokastrozone","korezone","katalakizone","alikamposzone","zaroszone","panochorizone","boatzone1","boatzone2","boatzone3","boatzone4","boatzone5","boatzone6","boatzone7","boatzone8","boatzone9","boatzone10","boatzone11","boatzone12","boatzone13","boatzone14","boatzone15","boatzone16","boatzone17","boatzone18","boatzone19"];

null = [] execVM "randomWeather2.sqf"; //Executes weather script - does not seem to work otherwise if placed in other init files
null = [] execVM "initplayer.sqf"; //This is for regular multiplayer hosting
null = [] execVM "initdedi.sqf"; //This is for dedicated server hosting
null = [] execVM "eos\OpenMe.sqf"; //Executes EOS script

sleep 0.15;

//Setting the time of day must be done from init.sqf, doesn't seem to work when placed in the other init files.
GlobalServerTime = date; 
GlobalServerTime set [3,(paramsarray select 2)];
publicvariable "GlobalServerTime"; 
setdate GlobalServerTime;

//View Distance parameter
viewparam = (paramsArray select 9);
if (viewparam == 0) then {setViewDistance 1000};
if (viewparam == 1) then {setViewDistance 1500};
if (viewparam == 2) then {setViewDistance 2000};
if (viewparam == 3) then {setViewDistance 2500};
if (viewparam == 4) then {setViewDistance 3000};
if (viewparam == 5) then {setViewDistance 3500};
if (viewparam == 6) then {setViewDistance 4000};
if (viewparam == 7) then {setViewDistance 5000};
if (viewparam == 8) then {setViewDistance 6000};
if (viewparam == 9) then {setViewDistance 7500};

sleep 0.15;

null = [] execVM "unflip.sqf"; //Adds Unflip action to players

//Create arrow signs above spare car truck spawns to aid players 
_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position truck1;
	_truckarrow attachTo [truck1,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp1truck;
	_truckarrow attachTo [cp1truck,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp2truck;
	_truckarrow attachTo [cp2truck,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp3truck;
	_truckarrow attachTo [cp3truck,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp4truck;
	_truckarrow attachTo [cp4truck,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp5truck;
	_truckarrow attachTo [cp5truck,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp6truck;
	_truckarrow attachTo [cp6truck,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp7truck;
	_truckarrow attachTo [cp7truck,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp8truck;
	_truckarrow attachTo [cp8truck,[0,-0.5,3]];

//Make the spare car spawn trucks invulnerable so the attack choppers don't accidentally blow them up if firing on players at checkpoints.		
{
_x allowdamage false;
}forEach [truck1,cp1truck,cp2truck,cp3truck,cp4truck,cp5truck,cp6truck,cp7truck,cp8truck];

//Make the ending UAV planes invulnerable. This prevents the ending sequence glitching out on the rare occasions one of the UAV's was destroyed before the player finished the race.	
{
_x allowdamage false;
}forEach [endplane1,endplane2,endplane3,endplane4,endplane5];


initplayer.sqf

 

//This Init SQF is for single player or local multiplayer hosting purposes. 

waitUntil {!isNull player};
[] execVM "player_markers.sqf";  //Executes player markers script so players can see their relative real time positions on the map
null = [player] execVM "RespawnLoadout.sqf"; //Executes player loadout script




//Civilian Traffic - If enabled it will activate the EOS script zones.
if ((paramsarray select 3) == 0) then {
null = [] execVM "disableCiv.sqf";
};


//OPFOR AH-9 Helos
if ((paramsarray select 4) == 0) then {
for "_i" from 1 to 14 do { 
   deleteMarker ("helozone" + str _i); 
};  
};

//Ambient AI - This will not delete the starting A-164 planes, these are necessary for the intro sequence to work
if ((paramsarray select 5) == 0) then {
[] spawn {
{ waitUntil {driver _x != objNull};
deleteVehicle (driver _x);
deleteVehicle _x; } forEach [indplane1,indplane2,indplane3,indplane4,indplane5,indplane6,indplane7,indpilot1,indpilot2,indpilot3,indpilot4,indpilot5,indpilot6,indpilot7,indhelo1,indhelo2,indhelo3,indhelo4,indhelo5,indhelo6,indhelo7];
}; 
};

if ((paramsarray select 5) == 0) then {
for "_i" from 1 to 19 do { 
   deleteMarker ("boatzone" + str _i); 
};  
};

//Repair Modifier
//326km/h
if ((paramsarray select 6) == 0) then {
Max_Repair_Damage = 0;
Repair_Action_Number = 0;
null = [] execVM "repair.sqf";
};

//187-287km/h
if ((paramsarray select 6) == 1) then {
Max_Repair_Damage = 0.25;
Repair_Action_Number = 0.25;
null = [] execVM "repair.sqf";
};

//148-197km/h
if ((paramsarray select 6) == 2) then {
Max_Repair_Damage = 0.75;
Repair_Action_Number = 0.75;
null = [] execVM "repair.sqf";
};

//Arcade Mode (All Damage Off)
if ((paramsarray select 6) == 3) then {
null = [] execVM "invul.sqf";
};

//course Selection

//Kavala to Molos
if ((paramsarray select 0) == 1) then {
null = [] execVM "course\CourseKM.sqf";
};

//Kavala to Feres
if ((paramsarray select 0) == 2) then {
null = [] execVM "course\CourseKF.sqf";
};

//Molos to Kavala
if ((paramsarray select 0) == 3) then {
null = [] execVM "course\CourseMK.sqf";
};

//Molos to Feres
if ((paramsarray select 0) == 4) then {
null = [] execVM "course\CourseMF.sqf";
};

//Feres to Kavala
if ((paramsarray select 0) == 5) then {
null = [] execVM "course\CourseFK.sqf";
};

//Feres to Molos
if ((paramsarray select 0) == 6) then {
null = [] execVM "course\CourseFM.sqf";
};

//Thronos to Kavala
if ((paramsarray select 0) == 7) then {
null = [] execVM "course\CourseTK.sqf";
};

//Thronos to Feres
if ((paramsarray select 0) == 8) then {
null = [] execVM "course\CourseTF.sqf";
};

//Thronos to Eginio
if ((paramsarray select 0) == 9) then {
null = [] execVM "course\CourseTE.sqf";
};

//Eginio to Thronos
if ((paramsarray select 0) == 10) then {
null = [] execVM "course\CourseET.sqf";
};

//Eginio to Kavala
if ((paramsarray select 0) == 11) then {
null = [] execVM "course\CourseEK.sqf";
};

sleep 0.1;

titleText ["The Great Altis Race is loading!\n\nPlease Standby.","PLAIN",2];

sleep 3;

null = [] execVM "checkpoints.sqf"; //Executes roaming checkpoint respawn script. Needs to be executed after course and repair selection params to function otherwise no respawn points will be available.

//Force first person view on player when driving.
if ((paramsarray select 7) == 1) then {
[] spawn {
	while {true} do {
		if ((vehicle player != player) && (CameraView == "EXTERNAL")) then {
			vehicle player switchCamera "INTERNAL";
			hint "Third person view disabled while in a vehicle!";
		};
	};

};
};



sleep 6.5;



//Intro sequence has been split into separate SQF's because moving planes on dedicated servers was unreliable and caused the intro to break. Now planes are in the editor in each position, but deleted if not used depending on course selected.
//Camera intros - Each course has a modified intro sequence to reflect its starting location and course selection.

//Kavala to Molos Intro
if ((paramsarray select 0) == 1) then {
null = [] execVM "intro\CameraKM.sqf";
};

//Kavala to Feres Intro
if ((paramsarray select 0) == 2) then {
null = [] execVM "intro\CameraKF.sqf";
};

//Molos to Kavala Intro
if ((paramsarray select 0) == 3) then {
null = [] execVM "intro\CameraMK.sqf";
};

//Molos to Feres Intro
if ((paramsarray select 0) == 4) then {
null = [] execVM "intro\CameraMF.sqf";
};

//Feres to Kavala Intro
if ((paramsarray select 0) == 5) then {
null = [] execVM "intro\CameraFK.sqf";
};

//Feres to Molos Intro
if ((paramsarray select 0) == 6) then {
null = [] execVM "intro\CameraFM.sqf";
};

//Thronos to Kavala Intro
if ((paramsarray select 0) == 7) then {
null = [] execVM "intro\CameraTK.sqf";
};

//Thronos to Feres Intro
if ((paramsarray select 0) == 8) then {
null = [] execVM "intro\CameraTF.sqf";
};

//Thronos to Eginio Intro
if ((paramsarray select 0) == 9) then {
null = [] execVM "intro\CameraTE.sqf";
};

//Eginio to Thronos Intro
if ((paramsarray select 0) == 10) then {
null = [] execVM "intro\CameraET.sqf";
};

//Eginio to Kavala Intro
if ((paramsarray select 0) == 11) then {
null = [] execVM "intro\CameraEK.sqf";
};

initdedi.sqf

 

//This Init SQF is for Dedicated Server hosting purposes. Some features of the mission do not work properly or at all without this SQF on dedicated servers!

if (!isDedicated) exitWith {};

[] spawn {
{
	if (isPlayer _x) then {
		null = [] execVM "player_markers.sqf";  //Executes player markers script so players can see their relative real time positions on the map
		null = [player] execVM "RespawnLoadout.sqf"; //Executes player loadout script
	};
}forEach allUnits;
};

//OPFOR AH-9 Helos
if ((paramsarray select 4) == 0) then {
for "_i" from 1 to 14 do { 
   deleteMarker ("helozone" + str _i); 
};  
};


//Civilian Traffic - If enabled it will activate the EOS script zones.
if ((paramsarray select 3) == 0) then {
null = [] execVM "disableCiv.sqf";
};


//Ambient AI -  Can enable/disable all Naval and Aircraft AI. This will NOT however delete the starting A-164 planes, these are necessary for the intro sequence to work.
if ((paramsarray select 5) == 0) then {
[] spawn {
{ waitUntil {driver _x != objNull};
deleteVehicle (driver _x);
deleteVehicle _x; } forEach [indplane1,indplane2,indplane3,indplane4,indplane5,indplane6,indplane7,indpilot1,indpilot2,indpilot3,indpilot4,indpilot5,indpilot6,indpilot7,indhelo1,indhelo2,indhelo3,indhelo4,indhelo5,indhelo6,indhelo7];
}; 
};

if ((paramsarray select 5) == 0) then {
for "_i" from 1 to 19 do { 
   deleteMarker ("boatzone" + str _i); 
};  
};


//Repair Modifier
//326km/h
if ((paramsarray select 6) == 0) then {
Max_Repair_Damage = 0;
Repair_Action_Number = 0;
null = [] execVM "repair.sqf";
};

//187-287km/h
if ((paramsarray select 6) == 1) then {
Max_Repair_Damage = 0.25;
Repair_Action_Number = 0.25;
null = [] execVM "repair.sqf";
};

//148-197km/h
if ((paramsarray select 6) == 2) then {
Max_Repair_Damage = 0.75;
Repair_Action_Number = 0.75;
null = [] execVM "repair.sqf";
};

//Arcade Mode (All Damage Off)
if ((paramsarray select 6) == 3) then {
null = [] execVM "invul.sqf";
};

//course Selection

//Kavala to Molos
if ((paramsarray select 0) == 1) then {
null = [] execVM "course\CourseKM.sqf";
};

//Kavala to Feres
if ((paramsarray select 0) == 2) then {
null = [] execVM "course\CourseKF.sqf";
};

//Molos to Kavala
if ((paramsarray select 0) == 3) then {
null = [] execVM "course\CourseMK.sqf";
};

//Molos to Feres
if ((paramsarray select 0) == 4) then {
null = [] execVM "course\CourseMF.sqf";
};

//Feres to Kavala
if ((paramsarray select 0) == 5) then {
null = [] execVM "course\CourseFK.sqf";
};

//Feres to Molos
if ((paramsarray select 0) == 6) then {
null = [] execVM "course\CourseFM.sqf";
};

//Thronos to Kavala
if ((paramsarray select 0) == 7) then {
null = [] execVM "course\CourseTK.sqf";
};

//Thronos to Feres
if ((paramsarray select 0) == 8) then {
null = [] execVM "course\CourseTF.sqf";
};

//Thronos to Eginio
if ((paramsarray select 0) == 9) then {
null = [] execVM "course\CourseTE.sqf";
};

//Eginio to Thronos
if ((paramsarray select 0) == 10) then {
null = [] execVM "course\CourseET.sqf";
};

//Eginio to Kavala
if ((paramsarray select 0) == 11) then {
null = [] execVM "course\CourseEK.sqf";
};

sleep 3;

{
if (isPlayer _x) then {
	null = [] execVM "checkpoints.sqf"; //Executes roaming checkpoint respawn script. Needs to be executed after course and repair selection params to function otherwise no respawn points will be available.
};
}forEach allUnits;

//Force first person view on player when driving.
if ((paramsarray select 7) == 1) then {
[] spawn {
	while {true} do {
		if ((vehicle player != player) && (intro\cameraView == "EXTERNAL")) then {
			vehicle player switchintro\camera "INTERNAL";
			hint "No Third Person while in a vehicle!";
		};
	};

};
};



sleep 6.5;

Is what you suggest MDCCLXXVI still relevant or does this need redoing from the ground up? =P

Share this post


Link to post
Share on other sites

Well, just a suggestion for you, because I don't think I've ever seen so many if statements in sequence before, try using a switch statement in place of the many if's.

And yes what MDCCLXXVI recommended is still relevant, as the .sqf files that he is referring to are event scripts, that the game knows and understands, no different from the init.sqf, however, these script files are specifically geared towards executing certain code on the server or client, without having all the checks normally involved with that process, essentially saving the headache of script locality execution.

And you can use a forEach for the following, no different than what you have just below these lines:

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position truck1;
       _truckarrow attachTo [truck1,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp1truck;
       _truckarrow attachTo [cp1truck,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp2truck;
       _truckarrow attachTo [cp2truck,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp3truck;
       _truckarrow attachTo [cp3truck,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp4truck;
       _truckarrow attachTo [cp4truck,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp5truck;
       _truckarrow attachTo [cp5truck,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp6truck;
       _truckarrow attachTo [cp6truck,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp7truck;
       _truckarrow attachTo [cp7truck,[0,-0.5,3]];

_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position cp8truck;
       _truckarrow attachTo [cp8truck,[0,-0.5,3]];

{
_truckarrow = "Sign_Arrow_Large_Blue_F" createVehicle position _x;
       _truckarrow attachTo [_x,[0,-0.5,3]];
} forEach [truck1,cp1truck,cp2truck,cp3truck,cp4truck,cp5truck,cp6truck,cp7truck,cp8truck];

Edited by JShock

Share this post


Link to post
Share on other sites

Ok thanks for the help, will see what I can do, though not entirely sure where I need to put what where, but it'll be fun finding out =D

Share this post


Link to post
Share on other sites

Actually just realised I didn't post the actual loadout code in case anything is wrong here too:

_target = _this select 0;
waitUntil {!isNull _target};
removeAllWeapons _target;    
removeallassigneditems _target;   
removeBackpack _target;

_target addbackpack "B_AssaultPack_khk"; 

_target linkItem "ItemMap";    
_target linkItem "ItemGPS";    
_target linkItem "ItemRadio";    
_target linkItem "ItemWatch";    
_target linkItem "ItemCompass";        
_target addItem "FirstAidKit";
_target addItem "FirstAidKit";    
_target addItem "FirstAidKit";    
_target additem "ToolKit";   

Is this correct?

Share this post


Link to post
Share on other sites

That seems all good to me, but if you did as we suggested above (with initPlayerLocal.sqf) you should be able to just call the script and use player in place of _target, if you wanted to, it's not required, it should do the same thing :p.

You may have to use removeAllAssignedItems in conjunction with removeAllItems, but I'm not certain, some testing could clear that up :D.

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  

×