Frictional Games Forum (read-only)

Full Version: On and off light.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello! I come here for a code.
sorry if this is not well understood English ... that I speak Spanish and am using the translator
I hope you understand me

I want prener a light with a button or area (same for me) and off (like a switch). This time it was with a book by touching an area comprising a light.

But I have a problem. Achievement on and off the light but after aver done this. no light turns back on, it's like only use the script only once I leave here.


void OnStart()
{
SetLocalVarInt("Var0", 0);
SetLocalVarInt("Var1", 0);
AddEntityCollideCallback("B0", "A0A", "Prender0", true, 1);
AddEntityCollideCallback("B1", "A1A", "Prender1", true, 1);
AddEntityCollideCallback("B0", "D0", "Desactivo0", true, 1);
AddEntityCollideCallback("B1", "D1", "Desactivo1", true, 1);

}

void Desactivo0(string &in asParent, string &in asChild, int alState)
{
SetLocalVarInt("Var0", 0);


}
void Desactivo1(string &in asParent, string &in asChild, int alState)
{
SetLocalVarInt("Var1", 0);



}

void Prender1(string &in asParent, string &in asChild, int alState)
{
AddLocalVarInt("Var1", 1);
if(GetLocalVarInt("Var1") == 1)
{

SetLampLit("l1", false, false);
SetLampLit("l2", false, false);
SetLampLit("l3", false, false);
SetLampLit("l4", false, false);
SetLampLit("l5", false, false);
SetLampLit("l6", false, false);
SetLampLit("l7", false, false);
SetLampLit("l8", false, false);
SetLampLit("l9", false, false);
SetLampLit("l10", false, false);
SetLampLit("l11", false, false);
SetLampLit("l12", false, false);
SetLampLit("l13", false, false);
SetLampLit("l14", false, false);
SetLampLit("l15", false, false);
SetLampLit("l16", false, false);
SetLampLit("l17", false, false);
SetLampLit("l18", false, false);
SetLampLit("l19", false, false);
SetLampLit("l20", false, false);

SetLampLit("l16", true, true);
SetLampLit("l12", true, true);
SetLampLit("l8", true, true);
SetLampLit("l4", true, true);
SetLampLit("l20", true, true);
}

}
void Prender0(string &in asParent, string &in asChild, int alState)
{
AddLocalVarInt("Var0", 1);
if(GetLocalVarInt("Var0") == 1)
{
SetLampLit("l1", false, false);
SetLampLit("l2", false, false);
SetLampLit("l3", false, false);
SetLampLit("l4", false, false);
SetLampLit("l5", false, false);
SetLampLit("l6", false, false);
SetLampLit("l7", false, false);
SetLampLit("l8", false, false);
SetLampLit("l9", false, false);
SetLampLit("l10", false, false);
SetLampLit("l11", false, false);
SetLampLit("l12", false, false);
SetLampLit("l13", false, false);
SetLampLit("l14", false, false);
SetLampLit("l15", false, false);
SetLampLit("l16", false, false);
SetLampLit("l17", false, false);
SetLampLit("l18", false, false);
SetLampLit("l19", false, false);
SetLampLit("l20", false, false);

SetLampLit("l1", true, true);
SetLampLit("l2", true, true);
SetLampLit("l3", true, true);
SetLampLit("l4", true, true);
SetLampLit("l5", true, true);
SetLampLit("l9", true, true);
SetLampLit("l13", true, true);
SetLampLit("l17", true, true);
SetLampLit("l20", true, true);
SetLampLit("l16", true, true);
SetLampLit("l12", true, true);
SetLampLit("l8", true, true);
SetLampLit("l18", true, true);
SetLampLit("l19", true, true);

}

}
hopefully can give me the solution Thanks.
If you want it to happen multiple times, you need to pass in false to AddEntityCollideCallback. Though, you're probably using script areas for a switch or lever, which would be the wrong way of checking which direction the switch was pulled.
So basically what you want is to make a lightswitch?
If so, I'll post a solution in a few minutes.
(07-15-2012, 11:23 PM)Ongka Wrote: [ -> ]So basically what you want is to make a lightswitch?
If so, I'll post a solution in a few minutes.
I would help a lot if you could do that also I will try the first way I said

Thanks!
You want to turn all lights on and off with one switch right?
(07-15-2012, 11:46 PM)Ongka Wrote: [ -> ]You want to turn all lights on and off with one switch right?

Yes.
Only it would be enough to know how to operate a switch that can turn on and off a light infinitely.
Create a lever, doesn't matter which one.
Set the configuration of the lever like shown in the image.
[Image: Qw2NX.jpg]


Put this into your script:
Code:
void LightSwitch(string &in asEntity, int alState)
{
    if(alState == 1){
    
        for(int i=1;i<=20;i++)  //Change the 20 to any number you want, e.g. 10, this will cause only the first 10 to be lit/unlit
        {
        SetLampLit("l"+i, false, true);
        }

    }
    else if(alState == -1){
        for(int i=1;i<=20;i++)  //Change the 20 to any number you want, e.g. 10, this will cause only the first 10 to be lit/unlit
        {
        SetLampLit("l"+i, true, true);
        }
    }
}

By moving the lever up the lamps get lit and by moving down they get unlit.
Works infinite times.

Have fun! Wink
(07-16-2012, 01:15 AM)Ongka Wrote: [ -> ]Create a lever, doesn't matter which one.
Set the configuration of the lever like shown in the image.
[Image: Qw2NX.jpg]


Put this into your script:
Code:
void LightSwitch(string &in asEntity, int alState)
{
    if(alState == 1){
    
        for(int i=1;i<=20;i++)  //Change the 20 to any number you want, e.g. 10, this will cause only the first 10 to be lit/unlit
        {
        SetLampLit("l"+i, false, true);
        }

    }
    else if(alState == -1){
        for(int i=1;i<=20;i++)  //Change the 20 to any number you want, e.g. 10, this will cause only the first 10 to be lit/unlit
        {
        SetLampLit("l"+i, true, true);
        }
    }
}

By moving the lever up the lamps get lit and by moving down they get unlit.
Works infinite times.

Have fun! Wink
Thank you very much! Did not know recently started with this.
So did it work?
It may be hard in the beginning, but you'll learn to do this stuff by yourself step by step.