GolovaRaoul

[Solved] Trying to create Advanced Time.sqf

8 posts in this topic

Hello everyone,

I think for some of you this might be a very simple question, but I've only studied 6 weeks Python on my college, so I simply do not 100% know how Arma-coding works...

Anyway, my question is how to get this script to work:

Spoiler

if (!isServer) exitWith {};
while {true} do
{
    if (daytime >= 6 || daytime <= 6.75) then
    {
        setTimeMultiplier 3
    }
    elif (daytime > 6.75 || daytime <= 11) then
    {
        setTimeMultiplier 32
    };
    elif (daytime > 11 || daytime <= 15) then
    {
        setTimeMultiplier 1.22
    };
    elif (daytime > 15 || daytime <= 16.75) then
    {
        setTimeMultiplier 21
    };
    else
    {
        setTimeMultiplier 1
    };
    uiSleep 60;
};

Since Arma does not accept 'elif'...

The goal behind this script is to let the server hang a bit on sun rise and sunset...
Like the server starts with a sunrise, and it restarts exactly when sunset (sorry, that's very bad English...)

Thanks for responding!

Paul

Share this post


Link to post
Share on other sites

Posted (edited)

12 minutes ago, GolovaRaoul said:

Hello everyone,

I think for some of you this might be a very simple question, but I've only studied 6 weeks Python on my college, so I simply do not 100% know how Arma-coding works...

Anyway, my question is how to get this script to work:

  Hide contents

if (!isServer) exitWith {};
while {true} do
{
    if (daytime >= 6 || daytime <= 6.75) then
    {
        setTimeMultiplier 3
    }
    elif (daytime > 6.75 || daytime <= 11) then
    {
        setTimeMultiplier 32
    };
    elif (daytime > 11 || daytime <= 15) then
    {
        setTimeMultiplier 1.22
    };
    elif (daytime > 15 || daytime <= 16.75) then
    {
        setTimeMultiplier 21
    };
    else
    {
        setTimeMultiplier 1
    };
    uiSleep 60;
};

Since Arma does not accept 'elif'...

The goal behind this script is to let the server hang a bit on sun rise and sunset...

Thanks for responding!

Paul

Not sure if this will work or not and i know less coding then you but i think when i have been looking through scripts you might do it like this... 

if (!isServer) exitWith {};
while {true} do
{
    if (daytime >= 6 || daytime <= 6.75) then
    {
        setTimeMultiplier 3;
    };
    if (daytime > 6.75 || daytime <= 11) then
    {
        setTimeMultiplier 32;
    };
    if (daytime > 11 || daytime <= 15) then
    {
        setTimeMultiplier 1.22;
    };
    if (daytime > 15 || daytime <= 16.75) then
    {
        setTimeMultiplier 21;
    };
    else
    {
        setTimeMultiplier 1;
    };
    uiSleep 60;
};

Basically just change the elif to if. you also missed a ; on your first block. I also think you need a ; after each of the time multiplier numbers as it ends the line

Edited by Mr Health And Safety
1 person likes this

Share this post


Link to post
Share on other sites
Advertisement

Thanks man :)

Your code almost worked, but for some reason it didn't like the else statement

So I made it like this and it worked:

Spoiler

if (!isServer) exitWith {};
while {true} do
{
    if (daytime >= 6 || daytime <= 6.75) then
    {
        setTimeMultiplier 3
    };
    if (daytime > 6.75 || daytime <= 11) then
    {
        setTimeMultiplier 32
    };
    if (daytime > 11 || daytime <= 15) then
    {
        setTimeMultiplier 1.22
    };
    if (daytime > 15 || daytime <= 16.75) then
    {
        setTimeMultiplier 21
    };
    if (daytime > 16.75 || daytime < 6) then
    {
        setTimeMultiplier 120
    };
    uiSleep 60;
};

Thanks for responding so quickly :) +1

Share this post


Link to post
Share on other sites

wow really? I didnt think it would work as normally doesn't lol. Are you sure you dont need the ; to end each setTimeMultiplier line though? 

Share this post


Link to post
Share on other sites

Eeeehm... Could be, Im not sure :P

But this does exactly the same as you said me, so I guess goal achieved... :)

1 person likes this

Share this post


Link to post
Share on other sites
2 hours ago, Mr Health And Safety said:

wow really? I didnt think it would work as normally doesn't lol. Are you sure you dont need the ; to end each setTimeMultiplier line though? 

psst if(something) then { code } else { code }; :P

2 hours ago, GolovaRaoul said:

Eeeehm... Could be, Im not sure :P

But this does exactly the same as you said me, so I guess goal achieved... :)

Use this, it's much better :)

Also i've looked at what you have there, and it seems like you are going to be infinity using 21, || = or, && = and. This should work better, to make sure it's not always on 21.

Making this code run faster (not when it loops but the actual execution of the code)

DO NOT REMOVE THE "TRUE" OR ADD A ; AT THE END OF IT! IT CAN BREAK THE EXILE THREAD SYSTEM!

if (!isServer) exitWith {};
_fnc_time =
{
    switch (true) do
    {
        case ((daytime >= 6) && (daytime <= 6.75)):
        {
            setTimeMultiplier 3;
        };
        case ((daytime > 6.75) && (daytime <= 11)):
        {
            setTimeMultiplier 32;
        };
        case ((daytime > 11) && (daytime <= 15)):
        {
            setTimeMultiplier 1.22;
        };
        case ((daytime > 15) && (daytime <= 16.75)):
        {
            setTimeMultiplier 21;
        };
        default 
        {
            setTimeMultiplier 1;
        };
    };
    true
};
if!(isNil 'Fnc_timeThread') then { [Fnc_timeThread] call ExileServer_system_thread_removeTask; };
Fnc_timeThread = [60, _fnc_time, [], true] call ExileServer_system_thread_addtask;

Python dosent have anything to do with arma, arma is SQF completely different language, i recommend reading up on this: https://community.bistudio.com/wiki/Category:Scripting_Commands_Arma_3 it will help you get a understanding of armas scripting language.

1 person likes this

Share this post


Link to post
Share on other sites

Thanks man :)

Yeah I noticed that my script didn't work :P It as indeed stuck on multiplier 21

Thanks for your code man, works perfectly :)

Share this post


Link to post
Share on other sites

we have closed this thread and marked it as solved.

Share this post


Link to post
Share on other sites
Advertisement
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.