Angus S 10 Posted December 10, 2011 Is it possible to change a units rank on a trigger activation? Share this post Link to post Share on other sites
demonized 20 Posted December 10, 2011 unitName [url="http://community.bistudio.com/wiki/setRank"]setRank[/url] "COLONEL"; Share this post Link to post Share on other sites
Angus S 10 Posted December 10, 2011 Cool thanks for your help Share this post Link to post Share on other sites
Linrox 10 Posted December 23, 2011 Angus S said: Is it possible to change a units rank on a trigger activation? Hey Did you get the setRank command to work on units?? and was this for a SP or MP game?? I am also trying to use the setRank on units but cannot get it to work. Any pointers!! thanks Linrox Share this post Link to post Share on other sites
demonized 20 Posted December 23, 2011 Linrox said: I am also trying to use the setRank on units but cannot get it to work. Any pointers!! Well, we cant guess what you do wrong, so first post what you did that didnt work, then it would be alot easier to give pointers ;) Share this post Link to post Share on other sites
sxp2high 23 Posted December 23, 2011 I guess setRank effect is local. So, one way to change rank in multiplayer would be using a publicVariableEventHandler. Init.sqf "changeRank" addPublicVariableEventHandler { _data = _this select 1; (_data select 0) setRank (_data select 1); }; To change the rank (via Trigger or whatever) you can use: changeRank = [_Unit, _Rank]; publicVariable "changeRank"; For example: changeRank = [TheDude, "CAPTAIN"]; publicVariable "changeRank"; Share this post Link to post Share on other sites
mikie boy 18 Posted December 23, 2011 as simple as this - requestedplayer= player; desiredrank = "PRIVATE"; player setUnitRank desiredrank ; publicVariable "requestedplayer"; publicVariable "desiredrank "; Share this post Link to post Share on other sites
Linrox 10 Posted December 24, 2011 (edited) Well i though i would give you all an update. I finally got it to work :D but it is rather messy. Also this is not for MP, just SP. Can any body tell me why it would not work like this even though the variables hold the right info.:confused: //RankXmenu.sqf Rank_menu = [ ["Rank",false], ["Promote",[2],"#USER:Rank_menu",-5,[["expression","nul= [groupSelectedUnits player,('CAPTAIN')] execVM 'RankX\promote.sqf'"]],"1","1"] ]; BIS_MENU_GroupCommunication = [ [localize "STR_SOM_COMMUNICATIONS", false],["Rank",[2],"#USER:CUSTOM_menu",-5,[["expression",""]],"1","1"] ]; if (true) exitWith {}; //promote.sqf _newRank = _this select 1; _unit = _this selet 0; _unit setRank (format ["%1",_newRank]); instead i have to use this //RankXmenu.sqf sleep 1; [] call BIS_fnc_commsMenuCreate; CUSTOM_menu = [ ["Rank",false], ["Promote",[2],"#USER:Rank_menu",-5,[["expression","player sidechat ""this is Rank (submenu)"]],"1","1"] ]; Rank_menu = [ ["Rank",false], ["Corporal",[2],"",-5,[["expression", "nul= groupSelectedUnits player execVM 'RankX\corporal.sqf'"]],"1","1"], ["Sergeant",[3],"",-5,[["expression", "nul= groupSelectedUnits player execVM 'RankX\sergeant.sqf'"]],"1","1"], ["Lieutenant",[4],"",-5,[["expression", "nul= groupSelectedUnits player execVM 'RankX\lieutenant.sqf'"]],"1","1"], ["Captain",[5],"",-5,[["expression", "nul= groupSelectedUnits player execVM 'RankX\captain.sqf'"]],"1","1"], ["Major",[6],"",-5,[["expression","nul= groupSelectedUnits player execVM 'RankX\major.sqf'"]],"1","1"] ]; BIS_MENU_GroupCommunication = [ [localize "STR_SOM_COMMUNICATIONS", false],["Rank",[2],"#USER:CUSTOM_menu",-5,[["expression",""]],"1","1"] ]; if (true) exitWith {}; //Corporal.sqf sleep 0.5; _selected= _this select 0; _newRank = "CORPORAL"; _selected setRank (format ["%1",_newRank]); The Variable _newRank in both cases still holds the same value, but it only works when the variable is set in the same script. I will be trying to clean it up. at the moment i need to use 1 file for each rank, which i don't like. so i will keep reading forums and other scripts to help learn. Linrox Edited December 24, 2011 by Linrox Share this post Link to post Share on other sites
f2k sel 164 Posted December 24, 2011 Error in _unit = _this select 0 and it's an array. so you need to decide which unit/units are getting promoted. (_unit this select 0) setRank ect. or { _x setrank (format ["%1",_newRank]);} foreach _unit; I've not tested it so don't shoot me if I'm wrong. Share this post Link to post Share on other sites
Linrox 10 Posted December 25, 2011 Yes i realized the typo error in that line after i had posted. The typo does not exists in the actual script. The unit/units being promoted are chosen by the nul = changeSelectedUnits player part in the menu script. but i know i needed to add the foreach _unit; part as well I have tested the value of both _unit and _newRank in both scripts and in both cases the _unit does hold the ID of the selected unit, and the _newRank does hold the rank to promote too. so that's why i don't get it. The only difference (that i can see) is the the first script receives the rank from the menu choice, and the second script gets the rank from the _newrank = "CAPTAIN"; in the promote.sqf script. and yet if i use the hint format to print the content of the variables they are correct. Share this post Link to post Share on other sites
f2k sel 164 Posted December 25, 2011 I'm not that used to the custom menu scripting, I couldn't get your first RankXmenu.sqf to even allow the promote option to show. Share this post Link to post Share on other sites
Linrox 10 Posted December 26, 2011 sorry that wasn't the full script. Here is the init.sqf file and the menu.sqf files of both versions. I have added for testing a few hint and hint format lines to make sure the script is reaching those points. This is my current working version. but it is messy because i need a seperate file for each rank(i.e. corporoal.sqf,captain.sqf...). You will also need to place a GL in the map editor with this nul=[this] execVM "RankX\RankX_init.sqf"; in the initialization. //RankX_init.sqf waituntil {!isnil "bis_fnc_init"}; _HCLeader=_this select 0; _UnitID=_this select 1; _HCLeader hcSetGroup [group _HCLeader]; hint "init started"; sleep 1; [] execVM "RankX\RankX_Menu.sqf"; //RankX_menu.swf sleep 1; [] call BIS_fnc_commsMenuCreate; //This hint shows the SQF was started hint "Menu Start"; CUSTOM_menu = [ ["Rank",false], ["Promote",[2],"#USER:Rank_menu",-5,[["expression","player sidechat ""this is Rank (submenu)"]],"1","1"], ["Item 2",[3],"",-5,[["expression","hint 'Hello2!'"]],"1","1"] ]; Rank_menu = [ ["Rank",false], ["Corporal",[2],"",-5,[["expression", "nul= groupSelectedUnits player execVM 'RankX\corporal.sqf'"]],"1","1"], ["Sergeant",[3],"",-5,[["expression", "nul= groupSelectedUnits player execVM 'RankX\sergeant.sqf'"]],"1","1"] ]; BIS_MENU_GroupCommunication = [ [localize "STR_SOM_COMMUNICATIONS", false],["Rank",[2],"#USER:CUSTOM_menu",-5,[["expression",""]],"1","1"] ]; //if this hint is printed then script completed hint "Menu Complete"; if (true) exitWith {}; //corporoal.sqf //This hint shows the SQF was started hint "Promote started"; sleep 0.5; _unit= _this select 0; _newRank = "CORPORAL"; _unit setRank (format ["%1",_newRank]); //if this hint is printed then script completed hint "Promote end"; sleep 0.5; and here is the other version that i could not get to work. you will notice the hint format prints the same results as the version that i am currently using. The init.sqf is the same for both versions //RankX_menu.swf sleep 1; [] call BIS_fnc_commsMenuCreate; //This hint shows the SQF was started hint "Menu Start"; CUSTOM_menu = [ ["Rank",false], ["Promote",[2],"#USER:Rank_menu",-5,[["expression","player sidechat ""this is Rank (submenu)"]],"1","1"], //["Item 2",[3],"",-5,[["expression","hint 'Hello2!'"]],"1","1"] ]; Rank_menu = [ ["Rank",false], ["Corporal",[2],"",-5,[["expression", "nul= [groupSelectedUnits player,('CORPORAL')] execVM 'RankX\corporal.sqf'"]],"1","1"], ["Sergeant",[3],"",-5,[["expression", "nul= [groupSelectedUnits player,('SERGEANT')] execVM 'RankX\sergeant.sqf'"]],"1","1"] ]; BIS_MENU_GroupCommunication = [ [localize "STR_SOM_COMMUNICATIONS", false],["Rank",[2],"#USER:CUSTOM_menu",-5,[["expression",""]],"1","1"] ]; //if this hint is printed then script completed hint "Menu Complete"; if (true) exitWith {}; If I can get this part of the script to work correctly then i would only need 1 file for the actual promotion, not 1 per rank. //corporoal.sqf //This hint shows the SQF was started hint "Promote started"; sleep 0.5; _unit= _this select 0; _newRank = _this select 1; //just prints results hint format ["%1",_newRank]; sleep 1; hint format ["%1",_unit]; sleep 1; _unit setRank (format ["%1",_newRank]); //if this hint is printed then script completed hint "Promote end"; sleep 0.5; Share this post Link to post Share on other sites
f2k sel 164 Posted December 26, 2011 (edited) I have to ask as I'm getting several errors are you using _showscript http://forums.bistudio.com/showthread.php?t=121163 Anyway I still don't really see the problem, this is where I got earlier and as far as I can tell it works. I did change a file name and pass the player in case it's needed later. As a final test I created a trigger and had a unit named bill set to private and when promoted the trigger will execute and the unit dies. Cond rank bill != "private" onact bill setdamage 1; Bill only dies when his rank is changed. //RankXmenu.sqf waituntil {!isnil "bis_fnc_init"}; [] call BIS_fnc_commsMenuCreate ; CUSTOM_menu = [ ["Rank",false], ["Promote",[2],"#USER:Rank_menu",-5,[["expression","player sidechat ""this is Rank (submenu)"]],"1","1"] ]; Rank_menu = [ ["Promote",false], ["Private",[2],"",-5,[["expression","nul=[player,(groupSelectedUnits player),'PRIVATE'] execVM 'RankX\Change.sqf'"]],"1","1"], ["Corporal",[3],"",-5,[["expression","nul=[player,(groupSelectedUnits player),'CORPORAL'] execVM 'RankX\Change.sqf'"]],"1","1"], ["Sergeant",[4],"",-5,[["expression","nul=[player,(groupSelectedUnits player),'SERGEANT'] execVM 'RankX\Change.sqf'"]],"1","1"], ["Lieutenant",[5],"",-5,[["expression","nul=[player,(groupSelectedUnits player),'LIEUTENANT'] execVM 'RankX\Change.sqf'"]],"1","1"], ["Captain",[6],"",-5,[["expression","nul=[player,(groupSelectedUnits player),'CAPTAIN'] execVM 'RankX\Change.sqf'"]],"1","1"], ["Major",[7],"",-5,[["expression","nul=[player,(groupSelectedUnits player),'MAJOR'] execVM 'RankX\Change.sqf'"]],"1","1"], ["Colonel",[8],"",-5,[["expression","nul=[player,(groupSelectedUnits player),'COLONEL'] execVM 'RankX\Change.sqf'"]],"1","1"] ]; BIS_MENU_GroupCommunication = [ [localize "STR_SOM_COMMUNICATIONS", false],["Rank",[2],"#USER:CUSTOM_menu",-5,[["expression",""]],"1","1"] ]; if (true) exitWith {}; //change.sqf _unit_player =_this select 0; _unit = _this select 1; _newRank = _this select 2; { hint format ["Current Rank %1",rank _x]; Sleep 1; _x setRank _newRank; // _x setRank (format ["%1",_newRank]); Sleep 1; hint format ["New Rank is %1",rank _x]; } foreach _unit; Edited December 26, 2011 by F2k Sel Share this post Link to post Share on other sites
Linrox 10 Posted December 26, 2011 (edited) no, did not even know about the _showscript command I think i might know why you are getting errors, i am using ARMA 2 OA, but i also have Reinforcements installed which includes BAF & PMC. http://www.arma2.com/rft also remember this is for SP not MP, if that makes any difference. Edited December 26, 2011 by Linrox Share this post Link to post Share on other sites
Angus S 10 Posted December 26, 2011 Yeah i tried just using the setrank command (for SP) and it worked perfctly Share this post Link to post Share on other sites
f2k sel 164 Posted December 26, 2011 Linrox said: no, did not even know about the _showscript commandI think i might know why you are getting errors, i am using ARMA 2 OA, but i also have Reinforcements installed which includes BAF & PMC. http://www.arma2.com/rft also remember this is for SP not MP, if that makes any difference. I have the same content, the error was just a comma that should have been removed when you split the promote line. Share this post Link to post Share on other sites
Linrox 10 Posted December 26, 2011 (edited) Thanks all for your help, especially F2k sel I will give it a try. UPDATE Works well:bigsmile:, thank you.:icon_eek: Edited December 26, 2011 by Linrox Share this post Link to post Share on other sites
Linrox 10 Posted December 31, 2011 (edited) Str Sel: I am trying to add an if statement in the {} brackets in the change.sqf file. but the script will not run. the line i am trying to add is { if (rankId _x > rankId _unit_player) exitWith {}; I have also tried adding the line before the { but it stops at the line. Any help? I have also tried this _unit_player =_this select 0; _unit = _this select 1; _newRank = _this select 2; if (rankId _unit < rankId _unit_player) { hint format ["Current Rank %1",rank _x]; Sleep 1; _x setRank _newRank; // _x setRank (format ["%1",_newRank]); Sleep 1; hint format ["New Rank is %1",rank _x]; } foreach _unit; }; but still no joy Edited December 31, 2011 by Linrox Share this post Link to post Share on other sites
f2k sel 164 Posted December 31, 2011 Something like this should work. //change.sqf _unit_player =_this select 0; _unit = _this select 1; _newRank = _this select 2; { if (rankId _x == rankid _unit_player) exitwith {hint "Your already equal in rank"}; if (rankId _x >= rankid _unit_player) exitwith {hint "You cannot promote beyond your rank"}; sleep 1; hint format ["Current Rank %1",rank _x]; Sleep 1; _x setRank _newRank; // _x setRank (format ["%1",_newRank]); Sleep 1; hint format ["New Rank is %1",rank _x]; } foreach _unit; Share this post Link to post Share on other sites
Linrox 10 Posted December 31, 2011 (edited) i tried something similar, but it errors received an array, but wanted an object. I did end up fixing it. Thanks to you tip -showscripterror but ultimately, i wanted to use 'if ' conditions in the menu script so i could enable or disable options based on the players rank. Plus i found that with the current menu, if i select higher that 7 it errors, missing ] so i need a line to prevent that. here is what the promote.sqf currently looks like //change.sqf _o=1; _unit_player =_this select 0; _unit = _this select 1; _newRank = _this select 2; _rankI = _this select 3; _p=rankId _unit_player; { if (_p > _rankI-1) then { hint format ["Current Rank %1",rank _x]; Sleep 1; _x setRank _newRank; hint format ["New Rank is %1",rank _x]; sleep 3; };// else {exitWith {hint format ["can't promote %1 to %2",_unit,_newRank]}; }foreach _unit; if (count _unit <1) exitWith {titleText ["No unit is selected", "PLAIN DOWN"]}; also i don't understand why, if i add a line rankID=rankI-1 it returns as scalar. thanks for the reply, and for your help Edited December 31, 2011 by Linrox Share this post Link to post Share on other sites
f2k sel 164 Posted December 31, 2011 (edited) Try this and see if were a little closer. You only see the ranks available and if no units selected they are greyed out. The only option I couldn't do in the menu was if a unit of higher rank joins your group, that has to be checked in for in change.sqf. // if using team switch you will need to set up onteamswitch. // onteamswitch "null=[]execvm 'RankXmenu.sqf'" // // If you make any changes to the players rank you will need to rerun the script. // That will allow updates to the new rank to take effect. // // use the following to run the ranking system. // null=[] execvm "RankXmenu.sqf" // sleep 1; [] call BIS_fnc_commsMenuCreate; CUSTOM_menu = [ ["Rank",false], ["Promote",[2],"#USER:Rank_menu",-5,[["expression",""]],"1","1"] ]; _rank_pl = rankID player; _rank=[]; //Remove Promotions above the players rank. for "_i" from 0 to 6 do { if (_rank_pl >= _i) then {_rank = _rank+["1"]} else {_rank = _rank+["0"]} ; }; // "NotEmpty" = greyed out if no unit selected. Rank_menu = [ ["Promote",false], ["1 Private",[],"",-5,[["expression","nul=[player,(groupSelectedUnits player),'PRIVATE',0] execVM 'Rankx\Change.sqf'"]],_rank select 0,"NotEmpty"], ["2 Corporal",[],"",-5,[["expression","nul=[player,(groupSelectedUnits player),'CORPORAL',1] execVM 'Rankx\Change.sqf'"]],_rank select 1,"NotEmpty"], ["3 Sergeant",[],"",-5,[["expression","nul=[player,(groupSelectedUnits player),'SERGEANT',2] execVM 'Rankx\Change.sqf'"]],_rank select 2,"NotEmpty"], ["4 Lieutenant",[],"",-5,[["expression","nul=[player,(groupSelectedUnits player),'LIEUTENANT',3] execVM 'Rankx\Change.sqf'"]],_rank select 3,"NotEmpty"], ["5 Captain",[],"",-5,[["expression","nul=[player,(groupSelectedUnits player),'CAPTAIN',4] execVM 'Rankx\Change.sqf'"]],_rank select 4,"NotEmpty"], ["6 Major",[],"",-5,[["expression","nul=[player,(groupSelectedUnits player),'MAJOR',5] execVM 'Rankx\Change.sqf'"]],_rank select 5,"NotEmpty"], ["7 Colonel",[],"",-5,[["expression","nul=[player,(groupSelectedUnits player),'COLONEL',6] execVM 'Rankx\Change.sqf'"]],_rank select 6,"NotEmpty"] ]; BIS_MENU_GroupCommunication = [ [localize "STR_SOM_COMMUNICATIONS", false],["Rank",[2],"#USER:Rank_menu",-5,[["expression",""]],"1","1"] ]; if (true) exitWith {hint "I'm out of here"};// remove hint (testing only). //change.sqf _unit_player =_this select 0; _unit = _this select 1; _newRank = _this select 2; _rank_pl = _this select 3;// may not be needed { _pass = true; if (rankID _x > rankid _unit_player) then {hint format ["Can't demote a superior officer %1 to %2",_x,_newRank];_pass= false}; If (_pass) then { sleep 1; hint format ["Current Rank %1",rank _x]; Sleep 1; _x setRank _newRank; Sleep 1; hint format ["New Rank %1",rank _x]; }; } foreach _unit; Edited December 31, 2011 by F2k Sel Share this post Link to post Share on other sites