Recent changes Random page
GAMING
Gaming
 
WoWWiki
Halopedia
FFXIclopedia
Age of Conan
Warhammer Online
Grand Theft Wiki
See more...

Osrs pnp light inc

From NWNWiki

Jump to: navigation, search

osrs_pnp_light_inc is an OSRS script for the torch feature.

// file: 	osrs_pnp_light_inc.nss
// Purpose: 	Provide definitions for variables and functions used in 
//		osrs_pnp_light_* set of scripts. 
//		osrs_pnp_light_oml: OnModuleLoad
//		osrs_pnp_light_omh: OnModuleHeartbeat



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

// The var name used to write onto the object how long it has been burning. 
constant string csOSRSBurnTime = "osrs_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 osrsuses 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 csOSRSTorch = "osrs_torch"; 
// the custom osrs Torch has the correct burn radius and color.
stilltodo: must be constructed and placed as an import file 

// OSRS lantern template name 
constant string csOSRSLantern = "osrs_lantern";



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

// the message that the PC receives when his lantern is out of fuel
constant string csOSRSLanternEmpty = "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 OSRS torch is allowed to burn
constant int ciOSRSTorchBurnLimit = 12 * ciNumRoundsPerHour;

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

// the length of time that a OSRS Lantern is allowed to burn
constant int ciOSRSLanternBurnLimit = ciOSRSTorchBurnLimit * 4; 

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




// Perform PNP lighting check in the OnModuleHeartbeat script
void osrs_pnp_lighting();
void osrs_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 = ciOSRSTorchBurnLimit;
            }                    
            
            // is this a Wiki Lantern?
            else if (sTag == csOSRSLantern)
            {
                iMaxNumRoundsCanBurn = ciOSRSLanternBurnLimit;
            }
            
            // 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, csOSRSBurnTime); 

                // 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 == csOSRSTorch))
                    {
                        // 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, csOSRSTorchBurnedOut);

                    }
                    
                    // unequip Lanterns 
                    else if ((sTag == csOSRSLantern) || (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, csOSRSLanternEmpty);

                    }
                } // 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, csOSRSBurnTime, 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

}


Rate this article:
Share this article: