Jump to content
Sign in to follow this  
TurokGMT

Getting sidechat to work  in MP problem

Recommended Posts

Hey guys,

I'm having some bother getting a sidechat generated by a dedicated server get received by clients. I've been looking at various resources trying to debug this, but having no luck.

Here's my init.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

// init.sqf will run automatically on both the server and clients when they connect

// either at mission start, or join in progress clients

// Wait for players to join and synchronise before moving on

// The if statement will only affect clients, a DEDICATED server will never

// have a local player and !isserver will always return false for the server and true for clients

if ( (!isServer) && (player != player) ) then

{

waitUntil {player == player};

waitUntil {time > 10};

};

// Vehicle Respawn script - borrowed from domination, thanks xeno!

// Only needs to be executed on server, hence the if check

if (isserver) then {

_vehicles = [hummer1,hummer2,uaz1,uaz2];

{[_x,20] execvm "x_vehirespawn.sqf"} foreach _vehicles;

};

// Define which objectives belong to which team

// objectives have been defined in briefing.html

// this must be done local to each player, after the player has joined and synced

_objectives_blufor = ["1","2","3","4","5"];

_objectives_opfor = ["6","7","8","9","10"];

// Hide objectives from opposing teams

switch (side player) do

{

// BLUFOR Player

case west:

{

{_x objStatus "HIDDEN"} forEach _objectives_opfor;

};

// OPFOR Player

case east:

{

{_x objStatus "HIDDEN"} forEach _objectives_blufor;

};

};

// Script to keep weapons when respawning

// must be run by players locally?

_units = ["sierra1","sierra2","sierra3","sierra4","sierra5","sierra6","officer","durka1","durka2","durka3","durka4","durka5","durka6","durka7"];

{[_x,1] exec "weapons_respawn.sqs"} foreach _units;

// Pop-up targets reset scripting (to make them pop back up after being shot)

// arrays for two groups of targets, just incase you want to disable one set from popping back up

// should be run on server only and return a public variable to enable broadcast

// of a sidechat message

if (isserver) then {

// target arrays, using names given in editor

_opfor_targets = [RED1,RED2,RED3,RED4,RED5,RED6];

_blufor_targets = [BLUE1,BLUE2,BLUE3,BLUE4];

// Comment out following lines to DISABLE pop-up on a target group

{[_x, 1, true] execVM "InitPopUpTarget.sqf"} foreach _opfor_targets;

{[_x, 1, true] execVM "InitPopUpTarget.sqf"} foreach _blufor_targets;

};

// this event handler monitors a variable defined in the pop up target script called myvar

// when myvar is updated publically using publicvariable, the code within the event handler is fired

// on all machines OTHER than where the variable was made public (ie the server itself)

// the main job of the event handler is to send a globalchat message, therefore the server doesn't

// need it because it has no local player

"myvar" addPublicVariableEventHandler

{

if ((_this select 0) != null) then {

player globalChat format ["Confirmed hit on target %1",(_this select 1)];

_shot = null;

};

};

and here's the relevant script that helps generate the globalchat (initpopuptarget.sqf):

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

// this script should be being run by every pop up target on dedi server and client machines

// pop up feature is working, but sidechat is proving to be a pain

/* InitPopUpTarget.sqf

*

* SYNTAX: nil = [Object, Number, Boolean] execVM "InitPopUpTarget.sqf"

*

* PARAMETERS: Object: A pop-up target

* Number: The number of hits it takes to knock the target down

* Boolean: If set to True, the target will pop up again.

*

* NOTES: This function is meant to be placed in the Initialization field

* of a pop-up target.

*

* Pop-up targets that are not initialized with this function will

* stop working as expected: they won't pop up again. This is

* because this function sets the global variable "nopop" to True.

*/

#define VERSION 0.1

#define HIT_COUNTER "HitCounter"

#define ONHIT_PARAMS "AdvPopUp_OnHit_Params"

#define ONHIT_HANDLER "AdvPopUp_OnHit_Handler"

#define ONHIT_INDEX "AdvPopUp_OnHit_Index"

nopop = true;

_target = _this select 0;

_requiredHits = _this select 1;

_isPopUp = _this select 2;

_hitHandler = {

private ["_target", "_requiredHits", "_isPopUp", "_hitCount", "_keepUp"];

_target = _this select 0;

_requiredHits = _this select 1;

_isPopUp = _this select 2;

if (_target animationPhase "terc" > 0.1) exitWith {};

_hitCount = (_target getVariable HIT_COUNTER) + 1;

_keepUp = true;

if (_hitCount == _requiredHits) then {

////////////////

// ADDED CODE //

////////////////

// code designed to fire an even handler defined in init.sqf

myvar = _target;

publicVariable "myvar"; // This executes the event handler on other machines

sleep 1;

myvar = null;

publicvariable "myvar"; // This now sends a null value to the same event handler

///////////////////////

// END OF ADDED CODE //

///////////////////////

_hitCount = 0;

_target animate ["terc", 1];

sleep 3;

_keepUp = _isPopUp;

};

if _keepUp then {

_target animate ["terc", 0];

};

_target setVariable [HIT_COUNTER, _hitCount];

};

_target setVariable [HIT_COUNTER, 0];

_target setVariable [ONHIT_PARAMS, _this];

_target setVariable [ONHIT_HANDLER, _hitHandler];

_code = {

_t = _this select 0;

(_t getVariable ONHIT_PARAMS) spawn (_t getVariable ONHIT_HANDLER); // weird!

};

_index = _target addEventHandler ["Hit", _code];

_target setVariable [ONHIT_INDEX, _index];

Can anyone help me solve this problem?

Thanks in advance.

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  

×