BEAKSBY 11 Posted October 3, 2014 Hi Folks, I'm trying to create an addAction with a title that includes a countdown timer showing how much time is left before the addAction will be ready to execute. I have tried the following: myAction = player addAction ["dynamic",{ _return = [] call BEAKS_fnc_mines; },[],0,true,true, "", "_return = [] call BEAKS_fnc_mines; _specialTimeLeft = 0; if (_return == 1) then { _timeNow = time; _specialTimeLeft = 120 - (time - _timeNow); // seconds left in 2 minute countdown }; _display = _specialTimeLeft + ' Plant Mines '; player setUserActionText [myAction, _display ]; (_specialTimeLeft < 0)" ]; _return = [] call BEAKS_fnc_mines; will return "1" if the function mines is executed (and the mines are created) and will return "0" if it is aborted. I would like the addAction to be available to execute once _specialTimeLeft has run out. But the addAction will only appear if the condition is true or not. How do I get it to show but not be executable until the condition is met? Share this post Link to post Share on other sites
iceman77 18 Posted October 3, 2014 (edited) . . . I'm trying to create an addAction with a title that includes a countdown timer showing how much time is left before the addAction will be ready to execute. . . . But the addAction will only appear if the condition is true or not. How do I get it to show but not be executable until the condition is met? Example timer: script.sqf timerDone = true; player addAction ["Timer", {[1, 10] call ICE_fnc_timer;},[],0,true,true, "","timerDone"];// Waits until timerDone variable is true before action is available. ICE_fnc_timer timerDone = false; private ["_minutes", "_seconds"]; _minutes = [_this, 0, 0, [0]] call BIS_fnc_param; _seconds = [_this, 1, 0, [0]] call BIS_fnc_param; // _xHandlex = [_arguments] call some_fnc; // Fnc called on timer start while {!timerDone} do { _seconds = _seconds - 1; if (_seconds == 0 && {_minutes > 0}) then { hintSilent format ["%1:0%2", _minutes, _seconds]; _minutes = _minutes - 1; _seconds = 00; sleep 1; _seconds = 59; }; if (_seconds >= 10) then { hintSilent format ["%1:%2", _minutes, _seconds]; } else { hintSilent format ["%1:0%2", _minutes, _seconds]; }; if (_minutes == 0 && {_seconds < 1}) exitWith { timerDone = true; hintSilent "The timer is done and the action is available again."; //_xHandlex = [_arguments] call someOther_fnc; //Fnc called at timer end }; sleep 1; }; Edited October 3, 2014 by Iceman77 Share this post Link to post Share on other sites
Lala14 135 Posted October 3, 2014 use setUserActionText. And then maybe in the conditions have something being called to change it dynamically. Probably would need to use spawn because calling doesn't allow sleeps ;) Dammit I did it again where I forget to read. ---------- Post added at 16:17 ---------- Previous post was at 16:14 ---------- also just another little foot note is that in the addAction _this select 2 will return the index number of the addAction. ;) Share this post Link to post Share on other sites
iceman77 18 Posted October 3, 2014 (edited) Probably would need to use spawn because calling doesn't allow sleeps ;) That's not always the case. Wiki: A called function may only use suspension (sleep, uiSleep, waitUntil) if it originates in a scheduled environment. If the called function originates in a non-scheduled environment it will return a generic error. ---------- Post added at 22:32 ---------- Previous post was at 22:20 ---------- This thread is a great read regarding call + sleep in (non) scheduled environments. Edited October 3, 2014 by Iceman77 Share this post Link to post Share on other sites
BEAKSBY 11 Posted October 3, 2014 Thanks again Iceman77, I also wanted to see if I can display the time left before the addAction would become availabe in the addAction itself, possibly using setUserActionText? Otherwise I'll create a dialog for it, for each player. Share this post Link to post Share on other sites
killzone_kid 1330 Posted October 3, 2014 Maybe... [url="http://killzonekid.com/sqf-to-bbcode-converter/"][color="#FF8040"][color="#000000"]player[/color] [color="#191970"][b]setVariable[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"time"[/color][color="#8B3E2F"][b],[/b][/color] [color="#191970"][b]floor[/b][/color] [color="#000000"]time[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#FF0000"]30[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#000000"]player[/color] [color="#191970"][b]setVariable[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"id"[/color][color="#8B3E2F"][b],[/b][/color] [color="#000000"]player[/color] [color="#191970"][b]addAction[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]""[/color][color="#8B3E2F"][b],[/b][/color] [color="#8B3E2F"][b]{[/b][/color] [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#000000"]player[/color] [color="#191970"][b]getVariable[/b][/color] [color="#7A7A7A"]"time"[/color] [color="#8B3E2F"][b]>[/b][/color] [color="#191970"][b]floor[/b][/color] [color="#000000"]time[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#000000"]player[/color] [color="#191970"][b]removeAction[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#000000"]_this[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]2[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]hint[/b][/color] [color="#7A7A7A"]"PLANTING"[/color][color="#8B3E2F"][b];[/b][/color] [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color] [color="#7A7A7A"]""[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b],[/b][/color] [color="#000000"]false[/color][color="#8B3E2F"][b],[/b][/color] [color="#000000"]true[/color][color="#8B3E2F"][b],[/b][/color] [color="#7A7A7A"]""[/color][color="#8B3E2F"][b],[/b][/color] [color="#7A7A7A"]" if (player getVariable 'time' > floor time) then { player setUserActionText [player getVariable 'id', format [ "[/color][color="#7A7A7A"]"<t color='#00FFFFFF'>Plant Mines in %1</t>"[/color][color="#7A7A7A"]", (player getVariable 'time') - floor time ]]; } else { player setUserActionText [player getVariable 'id', 'Plant Mines']; }; true "[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color][/color][/url] Share this post Link to post Share on other sites
BEAKSBY 11 Posted October 4, 2014 (edited) Thanks KK, What are you planning on doing with your MANW prize money? :) On a similar note... I've add the code you provided above to onPlayerRespawn.sqf // for sniper if (_respawnedPlayer hasWeapon "srifle_EBR_DMS_pointer_snds_F") then { player setVariable ["time", floor time]; player setVariable ["Ready", 1]; while {(_respawnedPlayer hasWeapon "srifle_EBR_DMS_pointer_snds_F")} do { waitUntil {sleep 0.5; (player getVariable "Ready" == 1)}; player setVariable ["id", player addAction ["", { if (player getVariable "time" > floor time) exitWith {}; player removeAction (_this select 2); //hint "PLANTING"; [] call BEAKS_fnc_mines; }, "", 1, false, true, "", " if (player getVariable 'time' > floor time) then { player setUserActionText [player getVariable 'id', format [ ""<t color='#00FFFFFF'>Plant Mines in %1</t>"", (player getVariable 'time') - floor time ]]; } else { player setUserActionText [player getVariable 'id', 'Plant Mines']; }; player setVariable ['Ready', 0]; true "]]; }; }; ...and inside BEAKS_fnc_mines I added player setVariable ["Ready", 0]; at the top of the script, followed by player setVariable ["Ready", 1]; player setVariable ["time", floor time + specialReadyTime]; ...once the function is complete. BUT, the addAction that calls the mines function remains when the player dies and respawns as another type of soldier. Inside onPlayerKilled.sqf I've added: _KilledPlayer = _this select 0; _KilledPlayer setVariable ["id", nil]; removeAllActions _KilledPlayer; ...but the addAction remains for the next player I respawn as ?... // for SAW if (_respawnedPlayer hasWeapon "Laserdesignator") then { player setVariable ["time", floor time]; player setVariable ["Ready", 1]; while {(_respawnedPlayer hasWeapon "Laserdesignator")} do { waitUntil {sleep 0.5; (player getVariable "Ready" == 1)}; player setVariable ["id", player addAction ["", { if (player getVariable "time" > floor time) exitWith {}; player removeAction (_this select 2); //hint "PLANTING"; [] call BEAKS_fnc_UAV; }, "", 1, false, true, "", " if (player getVariable 'time' > floor time) then { player setUserActionText [player getVariable 'id', format [ ""<t color='#00FFFFFF'>UAV CAS in %1</t>"", (player getVariable 'time') - floor time ]]; } else { player setUserActionText [player getVariable 'id', 'UAV CAS']; }; player setVariable ['Ready', 0]; true "]]; }; }; How can I get rid of the previous addAction so it does not appear for then next player I respawn as? Edited October 4, 2014 by BEAKSBY Share this post Link to post Share on other sites
BEAKSBY 11 Posted October 4, 2014 Example timer:ICE_fnc_timer timerDone = false; private ["_minutes", "_seconds"]; _minutes = [_this, 0, 0, [0]] call BIS_fnc_param; _seconds = [_this, 1, 0, [0]] call BIS_fnc_param; // _xHandlex = [_arguments] call some_fnc; // Fnc called on timer start while {!timerDone} do { _seconds = _seconds - 1; if (_seconds == 0 && {_minutes > 0}) then { hintSilent format ["%1:0%2", _minutes, _seconds]; _minutes = _minutes - 1; _seconds = 00; sleep 1; _seconds = 59; }; if (_seconds >= 10) then { hintSilent format ["%1:%2", _minutes, _seconds]; } else { hintSilent format ["%1:0%2", _minutes, _seconds]; }; if (_minutes == 0 && {_seconds < 1}) exitWith { timerDone = true; hintSilent "The timer is done and the action is available again."; //_xHandlex = [_arguments] call someOther_fnc; //Fnc called at timer end }; sleep 1; }; Thanks Iceman77, I've modified you script a bit with the following: while {!timerDone} do { _seconds = _seconds - 1; _timer = ""; if ((_seconds - specialReadyTime) > 0) then { if ((_seconds mod 60)<10) then {_timer = format ["%1:0%2", floor (_seconds/60), _seconds mod 60]; } else { _timer = format ["%1:%2", floor (_seconds/60), _seconds mod 60]; }; hintSilent format ["UAV Time remaining: %1", _timer]; //...more code... also I found if _seconds = [_this, 1, 0, [0]] call BIS_fnc_param; is 0 then _seconds = _seconds - 1; generates a negative number and there is no if condition to satisfy this. Therefore the hint will show negative numbers. Share this post Link to post Share on other sites
iceman77 18 Posted October 4, 2014 (edited) Sure you're free to modify it any way you like. Anyhow always here to lend a hand to new comers. Don't be shy to post more help threads. ---------- Post added at 15:30 ---------- Previous post was at 15:26 ---------- On another note, you should be able to restrict certain values to be passed to the script with bis fnc param, and then set a default value if the value you tried to pass didn't suffice?? Edited October 4, 2014 by Iceman77 Share this post Link to post Share on other sites
BEAKSBY 11 Posted October 5, 2014 How can I get rid of the previous addAction I thought removeAllActions from post #7 would clear all addActions?...but still no luck. Share this post Link to post Share on other sites