Jump to content
Sign in to follow this  
somethingcool

MP, addEventHandler "hit" & broadcasting Variables

Recommended Posts

Hey,

I've been trying for a while now to make my firing range count the number of targets knocked down in a single lane.

I had a series of eventhandlers like so in init.sqf

t11s addEventHandler ["hit", {LaneOne = LaneOne + 1}];
t12s addEventHandler ["hit", {LaneTwo = LaneTwo + 1}];
t13s addEventHandler ["hit", {LaneThree = LaneThree + 1}];
t14s addEventHandler ["hit", {LaneFour = LaneFour + 1}];
t15s addEventHandler ["hit", {LaneFive = LaneFive + 1}];
t16s addEventHandler ["hit", {LaneSix = LaneSix + 1}];
t17s addEventHandler ["hit", {LaneSeven = LaneSeven + 1}];
t18s addEventHandler ["hit", {LaneEight = LaneEight + 1}];
t11k addEventHandler ["hit", {LaneOne = LaneOne + 1}];
t12k addEventHandler ["hit", {LaneTwo = LaneTwo + 1}];

And then use the code (getScore.sqs)

hint format["Lane 1: %1\nLane 2: %2\nLane 3: %3\nLane 4: %4\nLane 5: %5\nLane 6: %6\nLane 7: %7\nLane 8: %8\n", LaneOne, LaneTwo, LaneThree, LaneFour, LaneFive, LaneSix, LaneSeven, LaneEight];

To retrieve the scores from each of the Lanes.

The LaneOne etc.. variables are set up in gameLogics like this

GL named LaneOne

Init Line: LaneOne = 0;

I'm using the simple targets which fall down and stay down.

In single player this works like a dream, in multiplayer it just dosnt... every lane returns 0. I assume this is due to hit being an eventhandler that is local.

So I need to find a way to broadcast the values stored in LaneOne, LaneTwo etc from the server to the clients, as if my understanding is correct the server should have the hit eventhandlers stored because the objects will be local to it?

I looked at publicVariable, setVariable, getVariable, addPublicEventHandler etc.. but I cant fathom out from the wiki how to make them work, its essential it works with a DEDICATED server.

I've also looked over the other threads on this topic and most people seem to be having a problem scoring them correctly.

For reference this is the script ( a little condensed ) that I'm using to actually run the range if anyones interested.

//establish arrays of targets
//S = left K = mid D = right 100etc is m out.

T100S = [t11s, t12s, t13s, t14s, t15s, t16s, t17s, t18s];
T100K = [t11k, t12k, t13k, t14k, t15k, t16k, t17k, t18k];

T200S = [t21s, t22s, t23s, t24s, t25s, t26s, t27s, t28s];
T200K = [t21k, t22k, t23k, t24k, t25k, t26k, t27k, t28k];


sleep 5;

RangeControl sideChat "Adopt the prone position";

[this] exec "rangeDown.sqs"; 
// extra script to set all targets to damage1

sleep 2;

RangeControl sideChat "Four, Five Second Exposures at 100M from the prone position. Fire One Round at Each Target. Targets will fall when hit. Watch and shoot, watch and shoot";

sleep 2;

for [{_i=0}, {_i<4}, {_i=_i+1}] do
{
sleep 1;
{_x setDamage 0} forEach T100S;
sleep 5;
{_x setDamage 1} forEach T100S;
sleep 2;
};

Rangecontrol sideChat "STOP, Stand Up";

sleep 4;

RangeControl sideChat "Adopt the kneeling position";

sleep 5;

RangeControl sideChat "Two, Seven Second Exposures at 200m from the kneeling position. Fire one round at each target, targets will fall when hit. Watch and shoot, watch and shoot.";

sleep 3;

for [{_i=0}, {_i<2}, {_i=_i+1}] do
{
sleep 1;
{_x setDamage 0} forEach T200K;
sleep 7;
{_x setDamage 1} forEach T200K;
sleep 2;
};

[this] exec "getScore.sqs";

This all works in single player without an issue, and if I host I'm sure it would work then too, but on a dedicated server it just refuses to play ball.

Mission Download:

www.dspcs.co.uk/range.utes.rar

Share this post


Link to post
Share on other sites

Fixed it using a couple of methods I found on here for making MP friendly hints.

I'll post the scripts up later.

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  

×