Game Development Community

Building light switch

by Ronald J Nelson · in · 06/23/2007 (12:19 am) · 8 replies

I wanted to see if this can be done with TGE 1.5.2 script side only. Can you set up a building with sgmountlights in it that can be turned on and off by a switch on the wall. also can you do this with omni lights?

I want people to be able to make maps with my game's resources, but I need to make the buildings able to be added as one piece.

#1
06/23/2007 (12:44 am)
You could use a trigger to set the light to disabled.

However you achieve this keep in mind that the light has to be dynamic and not be one that needs a relight - otherwise the light will turn off but you'll still see whatever 'baked in' information the light uses.
#2
06/23/2007 (1:15 am)
Something like this would work.

datablock TriggerData(SwitchTrigger)
{
   // The period is value is used to control how often the console
   // onTriggerTick callback is called while there are any objects
   // in the trigger.  The default value is 100 MS.
   tickPeriodMS = 100;
};

function SwitchTrigger::onEnterTrigger(%this,%trigger,%obj)
{
if(isObject(Light1))
Light1.delete();

else
{
   %light = new sgLightObject(Light1) {
      canSaveDynamicFields = "1";
      position = lightBulb.getPosition();
      rotation = "1 0 0 0";
      scale = "1 1 1";
      dataBlock = "DynamicLight";
      Enable = "1";
      IconSize = "1";
      ParticleColorAttenuation = "1";
   };
}

   Parent::onEnterTrigger(%this,%trigger,%obj);
}

function SwitchTrigger::onLeaveTrigger(%this,%trigger,%obj)
{

   Parent::onLeaveTrigger(%this,%trigger,%obj);
}

This is a very inefficient way of doing it, but I think this should work.
#3
06/23/2007 (1:22 am)
Why create a new light in the trigger and then delete it?

Why not grab the light from the mission group and set its "Enable" flag to false.
#4
06/23/2007 (10:51 am)
How well does this work in a multiplayer environment?
#5
06/23/2007 (11:26 am)
It was just an example, it really shouldn't be taken too seriously. I think Tim's idea is much better, though you'd have to add some new console functions to apply the changes.
#6
06/23/2007 (8:58 pm)
My method wouldn't work across a network - unless you used some hacky script to obtain and send the ghost ID of the light. Best to create a new method in source.
#7
06/25/2007 (9:23 am)
Use the light's setEnable script method instead - most object methods are network friendly.
#8
06/25/2007 (9:28 am)
Thanks John, I am assuming the usual client do a server command then have that function take care of everything, correct?