Jump to content
nebulazerz

Way to use BIS_fnc_dynamicText in this script without it lagging it out?

Recommended Posts

I am trying to display xp/cash gain and level gain when a player updates their stats but using these in here seems to really lag up the scripts and make the level system work kind of funny. Is there a better way I can add the dynamicText to not lag up this script?

 

Edit: also I am trying to figure out the correct variable to show the difference in old xp to new xp. What I am using here is not correct, just what I was messing around with when i noticed how laggy it got.

//Function to update stats
fnc_updateStats = {

	//Get current experience
	_exp = player getVariable [ "experience", 0 ];
	_myLvl = player getVariable [ "level", 0 ];
	_tmpExp = _exp;
	_level = 0;
	_oldLevel = _myLvl;

	//Max value of level 1
	_expForNextLevel = 100;
	//Work out new level
	while { _tmpExp >= _expForNextLevel } do {
		_level = _level + 1;
		_tmpExp = _tmpExp - _expForNextLevel;
		_xpText = format [ "%1 XP", _tmpExp ];
		["<t color='#B8AB67' size = '.4'>" + _xpText + "</t>",safezoneX + 0.25 * safezoneW,safezoneY,4,1,0,789] call bis_fnc_dynamicText;
		//Every level needs twice as much exp as the level before
		_expForNextLevel = _expForNextLevel * 2;
	};
	//Set players level, minimum it can be is 0
	_myLvl = _level max 0;

	//If we increased in level
	if ( _level > _oldLevel ) then {
		//Inform player of level increase
		_lvlText = format [ " LEVEL UP!<br />Now Level %1", _myLvl ];
		["<t color='#B8AB67' size = '.4'>" + _lvlText + "</t>",safezoneX + 0.3 * safezoneW,safezoneY,4,1,0,789] call bis_fnc_dynamicText;
		[ [], "fnc_levelUpRewards", player ] call BIS_fnc_MP;
	};

	//Get progress to next level
	_progress = linearConversion [ 0, _expForNextLevel, _tmpExp, 0, 1 ];
	//Get player stats
	_cash = player getVariable [ "cash", 0 ];
	_kills = player getVariable [ "kills", 0 ];
	player setVariable [ "level", _myLvl, true ];
	

	//Update UI with stats
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIlevel ) ctrlSetText ( format [ "Level : %1", _myLvl ] );
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIprogress ) ctrlSetText ( format [ "XP : %1/%2", _tmpExp, _expForNextLevel ] );
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIprogressBar ) progressSetPosition _progress;
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIcash ) ctrlSetText ( format [ "Money : $%1", _cash ] );
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIkills ) ctrlSetText ( format [ "Kills : %1", _kills ] );
};

Share this post


Link to post
Share on other sites

You need to put a sleep in that while loop.

Share this post


Link to post
Share on other sites

You need to put a sleep in that while loop.

hm, there was no sleep in the while loop before, I am not the original author of the level script though i have made some modifications. Just tried adding a sleep, same results. Should I call the dynamicTexts from their own functions?

 

Edit : also, the script works perfect without the dynamicText

 

Like this it is less laggy (but no xp gain show, and still a little laggy at start up.)

fnc_updateStats = {

	//Get current experience
	_exp = player getVariable [ "experience", 0 ];
	_myLvl = player getVariable [ "level", 0 ];
	_tmpExp = _exp;
	_level = 0;
	_oldLevel = _myLvl;

	//Max value of level 1
	_expForNextLevel = 100;
	//Work out new level
	while { _tmpExp >= _expForNextLevel } do {
		_level = _level + 1;
		_tmpExp = _tmpExp - _expForNextLevel;
		//Every level needs twice as much exp as the level before
		_expForNextLevel = _expForNextLevel * 2;
	};
	//Set players level, minimum it can be is 0
	_myLvl = _level max 0;

	//If we increased in level
	if ( _level > _oldLevel ) then {
		//Inform player of level increase
		_lvlText = format [ " LEVEL UP!<br />Now Level %1", _myLvl ];
		["<t color='#B8AB67' size = '.4'>" + _lvlText + "</t>",safezoneX + 0.3 * safezoneW,safezoneY,4,1,0,789] call bis_fnc_dynamicText;
		[ [], "fnc_levelUpRewards", player ] call BIS_fnc_MP;
	};

	//Get progress to next level
	_progress = linearConversion [ 0, _expForNextLevel, _tmpExp, 0, 1 ];
	//Get player stats
	_cash = player getVariable [ "cash", 0 ];
	_kills = player getVariable [ "kills", 0 ];
	player setVariable [ "level", _myLvl, true ];
	

	//Update UI with stats
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIlevel ) ctrlSetText ( format [ "Level : %1", _myLvl ] );
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIprogress ) ctrlSetText ( format [ "XP : %1/%2", _tmpExp, _expForNextLevel ] );
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIprogressBar ) progressSetPosition _progress;
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIcash ) ctrlSetText ( format [ "Money : $%1", _cash ] );
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIkills ) ctrlSetText ( format [ "Kills : %1", _kills ] );
};

This is not laggy at all

fnc_updateStats = {

	//Get current experience
	_exp = player getVariable [ "experience", 0 ];
	_myLvl = player getVariable [ "level", 0 ];
	_tmpExp = _exp;
	_level = 0;
	_oldLevel = _myLvl;

	//Max value of level 1
	_expForNextLevel = 100;
	//Work out new level
	while { _tmpExp >= _expForNextLevel } do {
		_level = _level + 1;
		_tmpExp = _tmpExp - _expForNextLevel;
		//Every level needs twice as much exp as the level before
		_expForNextLevel = _expForNextLevel * 2;
	};
	//Set players level, minimum it can be is 0
	_myLvl = _level max 0;

	//If we increased in level
	if ( _level > _oldLevel ) then {
		//Inform player of level increase
		[ [], "fnc_levelUpRewards", player ] call BIS_fnc_MP;
	};

	//Get progress to next level
	_progress = linearConversion [ 0, _expForNextLevel, _tmpExp, 0, 1 ];
	//Get player stats
	_cash = player getVariable [ "cash", 0 ];
	_kills = player getVariable [ "kills", 0 ];
	player setVariable [ "level", _myLvl, true ];
	

	//Update UI with stats
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIlevel ) ctrlSetText ( format [ "Level : %1", _myLvl ] );
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIprogress ) ctrlSetText ( format [ "XP : %1/%2", _tmpExp, _expForNextLevel ] );
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIprogressBar ) progressSetPosition _progress;
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIcash ) ctrlSetText ( format [ "Money : $%1", _cash ] );
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIkills ) ctrlSetText ( format [ "Kills : %1", _kills ] );
};

Share this post


Link to post
Share on other sites

I have switched to trying to do this with dialogs but I cant seem to get the structuredText to popup the way the dynamic text did. I can get the control to display text if I put something in just the control. This will probably fix my problem if I can get it working correctly this way. I am not getting any errors, any idea why its not displaying?

 

in playerinfo.hpp

class structuredText
		{
			idc = 1005;
			text = ""; //--- ToDo: Localize;
			x = "SafeZoneX + (1020 / 1920) * SafeZoneW";
			y = "SafeZoneY + (0 / 1080) * SafeZoneH";
			w = "(120 / 1920) * SafeZoneW";
			h = "(30 / 1080) * SafeZoneH";
			ColorText[] = {0.9, 0.9, 0.9, 0.9};
		};

controls are being defined as such at top of initPlayerLocal.sqf

#define UIlevel 1000
#define UIprogress 1001
#define UIprogressBar 1002
#define UIcash 1003
#define UIkills 1004
#define UIlevelUP 1005

Function that updates info and displays the UIs for the level and hopefully the structuredtext every time the player levels. There are no errors but it does not display _lvlText on the screen

fnc_updateStats = {

	//Get current experience
	_exp = player getVariable [ "experience", 0 ];
	_myLvl = player getVariable [ "level", 0 ];
	_tmpExp = _exp;
	_level = 0;
	_oldLevel = _myLvl;

	//Max value of level 1
	_expForNextLevel = 100;
	//Work out new level
	while { _tmpExp >= _expForNextLevel } do {
		_level = _level + 1;
		_tmpExp = _tmpExp - _expForNextLevel;
		//Every level needs twice as much exp as the level before
		_expForNextLevel = _expForNextLevel * 2;
	};
	//Set players level, minimum it can be is 0
	_myLvl = _level max 0;

	//If we increased in level
	if ( _level > _oldLevel ) then {
		//Inform player of level increase
		_lvlText = format [ " LEVEL UP!<br />Now Level %1", _myLvl ];
		(uiNamespace getVariable "UIplayerInfo" displayCtrl UIlevelUp ) ctrlSetStructuredText (parseText format [ "%1", _lvlText ] );
		//["<t color='#B8AB67' size = '.4'>" + _lvlText + "</t>",safezoneX + 0.3 * safezoneW,safezoneY,4,1,0,789] call bis_fnc_dynamicText;
		[ [], "fnc_levelUpRewards", player ] call BIS_fnc_MP;
	};

	//Get progress to next level
	_progress = linearConversion [ 0, _expForNextLevel, _tmpExp, 0, 1 ];
	//Get player stats
	_cash = player getVariable [ "cash", 0 ];
	_kills = player getVariable [ "kills", 0 ];
	player setVariable [ "level", _myLvl, true ];
	

	//Update UI with stats
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIlevel ) ctrlSetText ( format [ "Level : %1", _myLvl ] );
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIprogress ) ctrlSetText ( format [ "XP : %1/%2", _tmpExp, _expForNextLevel ] );
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIprogressBar ) progressSetPosition _progress;
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIcash ) ctrlSetText ( format [ "Money : $%1", _cash ] );
	(uiNamespace getVariable "UIplayerInfo" displayCtrl UIkills ) ctrlSetText ( format [ "Kills : %1", _kills ] );
	
};

EDIT: Found a solution and its the easiest thing ever.

[ [], "fnc_showLevelUp", player ] call BIS_fnc_MP;

fnc_showLevelUp = {
	_myLvl = player getVariable [ "level", 0 ];
	_lvlText = format [ " LEVEL UP! Now Level %1", _myLvl ];
	["<t color='#B8AB67' size = '.4'>" + _lvlText + "</t>",safezoneX + 0.3 * safezoneW,safezoneY,4,1,0,789] call bis_fnc_dynamicText;
};

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

×