Jump to content
ARCH93

PlayerRating “cutrsc”

Recommended Posts

I’ve been using “Player Rating“ as a currency for a game mode for me and my friends, (using VASS), 

 the below code in my ini.sqf to show each players “Money”:

 

onEachFrame {hintSilent format ["MONEY”: %1", rating player]};

 

So every time they kill an enemy unit or pick up certain items their Rating/Money changes.

 

However I noticed “Cutrsc”; I’m scratching my head trying to figure out the best way to display this info so I can use the “hint” system for other things. 
 

Any help is appreciated! Thank you.

Share this post


Link to post
Share on other sites

A lot of good info in this topic:

 

 

but keep asking your questions here.

  • Like 1

Share this post


Link to post
Share on other sites

Harzach! Thank you!

 

So I looked in "cutRsc and Updating Variables" I also found this:

 

https://forums.bohemia.net/forums/topic/207620-show-each-players-rank-on-screen-in-dedicated-server/

 

I tried to mimic Larrow's code for my own cutRsc:

 

Description.ext

#include "ui\baseDefines.hpp" 
#include "VASS\gui\cfgGUI.hpp"

class RscTitles
{
	#include "ui\playerStatsUI.hpp"
};


class CfgFunctions
{
	#include "functions\playerStatsFunctions.hpp"
	#include "VASS\CfgFunctions.hpp" // this is from VASS (Virtual Arsenal Shop System)	
};

 

 

 

iniPlayerLocal.sqf

"playerRatingLayer" cutRsc [ "playerRating", "PLAIN" ];

 

baseDefines.hpp

#define CT_STATIC				0
#define ST_LEFT					0x00
#define GUI_GRID_WAbs			((safezoneW / safezoneH) min 1.2)
#define GUI_GRID_HAbs			(GUI_GRID_WAbs / 1.2)
#define GUI_GRID_H				(GUI_GRID_HAbs / 25)
#define GUI_TEXT_SIZE_MEDIUM	(GUI_GRID_H * 1)

class RscText
{
	deletable = 0;
	fade = 0;
	access = 0;
	type = CT_STATIC;
	idc = -1;
	colorBackground[] = {0,0,0,0};
	colorText[] = {1,1,1,1};
	text = "";
	fixedWidth = 0;
	x = 0;
	y = 0;
	h = 0.037;
	w = 0.3;
	style = ST_LEFT;
	shadow = 1;
	colorShadow[] = {0,0,0,0.5};
	font = "RobotoCondensed";
	SizeEx = GUI_TEXT_SIZE_MEDIUM;
	linespacing = 1;
	tooltipColorText[] = {1,1,1,1};
	tooltipColorBox[] = {1,1,1,1};
	tooltipColorShade[] = {0,0,0,0.65};
};

playerStatsUI.hpp

class playerRating
{
	idd = -1;
	fadein = 0;
	fadeout = 0;
	duration = 1e10;

	class controls
	{
		class rank : RscText
		{
			x = 0; //change this to position text on screen
			y = 0; //change this to position text on screen
			w = 0.06 * safeZoneW;
			h = 0.02 * safeZoneH;

			text = "MONEY: ";
			onLoad = "uinamespace setVariable [ 'playerRatingText', _this select 0 ]; _this select 0 call TAG_fnc_updatePlayerRating";
		};
	};
};

playerStatsFunctions.hpp

class ui
{
	tag = "TAG";
	class playerInfo
	{
		file = "functions";
		class updatePlayerRating {};
	};
};

fn_updatePlayerRank.sqf

uiNamespace getVariable "playerRatingText" ctrlSetText format[ "MONEY: %1", player rating ];

 

I was able to use his original code and in poking around was able to get text with "MONEY:0" by only changing: [ "Rank: %1", rank player ];   to ------> [ "MONEY: %1", player rating ]; in the fn_updatePlayerRank.sqf 

 

However I noticed when killing NPC's it wouldn't update the rating in the text "MONEY:0".

 

Right now the above code is what I have after fiddling with it.  

Share this post


Link to post
Share on other sites

You missed some critical info regarding fn_updatePlayerRank.sqf toward the bottom of Larrow's post:

 

Quote

This function needs calling every time you change the players rank and will update the text in the ui.

 

So, every time a player's rank changes, you need to call the function. Fortunately, there's an event handler for just that:  https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#HandleRating

//initPlayerLocal.sqf

params ["_player", "_didJIP"];

_player addEventHandler ["HandleRating", {
	params ["_unit", "_rating"];
	call TAG_fnc_updatePlayerRank;
}];

 

 

Also, when you see someone use "TAG" in an example, it is just a placeholder for your OPFEC tag. Mine is HARZ. You could use ARCH or A93 or whatever you want. You can even register your tag on the OPFEC site: https://www.ofpec.com/tags/

Share this post


Link to post
Share on other sites

As well as what @Harzach mentions...

 

10 hours ago, ARCH93 said:

class updatePlayerRating {};

10 hours ago, ARCH93 said:

fn_updatePlayerRank.sqf

You changed the name of the script file in CfgFunctions but have not updated the actual file name. These need to match for CfgFunctions to find the file and compile it.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you! Appreciate both of you taking the time to look into this.

 

Still having issues though, I will share below of what I have for the sake of clarity:

 

Description.ext

#include "ui\baseDefines.hpp"
#include "VASS\gui\cfgGUI.hpp"

class RscTitles
{
	#include "ui\playerStatsUI.hpp"
};

class CfgFunctions
{
	#include "functions\playerStatsFunctions.hpp"
	
	#include "VASS\CfgFunctions.hpp"	
};

initPlayerLocal.sqf

waitUntil{ !isNull call BIS_fnc_displayMission };

"playerRatingLayer" cutRsc [ "playerRating", "PLAIN" ];

params ["_player", "_didJIP"];

_player addEventHandler ["HandleRating", {
	params ["_unit", "_rating"];
	call TAG_fnc_updatePlayerRating;;
}];

ui\baseDefines.hpp

#define CT_STATIC				0
#define ST_LEFT					0x00
#define GUI_GRID_WAbs			((safezoneW / safezoneH) min 1.2)
#define GUI_GRID_HAbs			(GUI_GRID_WAbs / 1.2)
#define GUI_GRID_H				(GUI_GRID_HAbs / 25)
#define GUI_TEXT_SIZE_MEDIUM	(GUI_GRID_H * 1)

class RscText
{
	deletable = 0;
	fade = 0;
	access = 0;
	type = CT_STATIC;
	idc = -1;
	colorBackground[] = {0,0,0,0};
	colorText[] = {1,1,1,1};
	text = "";
	fixedWidth = 0;
	x = 0;
	y = 0;
	h = 0.037;
	w = 0.3;
	style = ST_LEFT;
	shadow = 1;
	colorShadow[] = {0,0,0,0.5};
	font = "RobotoCondensed";
	SizeEx = GUI_TEXT_SIZE_MEDIUM;
	linespacing = 1;
	tooltipColorText[] = {1,1,1,1};
	tooltipColorBox[] = {1,1,1,1};
	tooltipColorShade[] = {0,0,0,0.65};
};

ui\playerStatsUI.hpp

class playerRating
{
	idd = -1;
	fadein = 0;
	fadeout = 0;
	duration = 1e10;

	class controls
	{
		class rank : RscText
		{
			x = 0; //change this to position text on screen
			y = 0; //change this to position text on screen
			w = 0.12 * safeZoneW;
			h = 0.02 * safeZoneH;

			text = "Rating: ";
			onLoad = "uinamespace setVariable [ 'playerRatingText', _this select 0 ]; _this select 0 call TAG_fnc_updatePlayerRating";
		};
	};
};

functions\playerStatsFunctions.hpp

class ui
{
	tag = "TAG";
	class playerInfo
	{
		file = "functions";
		class updatePlayerRating {};
	};
};

functions\fn_updatePlayerRating.sqf

uiNamespace getVariable "playerRatingText" ctrlSetText format ["MONEY: %1", rating player];

 

In my example mission; the right side (as you guys know) is the Cutrsc. The left is a hint I call using debug:

onEachFrame {hintSilent format ["MONEY: %1", rating player]};

As I kill an opfor unit; the right side stays  MONEY:0 while the hint updates to MONEY:200

 

 

Share this post


Link to post
Share on other sites

Got that backwards, right side hint, left side cutrsc

Share this post


Link to post
Share on other sites

OK well I was wrong, it's working but the number is off.

 

For every regular infantry kill is equal to +200, https://community.bistudio.com/wiki/ArmA:_Armed_Assault:_Rating_Values

 

However on the first kill it doesn't change the variable; only on the second kill does it show MONEY:200; where instead it should show MONEY:400 

 

Almost there! Couldn't make it this far without this community.

 

 

edit: So its only the first kill that isn't counted; it seems to be counting consistently after that

Share this post


Link to post
Share on other sites

What happens if you pass the 'to be added' rating value from the event? rather than relying on just the current value of the rating command.

Is it just the event fires before rating is updated, seeing as you can change the rating value through the event. So would make sense the return from the rating command is not updated to reflect the new value until the event finishes, which involves the call to the function, so will not happen until after to UI text is updated.

//initPlayerLocal.sqf
_player addEventHandler ["HandleRating", {
	params ["_unit", "_rating"];
	
	_rating call TAG_fnc_updatePlayerRating;
}];
//functions\fn_updatePlayerRating.sqf
uiNamespace getVariable "playerRatingText" ctrlSetText format[ "MONEY: %1", _this + rating player ];

 

  • Like 1

Share this post


Link to post
Share on other sites

Larrow, glad your still here man. Grateful for your work.

 

So it's getting closer, this is what I have so far:

 

initPlayerLocal.sqf

waitUntil{ !isNull call BIS_fnc_displayMission };

"playerRatingLayer" cutRsc [ "playerRating", "PLAIN" ];

_player = c1;

_player addEventHandler ["HandleRating", {
	params ["_unit", "_rating"];
	
	_rating call TAG_fnc_updatePlayerRating;
}];

(I added _player = c1; after it was giving me an error with an undefined variable. I assume I would go ahead and give names to all playable units here?)

fn_updatePlayerRating.sqf

uiNamespace getVariable "playerRatingText" ctrlSetText format ["MONEY: %1", _this + rating player];

First thing, 

The  "MONEY:#" is updating in real time; however any changes other than killing enemies, like picking up items or using VASS to "buy" items, do not update automatically. 

 

ex.  I start the mission by killing an opfor unit: "MONEY:0" --changes to---> "MONEY:200"

 

       I go to my VASS shop that uses Player Rating as currency it shows $200 matching my current rating.

 

       I purchase a random weapon that costs $1 for testing.

 

      cutrsc rating still = "MONEY:200" VASS shows updated rating of $199.

 

      Spawn another opfor unit and kill that unit so now it updates giving me "MONEY:399"

 

The same thing happens for me  when I use:

Trigger:

Condition:
"CUP_item_Money" in UniformItems player;

Activation:
player addRating 2000; player removeItem "CUP_item_Money"

edit:It's only after killing the opfor unit does it show the extra "2000"

 

So far Rating changes only on killing hostile units.

 

Second, I noticed an error when I first open the test mission:

'... ctrlSetText format[ "MONEY: %1", _this |#|+ rating player ];'
Error +: Type Control, expected Number,Array,String,Not a number

 

 

Share this post


Link to post
Share on other sites
1 hour ago, ARCH93 said:

I added _player = c1; after it was giving me an error with an undefined variable.

 

Why did you remove the params line? That's what defines "_player" in initPlayerLocal.sqf.

params ["_player", "_didJIP"];  //  THIS SHOULD BE LINE 1

waitUntil{ !isNull call BIS_fnc_displayMission };

"playerRatingLayer" cutRsc [ "playerRating", "PLAIN" ];

_player addEventHandler ["HandleRating", {
	params ["_unit", "_rating"];
	_rating call TAG_fnc_updatePlayerRating;
}];

 

Just gave this a try and it works fine.

  • Like 1

Share this post


Link to post
Share on other sites
9 hours ago, ARCH93 said:

(I added _player = c1; after it was giving me an error with an undefined variable. I assume I would go ahead and give names to all playable units here?)

fn_updatePlayerRating.sqf

As @Harzach says initPlayerLocal is passed params of whom the player is, just add the params line as shown back in.

 

 

9 hours ago, ARCH93 said:

The  "MONEY:#" is updating in real time; however any changes other than killing enemies, like picking up items or using VASS to "buy" items, do not update automatically. 

Whenever you update the rating manually ( via addRating, VAS / your CUP money trigger ) you need to call the function. The rating EH only fires when the engine changes the rating (i.e for things like killing units).

e.g

Activation:
player addRating 2000; player removeItem "CUP_item_Money"; 0 call TAG_fnc_updatePlayerRating;

 

 

9 hours ago, ARCH93 said:

Second, I noticed an error when I first open the test mission:


'... ctrlSetText format[ "MONEY: %1", _this |#|+ rating player ];'
Error +: Type Control, expected Number,Array,String,Not a number

 

Change this line in ui\playerStatsUI.hpp...

From

onLoad = "uinamespace setVariable [ 'playerRatingText', _this select 0 ]; _this select 0 call TAG_fnc_updatePlayerRating";

To

onLoad = "uinamespace setVariable [ 'playerRatingText', _this select 0 ]; 0 call TAG_fnc_updatePlayerRating";

As there is no need to pass the control from the onLoad as we use the uiNamespace variable to get it, and we have changed the parameter to the rating amount to add instead.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you! Got it working.

 

Appreciate both of you for helping me

Share this post


Link to post
Share on other sites

I’m sorry to bring up a discussion that I thought was closed but, it turns out whoever hosts can see the “Money:” but whoever joins can’t. I’m going to do some digging to see what’s wrong but thought I’d ask here as well

 

I really appreciate the help with all this

Share this post


Link to post
Share on other sites
On 3/26/2023 at 2:18 PM, ARCH93 said:

I’m going to do some digging to see what’s wrong but thought I’d ask

Sorry been ill for a couple of weeks and really didn't have the mindset to look into this at the time, did you get this sorted @ARCH93? or you still need help?

Share this post


Link to post
Share on other sites

Larrow, Glad your doing better man!

 

Seems to be working for all clients using:

if (hasInterface) then { -----------> This is what I added, seems to be working for clients now instead of just the host.
params ["_player", "_didJIP"];  

waitUntil{ !isNull call BIS_fnc_displayMission };

"playerRatingLayer" cutRsc [ "playerRating", "PLAIN" ];

_player addEventHandler ["HandleRating", {
	params ["_unit", "_rating"];
	_rating call TAG_fnc_updatePlayerRating;
}];

 

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

×