stilton 0 Posted May 12, 2015 second topic in a short while.. i'm on a roll :D Ok so skiptime is wonderfully simple, and it works for skipping ahead 3 hours... which is what i want. I searched and used some other geniuses 'fastTime' script too, to slightly speed up the gameTime, but slows it down during dusk/dawn to keep the effect subtle... this mainly uses the 'date' command... Which is great because it gives the mission the flexability to be run from any start date... Also, what i want. So. I have a game-time running slightly faster than real-time, with a script that allows you to skip 3 hours ahead. Believe it or not, this all works fine so far. So you know the purpose, i'm paying my 'mercenaries' by the hour/day (not decided yet. ) ...The problem comes when trying to keep a 'mission elapsed time counter' If i don't use the 'date' command, it doesn't seem to take in account skipTime... So i was going to use, the current in-play 'date' and compare it to the start 'date' variables... ...I wrote a script to do this, but it's going horribly wrong somewhere... and showing my complete lack of arithmetic skills (the scripting was fine, the math/logic was the failing :D ) because at a point it read: Elapsed time: 1day, -9 hours. :D Share this post Link to post Share on other sites
killzone_kid 1331 Posted May 12, 2015 Did you know you could just use setTimeMultiplier and avoid all the headache? Share this post Link to post Share on other sites
Greenfist 1863 Posted May 12, 2015 (edited) I swear I've seen a BIS function that calculates time difference between two dates, but I can't see anything like that in the wiki's function section. Unless someone is willing to write you a time counter from scratch, maybe you should post your current script and we'll see if there's something we can help you with? Edited May 12, 2015 by Greenfist Share this post Link to post Share on other sites
st_dux 26 Posted May 12, 2015 I would suggest using dateToNumber to get the time difference as a simple scalar value (dateToNumber the current date minus dateToNumber the starting date); then, multiply that value by 365 to get days elapsed. You can figure out hours/minutes/whatever from there pretty easily. Share this post Link to post Share on other sites
stilton 0 Posted May 12, 2015 (edited) you could just use setTimeMultiplier and avoid all the headache? Doesn't seem to do much for me testing in the editor... which is where i prefer to test to get a quick turnaround on how many ;'s and ()'s i've left out... So i've been avoiding things that involve me having to compile the mission, upload it to dedi.. run multiple copies of arma, etc... ..i prefer things where i can just hit 'preview' and not have to faff about so much... So, i'd argue on whether i'd be 'avoiding all the headache' there mate or just 'replacing the headache with a whole new area of arse ache' :D I swear I've seen a BIS function... maybe you should post your current script Wow, searching the functions is something in my sleep deprived state i didnt really think of, i had furiously searched the commands/forums but... Good idea, ill double check :D In terms of my horrible code... I have several non-working examples lol.. but it's exactly what dux said... Something like: _startDate = date; while {true} do { _curDate = date; _minsPassed = (_curDate select 4) - (_startDate select 4); _hrsPassed = ((_curHour * 24 ) - (_startHour * 24 )) / 24; player groupChat format ["%1 Hours, %3 Mins ", _hrsPassed, _minsPassed ]; sleep 5; }; See i could go look it up further, i'm pretty sure i -could- bodge together some sort of working example... But when i do that sort of thing and it ends up being pages of code, just to get the 'elapsed time' of the mission, i know i'm doing something horribly wrong... Because surely it should be much simpler... Liiiike, using the dateToNumber command, which i couldn't work out.. Because: ... then multiply that value by 365 to get days elapsed. .... *humps* See, this is where i was going wrong, and this is why i come to here for help. I had tried this (honest) but i was getting some stupidly weird values... I had no idea that i had to multiply it by 365, that logic was completely beyond me lol. Thanks for letting me suckle at the teat of your scripting knowledge/logic sir. Edited May 12, 2015 by Stilton Share this post Link to post Share on other sites
killzone_kid 1331 Posted May 12, 2015 Doesn't seem to do much for me testing in the editor... which is where i prefer to test to get a quick turnaround on how many ;'s and ()'s i've left out... So i've been avoiding things that involve me having to compile the mission, upload it to dedi.. run multiple copies of arma, etc.....i prefer things where i can just hit 'preview' and not have to faff about so much... So, i'd argue on whether i'd be 'avoiding all the headache' there mate or just 'replacing the headache with a whole new area of arse ache' :D It should work in editor, any command that is meant for the server should work in editor. I have notified Iceman. Share this post Link to post Share on other sites
stilton 0 Posted May 12, 2015 (edited) It should work in editor, any command that is meant for the server should work in editor. I have notified Iceman. I've got arma open now... and i've tested it. It's me. So i took your suggestion and simplified the code down to: If ! (IsServer)exitwith{}; _sleepDelay = 2; _startDate = date; While{TRUE}do { // If the time is between 4am and 6pm, lets speed up the updates and reduce the time advance if ( (((Date select 3) > 4)&&((Date select 3) < 6)) or (((Date select 3) > 18)&&((Date select 3) < 20)) ) then { setTimeMultiplier 5; }else{ setTimeMultiplier 10; }; _curDate = date; _elapsedDays = ( (dateToNumber _curDate) - (dateToNumber _startDate) ) * 365; _elapsedHours = _elapsedDays * 24; //_elapsedMins = (_elapsedDays * 60); _elapsedMins = if ((_curDate select 4)>=(_startDate select 4)) then { ((_curDate select 4) - (_startDate select 4)); } else { ((60 - (_startDate select 4)) + (_curDate select 4)); }; _elapsed = format [ "%1, %2, %3", (floor _elapsedDays), (floor _elapsedHours), _elapsedMins ]; player groupChat _elapsed; sleep _sleepDelay; }; It all appears to work :) If anyone finds this useful, have at it. I'm not entirely sure if all the checking is required for _elapsedMins? I couldn't work out (and i guess in truth this is the bit that has been stumping me, not thinking like a computer) a more elegant way to get the 'elapsed time' without getting weird figures like -55 depending on what time i had started the mission... Edited May 12, 2015 by Stilton Share this post Link to post Share on other sites
st_dux 26 Posted May 12, 2015 (edited) I'm not entirely sure if all the checking is required for _elapsedMins? I couldn't work out (and i guess in truth this is the bit that has been stumping me, not thinking like a computer) a more elegant way to get the 'elapsed time' without getting weird figures like -55 depending on what time i had started the mission... _elapsedDays = (dateToNumber(_curDate) - dateToNumber(_startDate)) * 365; _elapsedHours = (_elapsedDays * 24) mod 24; _elapsedMins = (_elapsedHours * 60) mod 60; _elapsed = format ["%1, %2, %3",floor(_elapsedDays),floor(_elapsedHours),floor(_elapsedMins)]; The "mod" operator (short for modulo) provides a division remainder, which allows you to get remaining hours after elapsed days and remaining minutes after elapsed hours. I assume this is what you really want. Edited May 12, 2015 by ST_Dux Share this post Link to post Share on other sites
stilton 0 Posted May 12, 2015 brilliant cheers. i'm not a -total- idiot i swear! i've done this stuff in c# before, and i remember using the modulo operator there, but there it's like % i think.. but i had no idea it was in ofp/arma :D ..infact i think i have seen it other peoples arma scripts and might've even looked it up before - but memory like a fish i guess. i fear for every bit of knowledge i learn on here for arma scripting im 'losing' other knowledge.. i've hit my cap. :D but yes that's totally 'the more elegant way' i wanted, cheers :) Share this post Link to post Share on other sites
st_dux 26 Posted May 12, 2015 i've done this stuff in c# before, and i remember using the modulo operator there, but there it's like % i think.. You can use % in SQF as well. Both % and mod function identically... so that's one less new thing you need to remember :) Share this post Link to post Share on other sites
stilton 0 Posted May 12, 2015 or you've just taught me another thing so now i have to forget something else! stop please stop! Share this post Link to post Share on other sites
dreadedentity 278 Posted May 12, 2015 You guys still love your complicated scripts/functions. DE_calcElapsedTime = { _startDate = _this; _elapsedTime = []; { _elapsedTime pushBack (_x - (_startDate select _forEachIndex)); }forEach (date); _elapsedTime; }; That's all you need right there. It's small, it's light, it's cpu-friendly. Example usage: startTime = date; player addAction ["Calculated Elapsed Time", { hint str (startTime call DE_calcElapsedTime); }, [], 6]; Share this post Link to post Share on other sites