NWNWiki
Advertisement
NWNWiki
3,718
pages

Template:NRS wanted

Torch Feature

A set of scripts, and customized items, which together allow torches and lanterns to function in a more realistic manner and in accordance with Dungeons and Dragons 3.5 edition rules.

  • Lanterns burn more brightly than torches
  • Lanterns burn longer than torches
  • Torches expend themselves (i.e. need to get more torches or craft them when they burn out)
  • Lanterns expend fuel and require refueling
  • Torches can be crafted

wik_pnp_light_inc

// file: 	wik_pnp_light_inc.nss
// Purpose: 	Provide definitions for variables and functions used in 
//		wik_pnp_light_* set of scripts. 
//		wik_pnp_light_oml: OnModuleLoad
//		wik_pnp_light_omh: OnModuleHeartbeat



// The var name used to toggle realistic torches.  By default, this 
// flag is off.  
constant string csRealTorches = "wik_realisticTorches";

// The var name used to write onto the object how long it has been burning. 
constant string csWikBurnTime = "wik_burnTime"; 



// bioware torch template name 
constant string csBWTorch= "NW_IT_TORCH001";
// this is not quite realistic because the standard bioware torch 
// emits light in too large a radius.  Lanterns should be this bright.  
// Instead Wiki uses another item that has the appropriate burn 
// brightness. To compensate if Bioware torches are being used, we 
// make them burn half as long as a normal torch. 

// Bioware lantern object template name 
constant string csBWLantern = ""; 
stilltodo!

// Wiki torch template name 
constant string csWikTorch = "wik_torch"; 
// the custom Wiki Torch has the correct burn radius and color.
stilltodo: must be constructed and placed as an import file 

// Wiki lantern template name 
constant string csWikLantern = "wik_lantern";



// the message that the PC receives when his torch burns out.
constant string csWikTorchBurnedOut = "Your lighting device has burned out."; 

// the message that the PC receives when his lantern is out of fuel
constant string csWikLanternEmpty = "Your lantern is out of fuel and you have unequipped it.";



// a constant used to determine the number of Rounds in an hour
constant int ciNumRoundsPerHour = FloatToInt(HoursToSeconds(1) / 6.0f;


 
// the length of time in rounds that a Wiki torch is allowed to burn
constant int ciWikTorchBurnLimit = 12 * ciNumRoundsPerHour;

// the length of time that a Bioware torch is allowed to burn 
constant int ciBWTorchBurnLimit=FloatToInt(ciWikTorchBurnLimit/2);
// Wiki compensates for the Bioware torch being twice as bright by 
// allowing it to only burn half as long as a Wiki torch.

// the length of time that a Wiki Lantern is allowed to burn
constant int ciWikLanternBurnLimit = ciWikTorchBurnLimit * 4; 

// the length of time that a Bioware Lantern is allowed to burn
constant int ciBWLanternBurnLimit = ciWikLanternBurnLimit; 
stilltodo: make sure this var is referenced somewhere in the files




// Perform PNP lighting check in the OnModuleHeartbeat script
void wik_pnp_lighting();
void wik_pnp_lighting()
{    
    // Is this module using the realistic torch and lantern burning system?
    if (!GetLocalInt(oMod, "BURNTORCH"))
    {
     	// this module does not do the burning torch thing.
     	// kick out of this script
        return;
    } 

    // Walk through all of the PC's in the module using GetFirst/GetNext().
    object oPlayer = GetFirstPC();

    // We are at the end of the iteration when GetNextPC() returns an Invalid object 
    while (GetIsObjectValid(oPlayer))
    {
        // get the item in the player's left hand; a player cannot hold 
        // a torch in his right hand in NWN 
        object oLeftHandItem = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPlayer);

        // if this PC is holding an item in his left hand ...
        if (GetIsObjectValid(oLeftHandItem))
        {
            // what's it's tag?
            string sTag = GetTag(oLeftHandItem);

            // Is the item held in the left hand one of the lighting devices that we are interested in?

	    // Identify the burn limit time for the unknown device in 
	    // the hand by it's tag.  If the Burn Limit is still 0 
	    // after all the tag checks, then it also 
	    // is not a lighting device and we can kick out. 
            int iMaxNumRoundsCanBurn = 0;
            
            // is this a Bioware Torch?
            if (sTag == csBWTorch)
            {
                iMaxNumRoundsCanBurn = ciBWTorchBurnLimit; 
            }                   
            
            // is this a Wiki Torch?
            else if (sTag == csWikTorch)
            {
                iMaxNumRoundsCanBurn = ciWikTorchBurnLimit;
            }                    
            
            // is this a Wiki Lantern?
            else if (sTag == csWikLantern)
            {
                iMaxNumRoundsCanBurn = ciWikLanternBurnLimit;
            }
            
            // is this a Bioware lantern?
            else if (sTag == csBWLantern)
            {
                iMaxNumRoundsCanBurn = ciBWLanternBurnLimit;
            }

	    // if a legal burn limit time has been determined...
            // The default value must be a determined number. Ensure 
            // that burn limit is not zero.  If an upper limit is 
            // determined for this item, then a burn limit has been 
            // determined and the module must meet those obligations.
            if (iMaxNumRoundsCanBurn > 0)
            {
                // Determine the maximum number of rounds that this light 
                // device has left in it's life.  This number is stored 
                // on the Item.  
                iNumRoundsLeftToBurn = GetLocalInt(oLeftHandItem, csWikBurnTime); 

                // If it is not stored on the Item, then 
                // this is a fresh new light device and we set the value 
                // on it. This number indicates how many more rounds 
                // the device is allowed to burn.
 		if (iNumRoundsLeftToBurn == 0)
 		{
 		    iNumRoundsLeftToBurn = iMaxNumRoundsCanBurn;
 		    // no need to write it back to the device just yet, 
 		    // we still need to account for this round of it's life.
 		}
 		
                // this is a new round of burning 
 		// this Lighting item has burned this round. Deduct one round
 		iNumRoundsLeftToBurn = iNumRoundsLeftToBurn - 1;
 		    
                // Check to see if the lighting item has exceeded it's life.
                // then the lighting device has burned out
                if (nBurnCount >= iMaxNumRoundsCanBurn)
                {
                    // destroy torches 
                    if ((sTag == csBWTorch) || (sTag == csWikTorch))
                    {
                        // we have to destroy this object because it 
                        // will always burn while being held until we 
                        // manually stop it from burning.
                        DestroyObject(oLeftHandItem); 
                        // Stilltodo: replace torch with burned out stick?

                        // tell the player why his torch burned out
                        SendMessageToPC(oPlayer, csWikTorchBurnedOut);

                    }
                    
                    // unequip Lanterns 
                    else if ((sTag == csWikLantern) || (sTag == csBWLantern))
                    {
                    	// make the player unequip the lantern
                        AssignCommand(oPlayer, ActionUnequipItem(oLeftHandItem));
                        // the burn length value is still stored on 
                        // the item, so the next time it is equipped, 
                        // it will become unequipped on the next heartbeat
			// stilltodo: place a stick in the player's hand? he might be using his torch as a club against zombies 
			
			// tell the player that his lantern is out of fuel
                        SendMessageToPC(oPlayer, csWikLanternEmpty);

                    }
                } // if burn limit exceeded 
                else // we have not burned past the item's limit
                {
                    // store the updated burn count upon the lighting device
                    SetLocalInt(oLeftHandItem, csWikBurnTime, iNumRoundsLeftToBurn);
                    // next heartbeat we will do it all over again 
                    
                }
                
            } // if item is a lighting device 
            
        } // if item held in hand is a valid item

        // Get next player.
        oPlayer = GetNextPC();

    } // while next player to process is a valid object

}



wik_pnp_light_oml

// file: 	wik_pnp_light_oml.nss
// purpose: 	Establish whether or not this module uses Wiki Realistic 
//		Torches.  By default this variable is off, so you must 
//		specifically ExecuteScript("wik_pnp_light_oml") from 
//		your OnModuleLoad event in order to call this script 
//		which will turn on the lighting system. 

#include "wik_pnp_light_inc"

// Uncomment the following line in order to turn Realistic Torches on. 
main()
{
    // enable Wiki PNP D&D torch and lantern life span usage
    SetLocalInt(oMod, csRealTorches, 1); // see wik_pnp_light_omh for more info
    
}



wik_pnp_light_omh

// file: 	wik_pnp_light_omh.nss
// purpose: 	Simulate Paper and Pencil D&D torch life and burn times.  
// Usage: 	Call this script via ExecuteScript() from within your 
//		module.OnHeartbeat event.  There is a commensurate script 
//		wik_pnp_lighting_oml.nss that needs to be called within 
//		your OnModuleLoad event.



#include "wik_pnp_light_inc"
// defined values and methods for PNP realistic lighting


//::////////////////////////////////////////////////////////////////////////////
// Torches and lanterns have limited life.  Check the progress of these burning objects.
void main()
{
    // wiki lighting system activity
    wik_pnp_lighting();
}



Advertisement