Aller au contenu

Photo

day/night script trouble


  • Veuillez vous connecter pour répondre
16 réponses à ce sujet

#1
Batmanis64

Batmanis64
  • Members
  • 84 messages
Okay, here's a script I'm using to turn on/off lights (and lock/unlock doors), from NWN2 wiki here.  My module starts in the daytime.  When it becomes night, all lights turn on and doors lock.  So far, so good.  However, the next morning and into the day doors stay locked, and lights are still on.  I checked the local Int "NW_L_AMION" and it remains at 1.  That last part of the script, the one that's supposed to run at validDay, obviously isn't working.  What's going on?


////////////////////////////////////////////////////////////////////////////////
// Automatically turn lights on during the night or off during the day
////////////////////////////////////////////////////////////////////////////////
// Modified By: Stephen M. LaBar, Jr.
// Modified On: 08/07/2002
////////////////////////////////////////////////////////////////////////////////
// Currently this goes into the OnHeartbeat event handler for an invisible
// object located in a module area.  For ease of use I named my invisible
// object LightOnOff.
////////////////////////////////////////////////////////////////////////////////
// Make a custom placeable light with the tag LampPost and place it in whatever
// area you want in your module.
////////////////////////////////////////////////////////////////////////////////
void main()
{
object oLamp;
int nNth=0;
oLamp = GetObjectByTag("light1", nNth);
object oZ2Door1 = GetObjectByTag("hamil_in");
object oZ2Door2 = GetObjectByTag("annex_in");
object oZ2Door3 = GetObjectByTag("rygate_in");
object oZ2Door4 = GetObjectByTag("pierce_in");
object oZ2Door5 = GetObjectByTag("sung_in");
object oZ2Door6 = GetObjectByTag("silban_out");
object oZ1Door1 = GetObjectByTag("cross_in");
object oZ1Door2 = GetObjectByTag("kege_in");
object oZ1Door3 = GetObjectByTag("pawn_in");
object oZ1Door4 = GetObjectByTag("wool_in");
object oZ1Door5 = GetObjectByTag("goods_in");
object oZ1Door6 = GetObjectByTag("killian_out");
object oZ1Door7 = GetObjectByTag("z1_ishap_out");
object oKrndrDoor1 = GetObjectByTag("eagle_in");
object oKrndrDoor2 = GetObjectByTag("touchstone_in");
object oLamutDoor1 = GetObjectByTag("garrison");
object oLamutDoor2 = GetObjectByTag("fletch_in");

int validDay = GetIsDawn() || GetIsDay();
int validNight = GetIsDusk() || GetIsNight();

// This part of the script only runs one time.

    if (GetLocalInt(OBJECT_SELF, "RUNONCE") != 1)
    {
    while (GetIsObjectValid(oLamp))
    {
        SetLocalInt(OBJECT_SELF, "RUNONCE", 1);
        SetLightActive(oLamp, 0);
        SetLocked(oZ2Door1, 0);
        SetLocked(oZ2Door2, 0);
        SetLocked(oZ2Door3, 0);
        SetLocked(oZ2Door4, 0);
        SetLocked(oZ2Door5, 0);
        SetLocked(oZ2Door6, 0);
        SetLocked(oZ1Door1, 0);
        SetLocked(oZ1Door2, 0);
        SetLocked(oZ1Door3, 0);
        SetLocked(oZ1Door4, 0);
        SetLocked(oZ1Door5, 0);
        SetLocked(oZ1Door6, 0);
        SetLocked(oZ1Door7, 0);
        SetLocked(oKrndrDoor1, 0);
        SetLocked(oKrndrDoor2, 0);
        SetLocked(oLamutDoor1, 0);
        SetLocked(oLamutDoor2, 0);
        SetLocalInt(OBJECT_SELF, "NW_L_AMION", 0);
        RecomputeStaticLighting(GetArea(oLamp));
        nNth++;
        oLamp = GetObjectByTag("light1", nNth);
    };
    }
   
// This part of the script only runs once at validNight.

    if (validNight && GetLocalInt(OBJECT_SELF, "NW_L_AMION") == 0)
    {
    while (GetIsObjectValid(oLamp))
    {
        SetLightActive(oLamp, 1);
        SetLocked(oZ2Door1, 1);
        SetLocked(oZ2Door2, 1);
        SetLocked(oZ2Door3, 1);
        SetLocked(oZ2Door4, 1);
        SetLocked(oZ2Door5, 1);
        SetLocked(oZ2Door6, 1);
        SetLocked(oZ1Door1, 1);
        SetLocked(oZ1Door2, 1);
        SetLocked(oZ1Door3, 1);
        SetLocked(oZ1Door4, 1);
        SetLocked(oZ1Door5, 1);
        SetLocked(oZ1Door6, 1);
        SetLocked(oZ1Door7, 1);
        SetLocked(oKrndrDoor1, 1);
        SetLocked(oKrndrDoor2, 1);
        SetLocked(oLamutDoor1, 1);
        SetLocked(oLamutDoor2, 1);
        SetLocalInt(OBJECT_SELF, "NW_L_AMION", 1);
        RecomputeStaticLighting(GetArea(oLamp));
        nNth++;
        oLamp = GetObjectByTag("light1", nNth);
    };
    }

// This part of the script only runs once at validDay.
   
    if (validDay && GetLocalInt(OBJECT_SELF, "NW_L_AMION") == 1)
    {
    while (GetIsObjectValid(oLamp))
    {
        SetLightActive(oLamp, 0);
        SetLocked(oZ2Door1, 0);
        SetLocked(oZ2Door2, 0);
        SetLocked(oZ2Door3, 0);
        SetLocked(oZ2Door4, 0);
        SetLocked(oZ2Door5, 0);
        SetLocked(oZ2Door6, 0);
        SetLocked(oZ1Door1, 0);
        SetLocked(oZ1Door2, 0);
        SetLocked(oZ1Door3, 0);
        SetLocked(oZ1Door4, 0);
        SetLocked(oZ1Door5, 0);
        SetLocked(oZ1Door6, 0);
        SetLocked(oZ1Door7, 0);
        SetLocked(oKrndrDoor1, 0);
        SetLocked(oKrndrDoor2, 0);
        SetLocked(oLamutDoor1, 0);
        SetLocked(oLamutDoor2, 0);
        SetLocalInt(OBJECT_SELF, "NW_L_AMION", 0);
        RecomputeStaticLighting(GetArea(oLamp));
        nNth++;
        oLamp = GetObjectByTag("light1", nNth);
    };
    }

}

btw, how do you post script boxes in this forum?

#2
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
That looks like a NWN1 script, judging by the 2002 date. That's a problem because the GetIsDay group of functions don't work properly in NWN2, and NWN2 has trouble finding placed lights using GetObjectByTag after a save.

So, you'll have to check the time manually by using GetTimeHour and save the lights as local objects in order to get at them later.

#3
Batmanis64

Batmanis64
  • Members
  • 84 messages
That makes sense, considering my custom script on eating rations uses the GetTimeHour function, and that works perfectly.



I've never used local objects. How does that work?

#4
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
They're variables you set on an object (area, placeable, creature), except instead of being an integer, float, or string, they're another object, or rather a pointer to another object. You use the SetLocalObject and GetLocalObject functions to handle them. For lights, I run a script when the player first runs the module that looks up all the placeable lights by tag and then saves them as local objects on their particular area.

#5
Morbane

Morbane
  • Members
  • 1 883 messages

Batmanis64 Wrote...
btw, how do you post script boxes in this forum?


You don't really - the "code" tag works but there isn't any formatting for the code. so in essence it is a waste of time.

Modifié par Morbane, 30 août 2010 - 04:08 .


#6
Shallina

Shallina
  • Members
  • 1 011 messages
So far I haven't got any problem with GetOBjectBytAg and light and GetIsDay() and GetIsNight() function.

#7
Guest_Chaos Wielder_*

Guest_Chaos Wielder_*
  • Guests
Lugaid, what kind of problems have you had with GetIsDay() and the rest of them? I've had no difficulties, but I'd be interested in knowing whether or not there are some.

#8
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
I remember testing it before, and it would always return false, no matter what the time of day. If it works, then something else must throwing the script above off, the saved light problem doesn't crop until you load a saved game.

#9
Batmanis64

Batmanis64
  • Members
  • 84 messages
But what about the NW_L_AMION staying true? How would that be related to GetObjectByTag? Perhaps it has something to do with GetIsObjectValid when lights are active....or the Dusk and Dawn entries are confusing things.

#10
Batmanis64

Batmanis64
  • Members
  • 84 messages
so I ran some day/night cycles in-game, and sure enough, the script works when I don't load a game, but when I go back and load one, the problem persists. I'm using MotB, by the way. I'll set up a script with local objects and see if that works.

#11
Batmanis64

Batmanis64
  • Members
  • 84 messages
Lugaid, can you point me in the direction of a sample script that you have used?

#12
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
I know I posted them in the old forums, just can't find them easily. My Wassau prefabs on the vault have the scripts attached to them (OW, BA, and OC are good places to start).

#13
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 585 messages
I've seen the saved light problem as well. I haven't had any problems with GetIsDay though.

#14
Shallina

Shallina
  • Members
  • 1 011 messages
No problem with GetIsDay() or Night, but the light do loose their tag after reloading a saved game.

#15
Batmanis64

Batmanis64
  • Members
  • 84 messages
Lugaid, here's what I have for an initial script to store the local objects (extracted and edited from yours):



////////////////////////////////////////////////////////////////////////////////

//sets up lights as local objects

////////////////////////////////////////////////////////////////////////////////

void main()

{

object oLamp;

int nNth=0;

oLamp = GetObjectByTag("light1", nNth);



while (GetIsObjectValid(oLamp))

{

SetLocalObject(OBJECT_SELF, "lights" + IntToString(nNth), oLamp);

nNth++;

oLamp = GetObjectByTag("light1", nNth);

}

}



I'm assuming I would have to use this technique and store each light with a separate name. Is there an easier way? Anyways, I'm not sure how to call all of those objects in my hb script other than listing them all, since there's not an "nth" for GetLocalObject.



Long story short, I have no idea how to do this.

#16
Shallina

Shallina
  • Members
  • 1 011 messages
I am using something similar. GetObjectByTag("light1") won't work after a reloaded save.





int nLampNumber = 1;

object oLamp;

string wp_lamp;

string fire_tag ="firetorch_ar4800"+IntToString(nLampNumber) ;

string light_tag = "lt_torch_ar4800"+IntToString(nLampNumber);

wp_lamp = "wp_torch"+IntToString(nLampNumber);

oLamp = GetObjectByTag(wp_lamp);

object oArea =GetArea(GetFirstPC(TRUE));



while (GetIsObjectValid(oLamp)){



CreateObject(OBJECT_TYPE_PLACED_EFFECT,"firetorch_ar4800",GetLocation(oLamp),TRUE,fire_tag);

SetLocalObject(oArea,light_tag,CreateObject(OBJECT_TYPE_LIGHT,"lt_torch_ar4800",GetLocation(oLamp),TRUE,light_tag));



nLampNumber = nLampNumber+1;

wp_lamp = "wp_torch"+IntToString(nLampNumber);

fire_tag ="firetorch_ar4800"+IntToString(nLampNumber) ;

light_tag = "lt_torch_ar4800"+IntToString(nLampNumber);

oLamp = GetObjectByTag(wp_lamp);

}



and the other one to shut them down



int nLampNumber = 1;

object oArea =GetArea(GetFirstPC(TRUE));



string fire_tag ="firetorch_ar4800"+IntToString(nLampNumber) ;

string light_tag = "lt_torch_ar4800"+IntToString(nLampNumber);









while (GetIsObjectValid(GetObjectByTag(fire_tag))){



DestroyObject(GetObjectByTag(fire_tag));

DestroyObject(GetLocalObject(oArea,light_tag));

DeleteLocalObject(oArea,light_tag);



nLampNumber = nLampNumber+1;



fire_tag ="firetorch_ar4800"+IntToString(nLampNumber) ;

light_tag = "lt_torch_ar4800"+IntToString(nLampNumber);

}

#17
Batmanis64

Batmanis64
  • Members
  • 84 messages
I set up the local objects and everything works perfectly. Thanks!