Help first time Script

Blahman919

New Member
So, me and my friends have been wanting a way to have our sever be 2 hours daytime then 1 hour night before restart. So I decided I would looking into some scripting options and I came up with this:
Code:
_TimeToNight = 120;  //Time in minutes before nighttime



r_DoLoop = true;
_TimeToNight = _TimeToNight * 60; //Set time to seconds
while {r_DoLoop} do {
    if (_TimeToNight > 0) then {      //Repeat until time is 0
        _TimeToNight - 1;                 //Subtract one second each loop
    };
    if (_TimeToNight = 0) then {      
        setDate [2013, 4, 22, 24, 0];    //Set the time to night, the rest doesn't matter much
        r_DoLoop = false                  //End the loop
    };
    sleep 1;
};

What do you think? I have no idea if this would work or not and am wanting some thoughts on it. My first attempt at any kind of scripting at all with Arma/DayZ.
 
I think that would work. I did a script similiar last week when someone was talking about the same thing. I tested mine and it did work. The issue (i think) is that the server time is retrieved from the server every few minutes. So you can set the time, it will work and then the server retrieves the time from the machine its on and broadcasts that to all the players. You can disable the time sync but I am not sure what kind of issues that would cause ... maybe none, maybe the end of the world.
 
Alright so I added the script in to the server but it doesn't seem to be running, I'm not too sure why. I'm not getting any errors it's just not changing to nighttime.
 
How are you calling the script? In your init.sqf? I would say you want to run this on the server and then use the time sync function to broadcast the new time to all players.

How about you put a
diag_log format["TIMETONIGHT = %1",_timetonight];
in your loop so you can see it countdown in your log.

There is something wrong with your code because actually, it should run and exit almost immediately because if you look at this line
Code:
if (_TimeToNight = 0) then {
that is supposed to be testing if _timetonight is equal to zero. But one equal sign is the ASSIGNMENT operator, you want the COMPARITIVE operator which is 2 equals signs.
So change that line to this and insert your diag_log at the top of you loop and see what happens.
Code:
if (_TimeToNight = =0) then {
 
It still does not seem to be working for whatever reason. The countdown works, it get's to 0 and then seems to do nothing
Here's the full code that I have:

Code:
if (isServer) then {
    _TimeToNight = 3;         //Time in minutes before night time
    _TimeToSkip = 12;           //Amount of hours to skip forward
 
    };
    r_DoLoop = true;
    _TimeToNight = _TimeToNight * 60 + 1;                                  //Set time to seconds
    while {r_DoLoop} do {
       
        if (_TimeToNight >= 0) then {                                  //Repeat until time is 0
            _TimeToNight = _TimeToNight - 1;                            //Subtract one second each loop
                        diag_log format["TIMETONIGHT = %1",_timetonight];
        };
        if (_TimeToNight == 0) then {     
                    setDate [2013, 4, 22, 24, 0];                 //Set the time to night, the rest doesn't matter much
                    r_DoLoop = false                              //End the loop
        };
    sleep 1;
    };
};
 
To change the time for alk clients you need to do a publicvariable. Check the date code in server functions or player sync.

As I mentiined before, the server seems to get the time from the computer and then apply the offset from hive.ini so . Keep testing and use lots of logs to figure out what isnt going on . I can help more later
 
Thanks for all the help you've given, I'll start messing around with the publicvariable, see if I can get it working, not 100% on how to use it with setdate, or where I should put it, but after a bit of tweaking I'm sure I can figure something out.
 
In your server_monitor.sqf file
Code:
_key = "CHILD:307:";
    _result = _key call server_hiveReadWrite;
    _outcome = _result select 0;
    if(_outcome == "PASS") then {
        _date = _result select 1;
        //date setup
        _year = _date select 0;
        _month = _date select 1;
        _day = _date select 2;
        _hour = _date select 3;
        _minute = _date select 4;

        //Force full moon nights
        _date1 = [2013,8,3,_hour,_minute];
if(isDedicated) then {
            setDate _date1;
            dayzSetDate = _date1;
            dayz_storeTimeDate = _date1;
            publicVariable "dayzSetDate";
        };
        diag_log ("HIVE: Local Time set to " + str(_date1));
    };

setDate _date1;
dayzSetDate = _date1;
This line sets the date on the game server to _date1 which is retrieved from the hive call child:307 (which is a function in your hive.dll) and it probably gets the actual time from the server OS itself.
Then it copies the date array (_date1) into the publicvariable dayzSetDate. The next line, publicvariable "dayzsetdate" , sends that variable (dayzsetdate) to all the computers. Thats what publicvariable does, sends a variable and its value to all the computers.

So my point is that even if you change the time in your script, when the server_monitor runs it will get the servers date from the OS and broadcast that date to all the clients (using publicvariable) and the clients will change the time in their game. What you are wanting to do is eliminate the hive.dll calls and control the time yourself. To keep all the clients synced up at the same time you will have to broadcast the publicvariable "dayzsetdate" yourself after setting dayzsetdate = 'your custom time'. Possibly remove the child:307 call and just insert the custom time and date that you are constantly calculating.

all that being said and now you understand there is more to it than just your script, but your script should work. Instead of running it on the server, run it on all the computers by removing any isServer or isDedicated code blocks. The time should change, but 5 minutes later the server will get the time from the OS and broadcast the new time to all the clients and it will be daylight again. Get your script working, then we can figure out the best way to keep your custom time from being changed again.

Check this page. http://killzonekid.com/arma-scripting-tutorials-basic-multiplayer-coding/
Killzone kid has some great tutorials that will help you understand how things work even if they are a bit confusing sometimes. I think SQF was designed to be confusing on purpose :eek:
 
I will defiantly check out that link. Thanks again for all this help.
I cannot seem to find that bit of code in my server_monitor.sqf, I'm running DayZ Epoch, not sure if that would make a difference. I'm either looking in the wrong file or DayZ Epoch does it differently, I wouldn't know myself.
 
ah, of course not. epoch is using like 1.7.6.1 version of dayz .. its like the stone age ;)

I just checked epoch files for the date stuff and

They call this function server_timesync which is in your server_functions.sqf file
Code:
server_timeSync = {
    //Send request
    private ["_hour","_minute","_date","_key","_result","_outcome"];
    _key = "CHILD:307:";
    _result = _key call server_hiveReadWrite;
    _outcome = _result select 0;
    if(_outcome == "PASS") then {
        _date = _result select 1;
      
        if(dayz_fullMoonNights) then {
            _hour = _date select 3;
            _minute = _date select 4;
            //Force full moon nights
            _date = [2013,8,3,_hour,_minute];
        };

        setDate _date;
        PVDZE_plr_SetDate = _date;
        publicVariable "PVDZE_plr_SetDate";
        diag_log ("TIME SYNC: Local Time set to " + str(_date));  
    };
};

its called from server_playersetup.sqf and from server_cleanup.fsm
That looks like the only spots where the time is set. Again tho the same thing, its getting the date from the child:307 call. Should probably look in the hive.log and see exactly what that is doing (or not, probably doesn't matter).
So you want to use a global variable for your time as you countdown and replace the _date = select 1 above with your artificial date .. then see what happens :eek:
_date = date from my timetonight script since I am controlling time now.
(lets call your global variable for the time "DoctorWho" since he is a time lord)
 
So, theory, if I changed my code to something like this:
Code:
        _TimeToNight = 3;         //Time in minutes before night time
    _TimeToSkip = 12;           //Amount of hours to skip forward
        TimeSync1 = [2013, 4, 22, 12, 0];
    r_DoLoop = true;
    _TimeToNight = _TimeToNight * 60 + 1;                                  //Set time to seconds
   
    while {r_DoLoop} do {
       
        if (_TimeToNight >= 0) then {                                  //Repeat until time is 0
            _TimeToNight = _TimeToNight - 1;                            //Subtract one second each loop
                        diag_log format["TIMETONIGHT = %1",_timetonight];
        };
        if (_TimeToNight == 0) then {  
                    TimeSync1 = [2013, 4, 22, 24, 0];  
                    setDate TimeSync1;                 //Set the time to night, the rest doesn't matter much
                    r_DoLoop = false                              //End the loop
        };
    sleep 1;
    };


And then this to:
Code:
server_timeSync = {
    //Send request
    private ["_hour","_minute","_date","_key","_result","_outcome"];
    _key = "CHILD:307:";
    _result = _key call server_hiveReadWrite;
    _outcome = _result select 0;
    if(_outcome == "PASS") then {
        //_date = _result select 1;
       
        if(dayz_fullMoonNights) then {
            //_hour = _date select 3;
            //_minute = _date select 4;
            //Force full moon nights
            //_date = [2013,8,3,_hour,_minute];
        };

        setDate TimeSync1;
        PVDZE_plr_SetDate = TimeSync1;
        publicVariable "PVDZE_plr_SetDate";
        diag_log ("TIME SYNC: Local Time set to " + str(TimeSync1));

Shouldn't that set the server starting dating to the TimeSync1 variable, then have it change over after the countdown finishes?
 
looks like its getting closer.
problems:
Your timesync1 is set to noon ... there is no code to advance the time that is published to the clients. Every 5 minutes, every client will have their time set to noon. I realize you are testing with a 3 minute delay, just something to be aware of later.

I would instead, keep the _date settings in the server_timesync function and put a if / else block . If isnight = false then run the normal date code, else isnight = true then run your modified time code.
Then in your code add a global variable isnight=false; and when your timetonight counts down it sets isnight=true;
Then the next time your server updates the time, it will use the timesync1 on all computers.

I think this will work or at least its getting pretty close to working. When I did this script I think I used the skiptime though, not sure why, but I did, but setdate should work fine. People send me mission and server pbos all the time so I have overwrote my own files and lost the work in progress and cant use it for reference or see why I did what I did.
 
and if we are using global variables to set isnight true/false they are only available on the computer they are declared on. So then the code needs to run on the server, not to mention you would have conflicting setdates coming from each client.
 
So something like this:
Code:
    _TimeToNight = 3;         //Time in minutes before night time
    isnight = flase
    r_DoLoop = true;
    _TimeToNight = _TimeToNight * 60 + 1;                                  //Set time to seconds
    while {r_DoLoop} do {
       
        if (_TimeToNight >= 0) then {                                  //Repeat until time is 0
            _TimeToNight = _TimeToNight - 1;                            //Subtract one second each loop
                        diag_log format["TIMETONIGHT = %1",_timetonight];
        };
        if (_TimeToNight == 0) then {     
                   isnight = true
                    r_DoLoop = false                              //End the loop
        };
    sleep 1;
    };
Code:
server_timeSync = {
    //Send request
    private ["_hour","_minute","_date","_key","_result","_outcome"];
    _key = "CHILD:307:";
    _result = _key call server_hiveReadWrite;
    _outcome = _result select 0;
    if(_outcome == "PASS") then {
        if (isnight == flase) then {
            _date = _result select 1;
       
            if(dayz_fullMoonNights) then {
                _hour = _date select 3;
                _minute = _date select 4;
                //Force full moon nights
                _date = [2013,8,3,_hour,_minute];
            };
        };
        else if (isnight == true) then {
            _date = [2013,8,3,24,0];
        };
        setDate _date;
        PVDZE_plr_SetDate = _date;
        publicVariable "PVDZE_plr_SetDate";
        diag_log ("TIME SYNC: Local Time set to " + str(_date));

    };
};
 
ALLLLMOOOOOSTTTT
First of all I dont know where you are from but in the U.S of A. we spell false differently
Code:
    isnight = flase

and the timesync code, I would move the entire
Code:
 private ["_hour","_minute","_date","_key","_result","_outcome"];
    _key = "CHILD:307:";
    _result = _key call server_hiveReadWrite;
    _outcome = _result select 0;
    if(_outcome == "PASS") then {

into your isnight code block
if (isnight == flase) then {


Code:
server_timeSync = {
private ["_hour","_minute","_date","_key","_result","_outcome"];

if (isnight == flase) then {
    _key = "CHILD:307:";
    _result = _key call server_hiveReadWrite;
    _outcome = _result select 0;
    if(_outcome == "PASS") then {
            _date = _result select 1;
            _hour = _date select 3;
            _minute = _date select 4;
             //Force full moon nights
             _date = [2013,8,3,_hour,_minute];
          }; //end outcome
        }//end if
        else if (isnight == true) then {
            _date = [2013,8,3,24,0];
        };//end else
        setDate _date;
        PVDZE_plr_SetDate = _date;
        publicVariable "PVDZE_plr_SetDate";
        diag_log ("TIME SYNC: Local Time set to " + str(_date));

    };//end timesync
};


That looks about right, check it for errors and test it out.
 
Haha, yeah I tend to misspell stuff all the time, I type far too fast and my fingers get head of my brain xD
But I'll try this out and let you know how it works.
 
I seem to be getting this error:
Code:
15:34:37 Error in expression < Local Time set to " + str(_date));

};
};


server_spawncleanDead = {
private [>
15:34:37   Error position: <};


server_spawncleanDead = {
private [>
15:34:37   Error Missing {
15:34:37 File z\addons\dayz_server\init\server_functions.sqf, line 760


I'm not too sure what's wrong, I think it's saying there's a missing '{' but I cannot find where one would go.
 
I think I may have fixed it.
Changed it to this:
Code:
server_timeSync = {
private ["_hour","_minute","_date","_key","_result","_outcome"];

if (isnight == flase) then {
    _key = "CHILD:307:";
    _result = _key call server_hiveReadWrite;
    _outcome = _result select 0;
    if(_outcome == "PASS") then {
            _date = _result select 1;
            _hour = _date select 3;
            _minute = _date select 4;
             //Force full moon nights
             _date = [2013,8,3,_hour,_minute];
          }; //end outcome
        }//end if
        else (isnight == true) then {
            _date = [2013,8,3,24,0];
        };//end else
        setDate _date;
        PVDZE_plr_SetDate = _date;
        publicVariable "PVDZE_plr_SetDate";
        //diag_log ("TIME SYNC: Local Time set to " + str(_date));

    };//end timesync

But now I'm getting this error that I don't think I was before:

Code:
16:09:14 Error in expression <esList set [_index, AllowedVehiclesList select _lastIndex];
};
AllowedVehiclesLi>
16:09:14   Error position: <select _lastIndex];
};
AllowedVehiclesLi>
16:09:14   Error Zero divisor
16:09:14 File z\addons\dayz_server\init\server_functions.sqf, line 264
16:09:14 Error in expression <ect _lastIndex];
};
AllowedVehiclesList resize _lastIndex;
};

if (count Allowed>
16:09:14   Error position: <resize _lastIndex;
};

if (count Allowed>
16:09:14   Error Zero divisor
16:09:14 File z\addons\dayz_server\init\server_functions.sqf, line 266
16:09:17 "DEBUG: unable to find suitable vehicle to spawn"
16:09:17 Error in expression <esList set [_index, AllowedVehiclesList select _lastIndex];
};
AllowedVehiclesLi>
16:09:17   Error position: <select _lastIndex];
};
AllowedVehiclesLi>
16:09:17   Error Zero divisor
 
Back
Top