int AlignmentLock(object oDoor, object oPC, int iLawChaosValue = ALIGNMENT_ALL, int iGoodEvilValue = ALIGNMENT_GOOD, int iDoLock = 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
{
//check parameters iLawChaosValue and iGoodEvilValue are in the valid range and if not exit returning FALSE
if((iLawChaosValue < 0)||(iLawChaosValue > 5)||(iGoodEvilValue < 0)||(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;
[/list] }
//----------------------------------------------------------------------------------------------------------------
TR
Modifié par Tarot Redhand, 17 avril 2013 - 01:29 .