ROTAHOE 3 Posted May 3, 2017 So first off here's my code that I would like to add: if (_rank >= 30) then { player spawn { _pilot = _this; private _price = 25000; if([_price] call HG_fnc_hasEnoughMoney) then { [25000,1] call HG_fnc_addOrSubCash; _jet = createVehicle ["B_Plane_CAS_01_F", [4113.665,800.764,1200], [], 0, "FLY"]; _jet setDir 0; _jet setVelocityModelSpace [0,150,0]; _pilot moveInDriver _jet; removeUniform _pilot; removeBackpackGlobal _pilot; removeHeadgear _pilot; _pilot forceAddUniform "U_O_PilotCoveralls"; _pilot addBackpackGlobal "B_parachute"; _pilot addHeadgear "H_PilotHelmetFighter_O"; _jet addAction ["Re-Arm Jet", "scripts\Rearm_Jet.sqf"]; hint format ["%1 \nYou have brought A10 Good Luck!",name _pilot]; } else { hint format ["%1 \nYou don't have enough money!",name _pilot] }; }; I've tried a few ways with adding this but with fail. The code just wont run, even after changing my xp in the datebase to match rank 30 ( 45000). Heres the getRankInfo.sqf _xp = _this; _rank = 0; _nextrankxp = 0; if (_xp >= 250000) then { _rank = 50; _nextrankxp = 0; }else{ if (_xp >= 230000) then { _rank = 49; _nextrankxp = 250000; }else{ if (_xp >= 210000) then { _rank = 48; _nextrankxp = 230000; }else{ if (_xp >= 190000) then { _rank = 47; _nextrankxp = 210000; }else{ if (_xp >= 170000) then { _rank = 46; _nextrankxp = 180000; }else{ if (_xp >= 150000) then { _rank = 45; _nextrankxp = 170000; }else{ if (_xp >= 140000) then { _rank = 44; _nextrankxp = 150000; }else{ if (_xp >= 130000) then { _rank = 43; _nextrankxp = 140000; }else{ if (_xp >= 120000) then { _rank = 42; _nextrankxp = 130000; }else{ if (_xp >= 110000) then { _rank = 41; _nextrankxp = 120000; }else{ if (_xp >= 100000) then { _rank = 40; _nextrankxp = 110000; }else{ if (_xp >= 90000) then { _rank = 39; _nextrankxp = 100000; }else{ if (_xp >= 85000) then { _rank = 38; _nextrankxp = 90000; }else{ if (_xp >= 80000) then { _rank = 37; _nextrankxp = 85000; }else{ if (_xp >= 75000) then { _rank = 36; _nextrankxp = 80000; }else{ if (_xp >= 70000) then { _rank = 35; _nextrankxp = 75000; }else{ if (_xp >= 65000) then { _rank = 34; _nextrankxp = 70000; }else{ if (_xp >= 60000) then { _rank = 33; _nextrankxp = 65000; }else{ if (_xp >= 55000) then { _rank = 32; _nextrankxp = 60000; }else{ if (_xp >= 50000) then { _rank = 31; _nextrankxp = 55000; }else{ if (_xp >= 45000) then { _rank = 30; _nextrankxp = 50000; }else{ if (_xp >= 40000) then { _rank = 29; _nextrankxp = 45000; }else{ if (_xp >= 37000) then { _rank = 28; _nextrankxp = 40000; }else{ if (_xp >= 34000) then { _rank = 27; _nextrankxp = 37000; }else{ if (_xp >= 31000) then { _rank = 26; _nextrankxp = 34000; }else{ if (_xp >= 28000) then { _rank = 25; _nextrankxp = 31000; }else{ if (_xp >= 25000) then { _rank = 24; _nextrankxp = 28000; }else{ if (_xp >= 22000) then { _rank = 23; _nextrankxp = 25000; }else{ if (_xp >= 19000) then { _rank = 22; _nextrankxp = 22000; }else{ if (_xp >= 16000) then { _rank = 21; _nextrankxp = 19000; }else{ if (_xp >= 14000) then { _rank = 20; _nextrankxp = 16000; }else{ if (_xp >= 12000) then { _rank = 19; _nextrankxp = 14000; }else{ if (_xp >= 10000) then { _rank = 18; _nextrankxp = 12000; }else{ if (_xp >= 9000) then { _rank = 17; _nextrankxp = 10000; }else{ if (_xp >= 8000) then { _rank = 16; _nextrankxp = 9000; }else{ if (_xp >= 7000) then { _rank = 15; _nextrankxp = 8000; }else{ if (_xp >= 6200) then { _rank = 14; _nextrankxp = 7000; }else{ if (_xp >= 5400) then { _rank = 13; _nextrankxp = 6200; }else{ if (_xp >= 4800) then { _rank = 12; _nextrankxp = 5400; }else{ if (_xp >= 4200) then { _rank = 11; _nextrankxp = 4800; }else{ if (_xp >= 3600) then { _rank = 10; _nextrankxp = 4200; }else{ if (_xp >= 3100) then { _rank = 9; _nextrankxp = 3600; }else{ if (_xp >= 2600) then { _rank = 8; _nextrankxp = 3100; }else{ if (_xp >= 2100) then { _rank = 7; _nextrankxp = 2600; }else{ if (_xp >= 1700) then { _rank = 6; _nextrankxp = 2100; }else{ if (_xp >= 1300) then { _rank = 5; _nextrankxp = 1700; }else{ if (_xp >= 900) then { _rank = 4; _nextrankxp = 1300; }else{ if (_xp >= 600) then { _rank = 3; _nextrankxp = 900; }else{ if (_xp >= 300) then { _rank = 2; _nextrankxp = 300; }else{ _rank = 1; _nextrankxp = 100; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; }; _output = [_rank, _nextrankxp]; _output and this is the database getPlayerStats.sqf if (isServer) then { //check if player exists in db _unit = _this select 0; _uid = getPlayerUID _unit; _name = name _unit; _query = format ["SELECT id,uid FROM player WHERE uid = '%1'", _uid]; while{!isNil("serverRunningQuery") && serverRunningQuery} do { sleep 0.5;//busy wait }; serverRunningQuery = true; _get = nil; while {isNil("_get")} do { _get = "Arma2Net.Unmanaged" callExtension format ["Arma2NETMySQLCommandAsync ['MyDataBaseName', '%1']", _query]; if (_get == "") then { _get = nil; }; sleep 0.5; }; if ((count (toArray(_get))) < 6) then { //if user doesnt exist in database _query = "INSERT into player (uid, name, xp, kills, deaths, ammo, weapons, items, assignitems, headgear, goggles, vest, vestitems, uniform, uniformitems, backpack, packitems, handgunitems, primarywep, secondarywep) VALUES("; _query = _query + "'" + (_uid) + "'," + "'" + (_name) + "'" + ",0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)"; _return = nil; while {isNil("_return")} do { _return = "Arma2Net.Unmanaged" callExtension format ["Arma2NETMySQLCommandAsync ['MyDataBaseName', '%1']", _query]; if (_return == "") then { _return = nil; }; sleep 0.5; }; }; //get saved stats from server _query = format ["SELECT xp,kills,deaths FROM player WHERE uid = '%1'", _uid]; _get = nil; while {isNil("_get")} do { _get = "Arma2Net.Unmanaged" callExtension format ["Arma2NETMySQLCommandAsync ['MyDataBaseName', '%1']", _query]; if (_get == "") then { _get = nil; }; sleep 0.5; }; serverRunningQuery = false; //This converts the string to an array _get = call compile _get; //only select the inner array, throw away this outer array shell _get = _get select 0; _get = _get select 0; _string = _get select 0; _xp = parseNumber _string; _string = _get select 1; _kills = parseNumber _string; _string = _get select 2; _deaths = parseNumber _string; player_stats_add = [_xp,_kills,_deaths]; owner _unit publicVariableClient "player_stats_add"; player_stats_got = 1; owner _unit publicVariableClient "player_stats_got"; }; Any help would be great. Just spent 6hrs trying to add this with no luck. Please don't let me try sleep on a loss LOL Share this post Link to post Share on other sites
killzone_kid 1330 Posted May 3, 2017 https://community.bistudio.com/wiki/switch_do Share this post Link to post Share on other sites
ROTAHOE 3 Posted May 3, 2017 Also this is how its updating my RscTitles using call command getRankInfo. Now after looking at this I am unsure if I should be using _rank = player stats select 0 call getRankInfo; witch I tried _rankinfo = player_stats select 0 call getRankInfo; uiNamespace setVariable ['playerrank', _rankinfo select 0]; uiNamespace setVariable ['playernextrank', _rankinfo select 1]; uiNamespace setVariable ['playerkills', player_stats select 1]; uiNamespace setVariable ['playerdeaths', player_stats select 2]; //update controls. ONLY uinamespace from this point with uiNamespace do { //_output = format ["Server restart: %1 min", _tL]; //statsstime ctrlSetText _output; //statsstime ctrlCommit 0.1; _output = format ["Rank: %1 XP: %2/%3", playerrank, playerxp, playernextrank]; Share this post Link to post Share on other sites
ROTAHOE 3 Posted May 3, 2017 12 minutes ago, killzone_kid said: https://community.bistudio.com/wiki/switch_do I've used this before but how to add to my code using this ? I'm thinking but unsure what you are getting at ? Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted May 3, 2017 You could go for a more readable approach, into init.sqf: getNextRankAndXP = { params ["_xp",["_debug",true]]; _levels = [[0,1000],[1000,2000],[2000,3000],[3000,4000],[4000,5000],[5000,6000],[6000,7000],[8000,9000],[9000,10000]]; _getrank = (_levels apply {_xp > _x select 0 AND _xp <= _x select 1}); _rank = (_getrank find true) + 1; _nextRankXP = if (_rank < count _levels) then {_levels select ((_getrank find true) + 1) select 0} else {0}; if (_debug) then {systemchat format ["Input: %1 = %2",_xp,[_rank,_nextRankXP]]}; [_rank,_nextRankXP] }; To call simply: _output = [random 10000] call getNextRankAndXP; With 0.0274 ms it's running a bit slower than your if then else abomination (0.0178ms) but more readable and easier to expand. Returns 0 as next rankXP when max rank has been reached, otherwise it returns the xp value needed for the next rank. Some outputs: Input: 9414.63 = [9,0] Input: 5918.12 = [6,6000] Input: 8890.21 = [8,9000] Input: 4067.06 = [5,5000] Cheers 1 Share this post Link to post Share on other sites
ROTAHOE 3 Posted May 3, 2017 1 hour ago, Grumpy Old Man said: You could go for a more readable approach, into init.sqf: getNextRankAndXP = { params ["_xp",["_debug",true]]; _levels = [[0,1000],[1000,2000],[2000,3000],[3000,4000],[4000,5000],[5000,6000],[6000,7000],[8000,9000],[9000,10000]]; _getrank = (_levels apply {_xp > _x select 0 AND _xp <= _x select 1}); _rank = (_getrank find true) + 1; _nextRankXP = if (_rank < count _levels) then {_levels select ((_getrank find true) + 1) select 0} else {0}; if (_debug) then {systemchat format ["Input: %1 = %2",_xp,[_rank,_nextRankXP]]}; [_rank,_nextRankXP] }; To call simply: _output = [random 10000] call getNextRankAndXP; With 0.0274 ms it's running a bit slower than your if then else abomination (0.0178ms) but more readable and easier to expand. Returns 0 as next rankXP when max rank has been reached, otherwise it returns the xp value needed for the next rank. Some outputs: Input: 9414.63 = [9,0] Input: 5918.12 = [6,6000] Input: 8890.21 = [8,9000] Input: 4067.06 = [5,5000] Cheers Sorry mate new to this and you lost me ? Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted May 3, 2017 What exactly is unclear? Cheers Share this post Link to post Share on other sites
ROTAHOE 3 Posted May 3, 2017 _output = [random 10000] call getNextRankAndXP; Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted May 3, 2017 2 minutes ago, ROTAHOE said: _output = [random 10000] call getNextRankAndXP; How exactly can I help you? You just posted how to call the function, random 10000 is just a placeholder and to be replaced with your _xp value. This outputs the next rank and the xp needed for the next rank, exactly like the function you posted earlier. Cheers Share this post Link to post Share on other sites
ROTAHOE 3 Posted May 3, 2017 I got done what was needed with player spawn { _pilot = _this; private _price = 25000; if([_price] call HG_fnc_hasEnoughMoney) then { _info = player_stats select 0 call getRankInfo; _rank = _info select 0; if (_rank >= 50) then { [25000,1] call HG_fnc_addOrSubCash; _jet = createVehicle ["B_Plane_CAS_01_F", [4113.665,800.764,1200], [], 0, "FLY"]; _jet setDir 0; _jet setVelocityModelSpace [0,150,0]; _pilot moveInDriver _jet; removeUniform _pilot; removeBackpackGlobal _pilot; removeHeadgear _pilot; _pilot forceAddUniform "U_O_PilotCoveralls"; _pilot addBackpackGlobal "B_parachute"; _pilot addHeadgear "H_PilotHelmetFighter_O"; _jet addAction ["Re-Arm Jet", "scripts\Rearm_Jet.sqf"]; hint format ["%1 \nYou have brought A10 Good Luck!",name _pilot]; } else { hint format ["%1 \nYou don't have enough money!",name _pilot] }; }; }; But interested on your input Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted May 3, 2017 My function was just a suggestion, if you already got it working all is well. Cheers 1 Share this post Link to post Share on other sites
ROTAHOE 3 Posted May 3, 2017 Sorry those functions work fine, it was just this script ^ adding a needed rank i.e 50 1 Share this post Link to post Share on other sites
ROTAHOE 3 Posted May 3, 2017 Thank you for posting mate :cheers: Share this post Link to post Share on other sites