Jump to content

Sign in to follow this  
Fuzzy Bandit

Adding Player Points in MP

Recommended Posts

Hello!

I want to be able to add points to a player in an MP game.

I've tried using the addRating command, but that doesn't add visual points that appear on the scoreboard.

Is there a command / function for this?

Cheers!

Share this post


Link to post
Share on other sites

Indeed, just found that as soon as I posted!

Is there any way to add score to a singular unit using a local script? Maybe using public variables and event handlers?

Share this post


Link to post
Share on other sites

Give this a shot, untested and forgive typos:

In all examples below, TAG_ represents whatever tag you you for your global/public variables.

In your init.sqf, initialize a global array that will later be used to pass information needed for the score update. Also, create a PVEH on the server only to execute a script that will run the addScore command.

// init.sqf

// Create a global/public score array on all machines to store the unit's name and new score value to update when applicable.
TAG_scoreUpdate = [];


// If this machine is the server then add a PVEH to update scores whenever a new value of TAG_scoreUpdate is broadcasted.  For PVEHs, _this select 0: variable name, _this select 1: new variable value. 
if (isServer) then
{
"TAG_scoreUpdate" addPublicVariableEventHandler {_nul = [(_this select 1)] execVM "addScore.sqf";};
};

So you will also need a script that will actually peform the addScore command that is executed by the PVEH.

// addScore.sqf

// Scope
private ["_unit", "_score"];

// Params
_unit = _this select 0;
_score = _this select 1;


// Update the unit's score.
_unit addScore _score;

And finally a script, or scripts, or other method, that runs locally on the clients that will broadcast that PVs the update array.

// updateScore.sqf

// Only run this on clients!!!!

// Scope
private ["_unit", "_score"];

// Insert here whatever condition code you want to change a unit's score.

// Assign a unit and score value (arbitrary example values).
_unit = loon1;
_score = 10;

// Update score array and PV it so the PVEH fires.
TAG_scoreUpdate = [_unit, _score];
publicVariable "TAG_scoreUpdate";

Edited by Loyalguard
Added some comment clarification and correct typos

Share this post


Link to post
Share on other sites

Fantastically cool script. Was never sure of how to create public arrays and how they worked, and it's a great introduction into it!

The only problem is... it's not giving me any points! :D

At the moment, the player is running a local script to which I'm adding:

[player] execVM "updatescore.sqf";

which is then apparently activating the public variable in the init.sqf, which should then run addScore.sqf.

I added a global MP hint to addScore.sqf, but that doesn't appear. I'm not getting any errors with -showScriptErrors, but it's obviously failing somewhere down the line... I just can't figure out where!

EDIT:

Added a few debugging hints. It appears the end of the code (_unit addScore _score;) comes back as:

any addScore <null>;

Any ideas?

Edited by Fuzzy Bandit

Share this post


Link to post
Share on other sites

Hmmm, The way I wrote it (and didn't explain!, sorry!) updateScore.sqf needs the name of the unit AND the score to add. More imporantly... you need to PV both a unit name and a score value for the PVEH to function properly. Are you putting a score value in the array (the second element)? Such as...

TAG_scoreUpdate = [player, 10];
publicVariable "TAG_scoreUpdate";

or

_unit = _this select 0; // passed from [player] execVM "updatescore.sqf";

TAG_scoreUpdate = [_unit, 10];
publicVariable "TAG_scoreUpdate";

or

_score = 10

TAG_scoreUpdate = [player, _score];
publicVariable "TAG_scoreUpdate";

...whatever variation, you need to make sure you PV the unit and the score value in that order in the array...or...if the score to add will always be the same (e.g. 10) you can just pv the unit (in that case just as a single variable not an array) and then change addScore.sqf to always use one value for score. Example:

// updateScore.sqf

_unit = _this select 0; // The player as passed from ...[player] execVM "updateScore.sqf";

TAG_scoreUpdate = _unit;
publicVariable "TAG_scoreUpdate";

// addScore.sqf

// Scope
private ["_unit"];

// Params
_unit = _this select 0;


// Update the unit's score.
_unit addScore 10;

I hope that clarifies/helps...if still not working let me know or post all your code to see if we can troubleshooot.

Share this post


Link to post
Share on other sites

Ok I'll test that as soon as I can. Don't have access to ARMA for a bit, but looks good to me.

The score will be a global variable, initialised in the init.sqf, named 'fcp', and the script WILL be initialised locally from the player's machine ok, so using:

_unit = _this select 0;

TAG_scoreUpdate = [_unit, fcp];
publicVariable "TAG_scoreUpdate";

Should work ok... right? :D

Cheers for the help!

Share this post


Link to post
Share on other sites

That should work...I assume the value of fcp might change throughout and that's why you have it as a global...if so, you should be good to go. Good luck!

Share this post


Link to post
Share on other sites

Ok sounds good - I'll go ahead and test ASAP.

Yeh FCP will be a variable that is changeable in the multiplayer parameters, hence the need for it to be a global.

Share this post


Link to post
Share on other sites

Tested and didn't work, but came up with a much simpler solution.

//init.sqf
fcp = paramsArray select 2;
addit = "waiting";
"addit" addPublicVariableEventHandler {addit addScore fcp;};


//Player-Executed Script
addit = player;
publicVariable "addit";

Sorted. :D

Share this post


Link to post
Share on other sites

I have a 14 man coop mission where 8 bunkers need to be captured. I was hoping to use a progress bar for capturing each bunker, but never found any help on that, so for now a player simply enters one of the bunkers and activates a trigger and the bunker is then instantly captured. What I would like to do is add 10 points to the player that captured the bunker, not the entire team. The players are named s1 through s14. I have been reading this thread and a couple of other threads that discuss "addScore", but I'm still unsure of how to get this working correctly. Can anybody help me with this?

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  

×