I just can't get this to work. I'm attempting to modify a day script, which works great, and modify it to save as a night script for something else.
Problem is, either the placeable never spawns after DUSK, or it is destroyed and recreated in an infinate loop.
For reference, I'm posting the working DAY script first, followed by my attempt at modifying it for a NIGHT script.
DAY SCRIPT [WORKS]
//::///////////////////////////////////////////////
//:: Name: Light Heartbeat Autoupdater -FIXED!!!
//:: FileName: light_htb
//:: Copyright © 2001 Bioware Corp.
//:: Created By: Grzech_U (gk6)
//:: Created On: 02.04.2007
//:://////////////////////////////////////////////
//<EDIT HERE>
//enter the time of dawn in Your mod
const int DAWN = 6;
//enter the time of dusk in Your mod
const int DUSK = 18;
//enter the number of mintes in one game hour (default is 2)
//seting it to 0 will cause the script to ignore minutes
//may be buggy...
const int MINUTES_PER_HOUR = 2;
//</EDIT HERE>
#include "nw_i0_2q4luskan"
void main()
{
int nCurrentTime = GetTimeHour();
//if its night, destroy the light and create a new light at dawn
if ((nCurrentTime > DUSK) || (nCurrentTime < DAWN))
{
location lLocation = GetLocation(OBJECT_SELF);
string sResRef = GetResRef(OBJECT_SELF);
DestroyObject(OBJECT_SELF, 0.1);
//when is the next dawn?
int nTimeHour;
if (nCurrentTime>DAWN)
{
nCurrentTime=24 -nCurrentTime;
nTimeHour =nCurrentTime + DAWN;
}
else nTimeHour = DAWN -nCurrentTime;
float fTimeHour = HoursToSeconds(nTimeHour);
float fTimeMinutes;
if(MINUTES_PER_HOUR!=0)
{
if(GetTimeMinute()>0)
{
fTimeMinutes=IntToFloat(MINUTES_PER_HOUR-GetTimeMinute())* HoursToSeconds(1)/60.0;
}
}
AssignCommand( GetModule(),
DelayCommand(fTimeHour + fTimeMinutes,
CreateObjectVoid(OBJECT_TYPE_PLACEABLE, sResRef, lLocation)));
}
}
And this is the attempted modified NIGHT script, which does not work.
//::///////////////////////////////////////////////
//:: Name: Light Heartbeat Autoupdater -FIXED!!!
//:: FileName: light_htb
//:: Copyright © 2001 Bioware Corp.
//:: Created By: Grzech_U (gk6)
//:: Created On: 02.04.2007
//:://////////////////////////////////////////////
//<EDIT HERE>
//enter the time of dawn in Your mod
const int DAWN = 6;
//enter the time of dusk in Your mod
const int DUSK = 18;
//enter the number of mintes in one game hour (default is 2)
//seting it to 0 will cause the script to ignore minutes
//may be buggy...
const int MINUTES_PER_HOUR = 2;
//</EDIT HERE>
#include "nw_i0_2q4luskan"
void main()
{
int nCurrentTime = GetTimeHour();
//if its day, destroy the light and create a new light at night
if ((nCurrentTime > DAWN) || (nCurrentTime < DUSK))
{
location lLocation = GetLocation(OBJECT_SELF);
string sResRef = GetResRef(OBJECT_SELF);
string sTime = IntToString(nCurrentTime);
AssignCommand(GetFirstPC(), SpeakString("DEBUG: DESTROYED AT " + sTime));
DestroyObject(OBJECT_SELF, 0.1);
//when is the next dusk?
// **** I AM THINKING IT IS THIS SECTION THAT IS CAUSING MY PROBLEM
int nTimeHour;
if (nCurrentTime>DAWN)
{
nCurrentTime=24 -nCurrentTime;
nTimeHour =nCurrentTime + DAWN;
}
else nTimeHour = DAWN -nCurrentTime;
// *******
float fTimeHour = HoursToSeconds(nTimeHour);
float fTimeMinutes;
if(MINUTES_PER_HOUR!=0)
{
if(GetTimeMinute()>0)
{
fTimeMinutes=IntToFloat(MINUTES_PER_HOUR-GetTimeMinute())* HoursToSeconds(1)/60.0;
}
}
AssignCommand( GetModule(),
DelayCommand(fTimeHour + fTimeMinutes,
CreateObjectVoid(OBJECT_TYPE_PLACEABLE, sResRef, lLocation)));
}
}
I have marked with *** where I -think- the problem is but I can't figure out how to rewrite it to suit my needs. So, I'm dipping into the community help desk once again!
Thanks,
FP!