SetTileMainLightColor(location, int, int)
Sets the main light colors for a tile.
void SetTileMainLightColor(
location lTileLocation,
int nMainLight1Color,
int nMainLight2Color
);
Parameters
- lTileLocation
- This specifies the location of the tile. See Description it is not a typical location but an X, Y grid reference.
- nMainLight1Color
- The first main light color - TILE_MAIN_LIGHT_COLOR_*
- nMainLight2Color
- The second main light color - TILE_MAIN_LIGHT_COLOR_*
Description
Sets the main light colors on the tile located at lTileLocation. Main lights are the general lighting of an area - so the bits that are not torches that are sometimes present on tile walls (for these use SetTileSourceLightColor).
Note: lTileLocation is not a typical location, instead it is actually a grid reference. See the nwscript code for an example of how to translate an objects location into a grid reference. Only the Area, X and Y parts are used, not the Z or facing. X starts at 0 and ends at GetAreaSize(AREA_WIDTH) - 1, and Y starts at 0 and ends at GetAreaSize(AREA_HEIGHT) - 1.
Remarks
You must call RecomputeStaticLighting after calling this function in order for the changes to occur visually for the players. If there are no players in the area (such as when the module starts) then this is unnecessary, but its easy to call. You can call it after all the changes were set if you are doing multiple tiles at once.
You can retrieve the current main lights using GetTileMainLight1Color and GetTileMainLight2Color.
Version
Previous bugs for it not persisting in save games were fixed early on in EE's release. Various fixes for this issue were sorted in 8192.21.
Example
// This function will compute the location of an object into a grid reference location
location GetObjectTileGridReferenceLocation(object oObject)
{
vector vPos = GetPositionFromLocation(GetLocation(oObject));
vPos.x /= 10;
vPos.y /= 10;
location lLoc = Location(GetArea(oObject), vPos, 0.0);
return lLoc;
}
// Set the main light to red in the entering objects tile (use this OnEnter of a trigger)
void main()
{
object oEnterer = GetEnteringObject();
// Get X, Y grid location
location lTile = GetObjectTileGridReferenceLocation(oEnterer);
// Set main light to red
SetTileMainLightColor(lTile, TILE_MAIN_LIGHT_COLOR_RED, TILE_MAIN_LIGHT_COLOR_RED);
// Set source light to red
SetTileSourceLightColor(lTile, TILE_SOURCE_LIGHT_COLOR_PALE_RED, TILE_SOURCE_LIGHT_COLOR_PALE_RED);
// Recompute lighting
RecomputeStaticLighting(GetArea(oEnterer));
}
// This creates a valid location for use with SetTileMainLightColor/SetTileSourceLightColor
// at grid reference X, Y.
location GetTileGridReferenceLocation(object oArea, int x, int y)
{
vector vPos = Vector(x/1.0, y/1.0, 0.0);
location lLoc = Location(oArea, vPos, 0.0);
return lLoc;
}
// Set the entire area - OBJECT_SELF so this could be OnEnter of the area - to red
void main()
{
object oArea = OBJECT_SELF;
location lTile;
// Loop area size - this is a little odd due to how "tile grid references" work in NWN.
// Grid references are 0, 0 being the first tile.
// For an 8x5 area, it would be 7,4 being the last tile.
int x, y;
for(x = 0; x < GetAreaSize(AREA_WIDTH, oArea); x++)
{
for(y = 0; y < GetAreaSize(AREA_HEIGHT, oArea); y++)
{
lTile = GetTileGridReferenceLocation(oArea, x, y);
// Set main light to red
SetTileMainLightColor(lTile, TILE_MAIN_LIGHT_COLOR_RED, TILE_MAIN_LIGHT_COLOR_RED);
// Set source light to red
SetTileSourceLightColor(lTile, TILE_SOURCE_LIGHT_COLOR_PALE_RED, TILE_SOURCE_LIGHT_COLOR_PALE_RED);
}
}
// Recompute lighting only once all tiles have their lights set (don't do it for every tile!)
RecomputeStaticLighting(oArea);
}
See Also
| functions: | |
| constants: |
author: Tom Cassiotis