Jump to content
Luft08

Locality... The Bain of my existence

Recommended Posts

I can't seem to get a handle on locality.  I understand it, I just can't seem to not get smacked in the face by it. The other day Harzach helped me identify my locality problem and I though I was being so careful but I once again have code that runs fine in single player but not on my dedicated server.

 

When a player destroys an enemy vehicle I want to award that player points based on the vehicle type and send a hint message to only that player.

 

When I create the vehicle I attach an event handler to it (from code that only runs on the server).

LFT_MilitaryTraffic:

if(!isServer) exitWith {};

// Delete dead vehicles
for "_c" from 0 to ((count militaryVehicleArray) - 1) do {
	private _veh = militaryVehicleArray # _c;
	if(!alive _veh) then {
		militaryVehicleArray deleteAt _c;
	};
};

while {(count militaryVehicleArray) < MAX_VEHICLES } do { 
	
	// Get Vehicle Type
	private _vehicleType = selectRandom vehicleTypeArray;
	// Get Random road positions for start
	private _posStart = [0,0];
	private _startSeg = [] call LFT_GetRandomRoadSeg;
	_posStart = getPos _startSeg;

	// Spawn Vehicle.
	private _roadDir = [_startSeg] call LFT_GetRoadDirection;
	
	private _vehArray = [_posStart, _roadDir, _vehicleType, east] call BIS_fnc_spawnVehicle;
	private _vehObject = _vehArray # 0;
	private _group = _vehArray # 2;
	_group deleteGroupWhenEmpty true;
	
	_vehObject addEventHandler["Killed", {
		params ["_unit", "_killer", "_instigator", "_useEffects"];
		[_unit, _killer] remoteExecCall ["LFT_AwardKillPoints"];
	}];
	
	if(_vehicleType == "O_Truck_02_Ammo_F") then {
		_vehObject addEventHandler["Killed", {
			params ["_unit", "_killer", "_instigator", "_useEffects"];
			for "_c" from 1 to 10 do {
				private _bomb = "Bo_GBU12_LGB" createVehicle (getPos _unit);
				_bomb setDamage 1;
			};
		}];
	};

	militaryVehicleArray pushBack _vehObject;
	
	// Send Vehicle
//	_group = _vehArray # 2;
	[_group] call LFT_SetWaypoint;	
}; 

I assume that the event handler will run on the server so I remoteExecCall a function (LFT_AwardKillPoints)  that has been compiled and placed into a variable.  The variable has been declared a public variable:

initServer:

if(!isServer) exitWith {};

private _year = 2035;
private _month = 7;
private _day = 19;
private _hour = 12;
private _min = floor random 60;

setDate [_year, _month, _day, _hour, _min];

private _handle = [] execVM "scripts\initVariables.sqf";
waitUntil {scriptDone _handle};

LFT_RaptorMaintenance = compileFinal preprocessfilelinenumbers "scripts\LFT_RaptorMaintenance.sqf";
LFT_VehicleMaintenance = compileFinal preprocessfilelinenumbers "scripts\LFT_VehicleMaintenance.sqf";
LFT_MilitaryTraffic = compileFinal preprocessfilelinenumbers "scripts\LFT_MilitaryTraffic.sqf";
LFT_GetRandomRoadSeg = compileFinal preprocessfilelinenumbers "scripts\LFT_GetRandomRoadSeg.sqf";
LFT_SetWaypoint = compileFinal preprocessfilelinenumbers "scripts\LFT_SetWaypoint.sqf";
LFT_GetRoadDirection = compileFinal preprocessfilelinenumbers "scripts\LFT_GetRoadDirection.sqf";
LFT_AwardKillPoints = compileFinal preprocessfilelinenumbers "scripts\LFT_AwardKillPoints.sqf";
LFT_InitBuildingManagement = compileFinal preprocessfilelinenumbers "scripts\LFT_InitBuildingManagement.sqf";


publicVariable "LFT_RaptorMaintenance";
publicVariable "LFT_VehicleMaintenance";
publicVariable "LFT_MilitaryTraffic";
publicVariable "LFT_GetRandomRoadSeg";
publicVariable "LFT_SetWaypoint";
publicVariable "LFT_GetRoadDirection";
publicVariable "LFT_awardKillPoints";

addMissionEventHandler ["entityRespawned",{
  params ["_unit"];
  call {
    if (side _unit isEqualTo WEST) exitWith {_unit setpos getpos respawn_west_1};
  };
}];



[] spawn LFT_MilitaryTraffic;

serverReady = true;
publicVariable "serverReady";

 LFT_AwardKillPoints:

params ["_unit", "_killer"];

if(player isEqualTo _killer) then {
	{
		private _unitType = _x # 0;
		private _unitTypeText = _x # 1;
		private _unitTypeScore = _x # 2;
		if(_unitType isEqualTo (TypeOf _unit)) exitWith {
			hint format ["You have destroyed a %1. +%2 Points!",  _unitTypeText, _unitTypeScore];
			// TODO - add _unitTypeScore to players total score.
		};
	} forEach scoreTable;	
};

The function uses an array called scoreTable that has also been made public:

 

initVariables.sqf:

if(!isServer) exitWith {};

MAX_VEHICLES = 150;

player_1_Score = 0;
player_2_Score = 0;
player_3_Score = 0;
player_4_Score = 0;

vehicleTypeArray = [
	"O_APC_Wheeled_02_rcws_v2_F", "O_MRAP_02_F", "O_MRAP_02_hmg_F", "O_LSV_02_AT_F", "O_LSV_02_armed_F",
	"O_LSV_02_unarmed_F", "O_Truck_03_device_F", "O_Truck_03_ammo_F", "O_Truck_03_fuel_F", "O_Truck_03_medical_F",
	"O_Truck_03_repair_F", "O_Truck_03_transport_F", "O_Truck_03_covered_F", "O_Truck_02_Ammo_F",
	"O_Truck_02_fuel_F", "O_Truck_02_medical_F", "O_Truck_02_box_F", "O_Truck_02_transport_F",
	"O_Truck_02_covered_F"
];

scoreTable = [
	["O_APC_Wheeled_02_rcws_v2_F","Unarmed Ifrit",10],
	["O_MRAP_02_F","Ifrit GMG",30],
	["O_MRAP_02_hmg_F","Ifrit HMG",30],
	["O_LSV_02_AT_F","Qilin (AT)",20],
	["O_LSV_02_armed_F","Qilin (Mini-Gun)",20],
	["O_LSV_02_unarmed_F", "Qilin (Unarmed)", 5],
	["O_Truck_03_device_F","Tempest (Device)",10],
	["O_Truck_03_ammo_F","Tempest (Ammo)",25],
	["O_Truck_03_fuel_F","Tempest (Fuel)",25],
	["O_Truck_03_medical_F","Tempest (Medical)",10],
	["O_Truck_03_repair_F","Tempest (Repair)",25],
	["O_Truck_03_transport_F","Tempest (Transport)",30],
	["O_Truck_03_covered_F","Tempest (Covered Transport)",30],
	["O_Truck_02_Ammo_F","Zamak Ammo",25],
	["O_Truck_02_fuel_F","Zamak Fuel",25],
	["O_Truck_02_medical_F","Zamak Medical",10],
	["O_Truck_02_box_F","Zamak Repair",25],
	["O_Truck_02_transport_F","Zamak Transport",30],
	["O_Truck_02_covered_F","Zamak Transport (Covered)",30]
];
publicVariable "scoreTable";

mainIsland = [[9803.08,9978.81], 5000];

cityArray = [
	["GeorgeTown",[6093.99,10023.6],1000],
	["BluePerl",[13436.6,11933.5],800],
	["Kotomo",[10786.3,6455.53],400],
	["Tanouka",[9029.22,10021.6],500]
];

militaryVehicleArray = [];

Again, It works when I run it from my PC but not on a dedicated server. Any ideas?

 

Thanks.

Share this post


Link to post
Share on other sites

Never mind... I just tested it out on the server after my long post and it is working. 🤪

  • Like 1
  • Haha 1

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

×