Saturday, November 12, 2011

More games with SLS

Since SLS lets you control lights, I've built up several script systems and a trigger based around lighting that uses SLS functionality. First, I've added the ability to turn lights on/off by doing appropriate damage to the light source. Normally this is fire for on, and ice for off, but "cold lights" would just be a matter of a quick script edit. You can also turn lights on/off via a number of non-damaging spells. Gust of Wind or Darkness etc will turn off a torch for instance. Magical lights are not able to be turned off via gust of wind, but can be dispelled. A variable on the light records the level of the creature that enchanted the light, and the dispel line of spells are very straightforward to implement. And of course some light sources can simply be used to turn them on/off.

So what? Well this is where my trigger comes in. I have a trigger for the lightsphere of a lightsource. The trigger reduces the hide skill of pc's that enter (not npc's as the ai can't deal with that, a sneaky npc doesn't stick to shadows), and restores it on exiting the trigger. But the trigger is also aware of the status of the light, if the light is off, the pc gets no bonus entering the trigger. The scripts that allow turning on and off lights also are aware of the trigger assigned to them, and adjust the hide skill accordingly, so for instance if the player is in the trigger when the light goes on, the hide bonus is immediately removed. This is demonstrated in this trigger awareness video .

Finally, the trigger looks for a local variable named guards_lights on anything that enters, and keeps track of if a guard can use the light source (a variable on the light source). Npc's with the guards_lights variable will move to a light source and turn the light back on if it's off and they can use it. Your average castle guard can light a torch, but not turn on a magical light.

In this youtube video you can see the guarded light function in action. link The pc hits the torch with an ice arrow at the very beginning of the video. You can see the guard enter the trigger (marked by the mushrooms for the demo). As he enters the trigger he notices the light is out, has a speakstring that plays "darn light!", moves to the lightsource, plays a use animation (it should loop until the light turns on but doesn't in this demo video), the light comes back on, and he then continues on his patrol path.

Tuesday, November 1, 2011

Fixing the SLS, light tag bug

Problem: The SLS lighting system relies on the tags of lights. However, saving and reloading the game causes lights to lose their tags, breaking SLS.

Solution: change of the SLS' ginc_sls2 script to reset the tag of the nearest light object when the action to handle placeable lights is called. Solution a bit below.

potential issue: assumes the nearest light object is the one to be used. This is normally the case, but you may want to make a copy of the scripts and use the altered script where you know the closest light will be the right one, such as for usable placeables like torches.


in ginc_sls2, line 352 is:
string sLightTag = GetLocalString(oFitting,"lightTag");

comment that out and replace it with
            //work around tag bug. kamal
            object oLight = GetNearestObject(OBJECT_TYPE_LIGHT, oFitting, 1);
            string sLightTag = GetLocalString(oFitting,"lightTag");
            SetTag(oLight, sLightTag);

This will change the script that controls turning the light on and off, so that it resets the light's tag automatically when the light is used, and then proceeds normally through the script. It does assume the light you want to turn on is the nearest light, but I believe that will be the case in almost all cases.

As an added bonus: If you make this change to ginc_sls2, and save ginc_sls2 to your override folder, it should fix the problem in every single player module that uses the SLS, thanks to the priority of the override (PWs can ignore the override folder).