Page 1 of 1

switching lights, or a number of them

Posted: Wed Oct 08, 2003 11:54 am
by JollyOrc
comments welcome.

Especially regarding perfomance, possibilities where this can go
hideously wrong, etc.

If no one can find something serious, I would propose this to be included in player housing, as many probably would like to switch lights on or off... ;)

Code: Select all

/*
ply_lightswitch is a set of two scripts that help
switching a number of lights on or off.

It consists of two functions: ply_SwSingleLight and
ply_Sw_MassLight.

ply_Sw_SingleLight just takes the existance of the
given object for granted, and turns it on or off,
depending on intOnOff. It also recomputed lighting.

ply_Sw_MassLight cycles through a bunch of objects,
by building the object tags out of a root tag and a
running number. It then invokes ply_Sw_SingleLight
to handle the actual turning on or off.


//::///////////////////////////////////////////////
//:: ply_SwSingleLight
//::
//:://////////////////////////////////////////////
/*
    This switches one object (oSwObject) on or off,
    depending on intOnOff (on=TRUE, off=FALSE, Default=FALSE)
*/
void ply_SwSingleLight(object oSwObject, int intOnOff = FALSE)
{

//  actual switching on or off of a single object.
    if (intOnOff == TRUE)
    {
        PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
        DelayCommand(0.4,SetPlaceableIllumination(oSwObject, TRUE));
        SetLocalInt(oSwObject,"NW_L_AMION",1);
        DelayCommand(0.5,RecomputeStaticLighting(GetArea(oSwObject)));
    }
    else
    {
        PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);
        DelayCommand(0.4,SetPlaceableIllumination(oSwObject, FALSE));
        SetLocalInt(oSwObject,"NW_L_AMION",0);
        DelayCommand(0.9,RecomputeStaticLighting(GetArea(oSwObject)));
    }
}


//::///////////////////////////////////////////////
//:: ply_SwMassLight
//::
//:://////////////////////////////////////////////
/*
    This cycles through a number of objects stored in
    intObjCount, starting at 0. If the object exists,
    it switches it on or off, according to intOnOff.
*/
void ply_SwMassLight(string strObjTagStart, int intObjCount, int intOnOff = FALSE)
{
    string strObjTag;
    int i=0;
    object oToSwitch;
    while(i<=intObjCount){
        oToSwitch = GetObjectByTag(strObjTagStart + IntToString(i));
        if (oToSwitch != OBJECT_INVALID) ply_SwSingleLight(oToSwitch,intOnOff);
        i++;
    }
}


Posted: Wed Oct 08, 2003 12:13 pm
by Nighthawk4
Two points.

1) As I understand it, Avlis is set in a time when lights were provided by lit torches or candles - not electric lights with switches. I suppose we could use the switch while Roleplaying that we are lighting or extinguishing the torches.

2) There is a post eleswhere, regarding an indicator at the AAAA Workshops to let a customer know if a crafter is on the premises or not. It seems to me that this might be helpful for that purpose. Maybe something like 'Crafter in, but Busy', 'Crafter available', or 'Nobody in' perhaps.

Nice idea, either way.

Posted: Wed Oct 08, 2003 12:23 pm
by JollyOrc
Nighthawk4 wrote:Two points.

1) As I understand it, Avlis is set in a time when lights were provided by lit torches or candles - not electric lights with switches. I suppose we could use the switch while Roleplaying that we are lighting or extinguishing the torches.
I've thought long and hard about this one too.

The requirement for this script stemmed from the following two reasons.
* You can't really set a light source to "disabled" on module
load. It doesn't work, as the glow always remains, even
when the flame animation is gone.

* Chandeliers aren't accessible to the in game avatars, as
they hang on the ceiling.

I think this is a neat workaround.

Posted: Wed Oct 08, 2003 12:38 pm
by Nighthawk4
Thanks JollyOrc,

The first point explains why I could not get a portal to start inactive.

The RP method for the second one is to use an lamplighter's tool - this is a lit taper on a long stick, together with a small inverted cone. The cone is used to snuff out the candles. This is how candelabra were lit and unlit when they had candles in RealLife.

Some of us are old enough to remember these (just kidding - I am not quite that old).

Posted: Wed Oct 08, 2003 12:55 pm
by JollyOrc
I've actually seen those lamplighter tools in action, but that doesn't solve the ooc problem of getting it to work in game.

Fact is, that the player has no option to do anything to the chandelier. He must interact with some object that is accessible to his avatar.

Posted: Wed Oct 08, 2003 1:12 pm
by Papillon
RP aside, who needs a switchable light in a NWN inhouse area ? The day/night cycle hasn't got any effect on inhouse areas, so it never gets dark anyway. Am I missing something here ?

Apart from that, why do you set a local int (true/false) on the object, if you never read it ?

Second, you can drop the parameter specifying the maximum number of lights, and instead let the while loop run as long as the light-object is valid (light_1, light_2, ... light_n). It will then stop automatically at n+1.

Posted: Wed Oct 08, 2003 1:18 pm
by Nightface
Just guessing, Pap, but I think it's for the RP aspect of turning the lights on when you get home, or turning them off when you leave. I tried to accomplish a similar goal until I realized my dwarf has darkvision. Then, I simply got rid of the torches altogether! :lol:

Posted: Wed Oct 08, 2003 1:23 pm
by JollyOrc
Personally, I think changing lighting according to mood of the rp a "nice thing to have".

For example, Janur likes to experiment with lighting or with shadows when painting (actually having people standing on several locations makes quite different screenshots.).

As to the local int: I've pilfered the whole "make light / dark" part of the script from the on/off scripts thats bound to candelabras in the toolset by default, assuming that they are making sense there. If they don't, I happily drop them. (I think they are there to store the on/off information so one script can do both things: Turning light on and off.)

I'll drop the parameter.

Posted: Wed Oct 08, 2003 1:29 pm
by Papillon
Ah yes, even better, make it one script then :lol:

Posted: Wed Oct 08, 2003 1:37 pm
by JollyOrc
Papillon wrote:Ah yes, even better, make it one script then :lol:
Like this:

Code: Select all

//::///////////////////////////////////////////////
//:: ply_SwMassLight
//::
//:://////////////////////////////////////////////
/*
    This cycles through all objects stored whose tags
    begin with strObjTagStart and are numbered through.
    If the object exists, it switches it on or off,
    depending on prior state.
*/
void ply_SwMassLight(string strObjTagStart)
{
    string strObjTag;
    int i=0;
    object oToSwitch;
    oToSwitch = GetObjectByTag(strObjTagStart + IntToString(i));
    while(oToSwitch != OBJECT_INVALID){
        if (GetLocalInt(oToSwitch,"NW_L_AMION")==0)
        {
            PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
            DelayCommand(0.4,SetPlaceableIllumination(oToSwitch, TRUE));
            SetLocalInt(oToSwitch,"NW_L_AMION",1);
            DelayCommand(0.5,RecomputeStaticLighting(GetArea(oToSwitch)));
        }
        else
        {
            PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);
            DelayCommand(0.4,SetPlaceableIllumination(oToSwitch, FALSE));
            SetLocalInt(oToSwitch,"NW_L_AMION",0);
            DelayCommand(0.9,RecomputeStaticLighting(GetArea(oToSwitch)));
        }
        ply_SwSingleLight(oToSwitch);
        i++;
        oToSwitch = GetObjectByTag(strObjTagStart + IntToString(i));
    }
}