DMH-Online

Dungeon Masters Helper · Est. 2005

Creatures Scripts

NWN Script: change_light_spawn_pt_on_death.htm

Author Sticky: Post Working Scripts Here
LMCBoy Posted: Tuesday, 25 June 01:45AM
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 ) {
    //:Determine the tile-location of the tile 
    //:containing the item-location loc
    //:by LMCBoy <jharris@30doradus.org>
    //Divide by 10 and take the integer to get the 
    //tile coordinates
    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 ) );
    //Construct the new tile-location
    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:
//Add these lines to OnDeath script to change
    //lighting at spawn point 
    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

⌂ All Scripts ← PreviousNext → 👁 Category List

All Creatures Scripts

📄 apply_spell_effect 📄 aurak_draconian 📄 baaz_draconian 📄 boss_spawner 📄 change_light_spawn_pt_on_death 📄 clone_mob 📄 collect_loot 📄 create_unique_objectIDs 📄 creature_proc 📄 explode_ondeath 📄 explode_ondeath_002 📄 explode_ondeath_003 📄 exploding_chickens 📄 fire_death 📄 inverse_mob 📄 iron_statue 📄 lich 📄 lootable_corpse 📄 lootable_corpse_002 📄 lootable_corpse_002a 📄 lootable_corpse_oo2 📄 mob_respawn 📄 mob_respawn_002 📄 multi_creature_spawn 📄 night_time 📄 random_death_effect 📄 random_drops 📄 random_drops_002 📄 random_drops_003 📄 random_enc_onrest 📄 random_hps 📄 sivac_draconian 📄 spawn 📄 spawn_on_hearbeat 📄 summon_last_hostile 📄 summon_mob 📄 trolls 📄 trolls_002 📄 vampire_coffin 📄 werewolf