Looked over your functions script very well done.
I found some errors:
const int iTargetSet= 0;// had int iTargetclass= class_TYPE_FIGHTER
void classLock(object oDoor, object oPC, int iTargetclass=iTargetSet, int iDoLock = TRUE)
{
int iMatchingclass = FALSE;
int iIndex = 1;
while(iIndex
{
if(GetclassByPosition(iIndex, oPC) == iTargetclass )
{
iMatchingclass = TRUE;
break;
}
iIndex++;
}
if(iMatchingclass){
SetLocked(oDoor, iDoLock);
}else{
SetLocked(oDoor, !(iDoLock));}
}
I corrected and made it work with NWN1
Here is Edited compiled working version:
//::///////////////////////////////////////////////
//:: Name Service Locks
//:: FileName scr_do_locks
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
Here is a set of routines that deal with conditional locking/unlocking of
objects such as chests and sarcophogi. These were inspired by similar
routines written by _knightmare_ for use with doors. These routines are
designed to be part of an objects OnClick event handler. Because standard
doors (as opposed to placeable doors) don't have this event, these
routines are not designed for use with them. Anyway I hope someone has a
use for them.
*/
//:://////////////////////////////////////////////
//:: Created By: Tarot Redhand
//:: Created On: 18th September 2010
//:://////////////////////////////////////////////
//simple routine to lock/unlock lockable object oDoor depending on whether it is day or night in game terms
//parameter iInDayTime should be set to FALSE for nighttime
//parameter iDoLock should be set to FALSE for the oDoor object to be unlocked in the active period
//Note - this routine assumes (has the pre-condition) that the oDoor object is already closed
void DayNightLock(object oDoor, int iInDayTime = TRUE, int iDoLock = TRUE)
{
if(iInDayTime)
{
if(GetIsDay())
SetLocked(oDoor, iDoLock);
else
SetLocked(oDoor, !(iDoLock));
}
else
{
if(GetIsNight())
SetLocked(oDoor, iDoLock);
else
SetLocked(oDoor, !(iDoLock));
}
}
//----------------------------------------------------------------------------------------------------------------
//routine to lock/unlock lockable object oDoor between the hours (inclusive) of iStartHour and iEndHour
//if iDoLock is TRUE the object will Locked during the active period otherwise it will be unlocked
//TimeLock returns FALSE if erroneous data is passed to it in the parameters otherwise TRUE is returned
//NOTE this routine expects a minimum difference of 2 hours between iStartHour and iEndHour
//Possible side-effect - if the period described goes from before midnight to after, iEndHour will be
//increased by 24 upon exit from this routine
int TimeLock(object oDoor, int iStartHour, int iEndHour, int iDoLock = TRUE)
{
//check for bad input data
if((iStartHour 23)||(iEndHour > 23)||(iStartHour == iEndHour)||(abs(iEndHour - iStartHour)
{return FALSE;}
//get current game hour
int iHourNow = GetTimeHour();
//Through midnight? adjust certain parameters to correct for it then.
if(iStartHour > iEndHour)
{
iEndHour += 24;
if(iStartHour > iHourNow)
{iHourNow += 24;}
}
//test and lock/unlock as appropriate
if((iHourNow >= iStartHour)&&(iHourNow
{SetLocked(oDoor, iDoLock);
}else
{SetLocked(oDoor, !(iDoLock));}
return TRUE;
}
//----------------------------------------------------------------------------------------------------------------
//routine to lock/unlock lockable object oDoor depending on the alignment of the creature oPC
//the parameters iLawChaosValue and iGoodEvilValue are tested against the alignment of oPC to
//determine the action to take
//
//Note - this routine expects iLawChaosValue and iGoodEvilValue to contain values consistant with
//the ALIGNMENT_* constants and values outside this range are considered to be in error
//by doing it this way means that not only can specific alignments can be targetted (ie Lawful good)
//but also that groups of alignments can be specified (the default parameters are set for all good alignments).
//
//the parameter iDoLock determines whether the oDoor object is locked or unlocked when the
//alignment conditions are met for the oDoor object to be unlocked set iDoLock to FALSE
//this routine will terminate and return FALSE if any error conditions are detected otherwise
//TRUE will be returned on a successful completion
int AlignmentLock(object oDoor, object oPC, int iLawChaosValue = ALIGNMENT_ALL, int iGoodEvilValue = ALIGNMENT_GOOD, int iDoLock = TRUE)
{
//check parameters iLawChaosValue and iGoodEvilValue are in the valid range and if not exit returning FALSE
if((iLawChaosValue 5)||(iGoodEvilValue 5))
{ return FALSE; }
//get the actual law/chaos value of the creature oPC. If the oPC object does not have
//an alignment exit returning FALSE.
int iActualLawChaos = GetAlignmentLawChaos(oPC);
if(iActualLawChaos == -1)
{return FALSE; }
//get the actual good/evil value of the creature oPC. We do not have to test for an invalid object here
//because the previous test has already done so
int iActualGoodEvil = GetAlignmentGoodEvil(oPC);
//by setting iActivate to False here we only need to test for conditions that necessitate changing
//its value in the iLawChaosValue tests
int iActivate = FALSE;
if((iLawChaosValue == ALIGNMENT_ALL)||(iActualLawChaos == iLawChaosValue))
{iActivate = TRUE;}
//if iActivate == FALSE at this point, no further tests are necessary otherwise we only need to test for
//the 1 condition that will necessitate changing its value in the iGoodEvilValue tests
if(iActivate && (iGoodEvilValue != ALIGNMENT_ALL)&&(iActualGoodEvil != iGoodEvilValue))
{iActivate = FALSE;}
//finally if the conditions have been met we put the lock in the state specified otherwise
//we set the lock in the opposite state. We then exit the routine returning TRUE to indicate
//successful completion.
if(iActivate){
SetLocked(oDoor, iDoLock);
}else{
SetLocked(oDoor, !(iDoLock));}
return TRUE;
}
//----------------------------------------------------------------------------------------------------------------
//-------------------------------- class Type Constants ------------------------
//::
//:: Base classes
//::
//:: class_TYPE_BARBARIAN - 0 class_TYPE_PALADIN - 6
//:: class_TYPE_BARD - 1 class_TYPE_RANGER - 7
//:: class_TYPE_CLERIC - 2 class_TYPE_ROGUE - 8
//:: class_TYPE_DRUID - 3 class_TYPE_SORCERER - 9
//:: class_TYPE_FIGHTER - 4 class_TYPE_WIZARD - 10
//:: class_TYPE_MONK - 5
//::
//:: Prestige classes
//::
//:: class_TYPE_SHADOWDANCER - 27
//:: class_TYPE_HARPER - 28
//:: class_TYPE_ARCANE_ARCHER - 29
//:: class_TYPE_ASSASSIN - 30
//:: class_TYPE_BLACKGUARD - 31
//:: class_TYPE_DIVINECHAMPION - 32 (Champion of Torm)
//:: class_TYPE_WEAPON_MASTER - 33
//:: class_TYPE_PALE_MASTER - 34
//:: class_TYPE_SHIFTER - 35
//:: class_TYPE_DWARVENDEFENDER - 36
//:: class_TYPE_DRAGONDISCIPLE - 37
//::
//------------------------------------------------------------------------------
//routine to lock/unlock lockable object oDoor depending on the class of the creature oPC
//the parameter iTargetclass is tested against the class of oPC to determine the action to take
//
//Note - this routine expects iTargetclass to contain a value consistant with the class_TYPE_* constants
//
//the parameter iDoLock determines whether the oDoor object is locked or unlocked when the
//class conditions are met. for the oDoor object to be unlocked set iDoLock to FALSE
// had int iTargetclass= class_TYPE_FIGHTER
const int iTargetSet= 0;// use class numbers from above
void classLock(object oDoor, object oPC, int iTargetclass=iTargetSet, int iDoLock = TRUE)
{
int iMatchingclass = FALSE;
int iIndex = 1;
while(iIndex
{
if(GetclassByPosition(iIndex, oPC) == iTargetclass )
{
iMatchingclass = TRUE;
break;
}
iIndex++;
}
if(iMatchingclass){
SetLocked(oDoor, iDoLock);
}else{
SetLocked(oDoor, !(iDoLock));}
}
//----------------------------------------------------------------------------------------------------------------
void main()
{
object oPC = GetClickingObject();
if(!(GetIsPC(oPC)))
{ return;}
//put call(s) to selected routines here
}
Will work on a include version, But it seems better especialy with the class issue to have that function at the top of your script so the const setting can be done according to unique object.
For those who are working on nwn2 use first version not the one I've posted
Modifié par Greyfort, 20 décembre 2010 - 02:06 .