Jump to content

Recommended Posts

Hello everybody.

 

There's a point in my coop-mission, where I want to reset the players ratings.

The script in which I want to do so is run only by server (executed in initServer.sqf).

 

init.sqf

resetRatings = {rating _x} forEach playableUnits;

script.sqf

...

{if (side _x == EAST) then {_x addRating - rating _x}} forEach playableUnits;
resetRatings = {rating _x} forEach playableUnits;
publicVariable "resetRatings";

Testing on a dedicated server, the new result of resetRatings is not broadcasted to my player unit.

 

 

Some help would be much appreciated :)

Share this post


Link to post
Share on other sites

2 methods you can use.

 

1) Publicvariable eventhandler system, called by the server.

The script attached to the PV EH will then run on all machines except the server automatically.

 

2) Boolean activated trigger that runs a script. Server defines the boolean true and (For belts & Braces) pv's it to make sure the trigger fires on all clients

 

To define the players initial start rating, I would run the following code in the init,sqf

if(HasInterface)then{player setvariable ["Ksh_PRating", rating player];};

The code that is then run should be based on the player object

  _startRating = player getvariable "Ksh_PRating";
  _nowRating = rating player;
  _rectifier = 0; 


  if ! (Isnil "_startRating")then
  {
	_rectifier = abs(_startRating - _nowRating);
	If( _startRating > _nowRating)then
	{
		Player addrating (0 - _rectifier);
	}
	else
	{
		Player addrating _rectifier;
	};
  };

Points to note.

You can only addrating, you cannot setrating.

You should be able to add a negative value to reduce the rating.

Addrating has to be done where the unit is local, this is why your addrating is not working when done serverside

 

The code is untested, the following blue line may also work if it's written like the red line (Untried - You never know with arma)

The line used

Player addrating (0 - _rectifier);

Player addrating ( - _rectifier);

 

the code can be simplified more, but I used long variable names and seperated the code to make it more readable for you

  • Like 1

Share this post


Link to post
Share on other sites

Thank you very much for taking the time! This whole scripting thing is very hard for me.

 

I managed now to broadcast a hint from initServer.sqf-executed script to the client.

 

initServer.sqf

[] execVM "broadcast.sqf";

initPlayerLocal.sqf

"msg4client" addPublicVariableEventhandler {
        call (_this select 1);
    publicVariable "msg4client";
};

broadcast.sqf

sleep 3;
//Server side script runs
["Debug-Start","hint",true,true] call BIS_fnc_MP;
sleep 3;

server2client = {
    msg4client = _this select 0;
    if ((_this select 1) == 1) then {call (_this select 0)};
    publicVariable "msg4client";
};

[{{_x groupChat "Dear Client, it's your buddy Server!"} forEach playableunits }, 1] call server2client;

"msg4client" addPublicVariableEventhandler {
    call (_this select 1);
};

sleep 3;
//Script runs through
["Debug-End","hint",true,true] call BIS_fnc_MP;

Now I will try to get it working with the intended resetRatings code.

 

I haven't tested your second option yet, but I will after I survived the first battle  :blink:

 

 

Edit: It seems to work, if I just replace the code in broadcast.sqf

[{{if (side _x == EAST) then {_x addRating - rating _x}} forEach playableUnits;}, 1] call server2client;

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

×