Jump to content
Sign in to follow this  
1para{god-father}

EventHandlers causing Freezing on Dedi Server or Public Varibles

Recommended Posts

I am adding Event Handlers to all AI that I spawn in , approx 35 AI

I have 12 players who also have Killed EH added and 4 vehicles.

So I did not think that would be many EH in total, or is it the Public Variable Each time adding up the score causing the Freezing ? if so any suggestions ?

I played a mission and it Froze 1/2 way through each time, if i take of the EH it runs no issue why would it cause the Dedi server to Freeze ?

Example of my spawn..


_grp2 = [_pos, EAST, (configFile >> "CfgGroups" >> "EAST" >> "BIS_TK_INS" >> "Infantry" >> "TK_INS_Patrol")] call BIS_fnc_spawnGroup;
[_grp2,_pos,150] execVM "scripts\BIN_taskPatrol.sqf";
{
 _x addEventHandler ["Killed", { if (isPlayer (_this select 1) AND side (_this select 1) == WEST ) then {totalscore = totalscore + 5;  publicVariable "totalscore";}}];
} forEach (units _grp2);

Share this post


Link to post
Share on other sites

try spawn a function from the eventhandler rather than place the whole code there - may work

Share this post


Link to post
Share on other sites
try spawn a function from the eventhandler rather than place the whole code there - may work

Cheers ill give that a Go, so you do not that it is the PV adding / changing each time ? as it is all run from Server not local

Share this post


Link to post
Share on other sites

I've actually written in your other thread, I wouldn't broadcast the var unless it reaches a certain amount. neokika gave a great example, imagine someone with an MG killing ll of grp2 in a matter of seconds. That means about 35 PV broadcasted in a matter of seconds. It's best to store the score for a kill on the server and broadcast it once the mission is over, like this:

if (totalscore == 50) then {
publicvariable totalscore;
endmission "END1";
};

Share this post


Link to post
Share on other sites

Hi thanks for the Reply.

A little confused now as that is what I though I was doing here is my Scripts that i thought all run from the server ? apart from the EH added to players INIT. how else can i store totalscore unless I use PV ?

////store PV on sever/////

init.sqf

if (isserver) then {

      if (isNil "totalscore") then { totalscore = 0 };
	publicVariable "totalscore"; 

};

Mission.sqf

if(not isServer) exitWith{};
sleep 2;
_towns = nearestLocations [getPosATL player, ["NameVillage","NameCity","NameCityCapital","StrongPoint"], 25000];
_pos = position (_towns select (floor (random (count _towns))));


["clear","Locate & Destroy","Destoy Ammo ",true,["MissionAO",_pos,"flag","ColorYellow"]] call SHK_Taskmaster_add;

////////PATROL MARKER/////////////
_mrk1 = createmarker ["marker_clear",_pos];
_mrk1 setmarkershape "ELLIPSE";
_mrk1 setmarkersize [300,300];
_mrk1 setMarkerColor "ColorRed";
"marker_clear" setMarkerAlpha 0;

sleep .2;

////////////////////////Set UP AI NOW/////////////////////
///////////Spawn Ammo Crate/////////////
_ammobox = createVehicle ["GuerillaCacheBox",getmarkerpos "marker_clear", [], 0, "NONE"];  

_houses = [_ammobox,150] call getEnterableHouses;
if((count _houses) > 0) then {
_house = _houses call getRandomElement;
_buildingpos = 1 max (round random (_house select 1));
_house = _house select 0;
_ammobox setPos (_house buildingPos _buildingpos);
} else {
//_ammobox setPos _pos; take out for testing 
};

sleep .5;


/////DEBUG/////////
if ((paramsarray select 0) == 1) then { 
	_cid = floor(random 10000);
_t = format["ammo is here%1",_cid];
[_t, _ammobox, "Icon", [1,1], "TEXT:", _t, "TYPE:", "dot", "COLOR:", "ColorGreen", "GLOBAL", "PERSIST"] call CBA_fnc_createMarker;
};

//   Create GROUP1 5  Man Team /////////
_grp1 = [_pos, EAST, (configFile >> "CfgGroups" >> "EAST" >> "BIS_TK_INS" >> "Infantry" >> "TK_INS_Patrol")] call BIS_fnc_spawnGroup;
[_grp1,_pos,250] execVM "scripts\BIN_taskPatrol.sqf";
{
 _x addEventHandler ["Killed", { if (isPlayer (_this select 1) AND side (_this select 1) == WEST ) then {totalscore = totalscore + 5;  publicVariable "totalscore";}}];
} forEach (units _grp1);

//////GROUP2    5  Man Team  /////////

_grp2 = [_pos, EAST, (configFile >> "CfgGroups" >> "EAST" >> "BIS_TK_INS" >> "Infantry" >> "TK_INS_Patrol")] call BIS_fnc_spawnGroup;
[_grp2,_pos,150] execVM "scripts\BIN_taskPatrol.sqf";
{
 _x addEventHandler ["Killed", { if (isPlayer (_this select 1) AND side (_this select 1) == WEST ) then {totalscore = totalscore + 5;  publicVariable "totalscore";}}];
} forEach (units _grp2);

///////////Place in Buildings   7 Man Team ///////////////////////

_grpbuild1 = [_pos, EAST, (configFile >> "CfgGroups" >> "EAST" >> "BIS_TK_INS" >> "Infantry" >> "TK_INS_Group")] call BIS_fnc_spawnGroup;
_grpbuild1 execVM "PlaceInBuilding.sqf";
{
 _x addEventHandler ["Killed", { if (isPlayer (_this select 1) AND side (_this select 1) == WEST ) then {totalscore = totalscore + 5;  publicVariable "totalscore"; }}];
} forEach (units _grpbuild1);

_radius = 500;
_exp = "(1 + meadow) * (1 - forest) * (1 - trees)";
_prec = 10;

_bestplace = selectBestPlaces [_pos,_radius,_exp,_prec,1];
_spot = _bestplace select 0;
_spot2 = _spot select 0;

// Cfreat ARMOUR////////////////////
_armourgrp1 = [_spot2, east,["LandRover_MG_TK_INS_EP1", "LandRover_MG_TK_INS_EP1"],[[-3,-3], [3,3]]]  call BIS_fnc_spawnGroup;
[_armourgrp1,_pos,200] execVM "scripts\BIN_taskPatrol.sqf";

{
_x addEventHandler ["Killed",{ if (isPlayer (_this select 1) AND side (_this select 1) == WEST ) then {totalscore = totalscore + 5;  publicVariable "totalscore"; }}];

} forEach units _armourgrp1 ;

//////////////Still need to work out how to add HIT EH to Vehicle
waitUntil {!alive _ammobox};
["clear","succeeded"] call SHK_Taskmaster_upd;
[] call SHK_addTask;
totalscore = totalscore +80;  publicVariable "totalscore";
titleText ["Well Done Mission Succeeded you got an extra 80 Points you score is now......" + str totalscore,"PLAIN DOWN"];titleFadeOut 6;

This is Added to Players INI

this addEventHandler ["Killed", { totalscore = totalscore -100;  publicVariable "totalscore"; }];

then at the end of the mission i just display the score so i do not broadcast it at all now

titleText ["End Of Mission well done Your Score Total is " + str totalscore,"BLACK FADED",20];
SLEEP 15;
endmission "END1";

But this still freezes the server about 30 min in ?!

Edited by psvialli

Share this post


Link to post
Share on other sites

You store the variable automatically when defining it. publicVariable is just to broadcast it properly to every client. The server stores the variable automatically.

Share this post


Link to post
Share on other sites

ahhh so just use:

_x addEventHandler ["Killed",{ if (isPlayer (_this select 1) AND side (_this select 1) == WEST ) then {totalscore = totalscore + 5; }}];

Share this post


Link to post
Share on other sites

Yes, and then the if-statement at the end to display the total score & end the mission.

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  

×