Hey everyone,
Here's a simple function that solves a problem I was having with
locations of creatures/items vs. locations of tiles.
I need to use SetTileMainLightColor() to change the lighting of the tile
containing a creature's spawn point when the creature gets killed. I was
trying to pass the location of the spawn point as the first argument to
SetTileMainLight(), but that doesn't work. I eventually figured out that
the location vector of a creature/item is not the same thing as the
location vector of a tile. The former has units of meters, and the
latter is just the tile's position in the grid.
This function will return a tile-location for the tile which contains
the creature/item at the item-location given as an argument (you can
either paste it into your script, or use it in an include file):
NWScript: location GetTileLocation( location loc ) {
vector vec = GetPositionFromLocation( loc );
float fNewX = IntToFloat( FloatToInt( vec.x/10.0 ) );
float fNewY = IntToFloat( FloatToInt( vec.y/10.0 ) );
float fNewZ = IntToFloat( FloatToInt( vec.z/10.0 ) );
vector vNew = Vector( fNewX, fNewY, fNewZ );
location lNew = Location( GetAreaFromLocation( loc ),
vNew, GetFacingFromLocation( loc ) );
return lNew;
}
And, just for laughs, here are the lines I added to the creature's
OnDeath script to change the lighting of its spawn point (note use of
above function). For the spawn
location, I added 'SetLocalLocation( OBJECT_SELF, "lmc_SkelInitLocation",
GetLocation( OBJECT_SELF ) )' to the creature's OnSpawn script. You
could also put a waypoint at the location, and just do
'GetLocation( GetObjectByTag( "MY_WAYPOINT" ) )' here.
NWScript:
object oKiller = GetLastKiller();
location lSpawn = GetLocalLocation(
OBJECT_SELF, "lmc_SkelInitLocation" );
location lTile = GetTileLocation( lSpawn );
if ( GetIsPC( oKiller ) ) {
SetTileMainLightColor( lTile,
TILE_MAIN_LIGHT_COLOR_BLACK,
TILE_MAIN_LIGHT_COLOR_BRIGHT_WHITE );
RecomputeStaticLighting( GetArea( OBJECT_SELF ) );
}
cheers,
LMCBoy
|