//////////////////////////////////////////////////////////////////////////////// // tr_en_secretd - OnEnter Secret Door Trigger // By Deva B. Winblood. December 11th, 2008 //////////////////////////////////////////////////////////////////////////////// #include "prc_inc_racial" #include "hos_saveload_h" void fnDetectionRoutine(object oPC,object oDetector,object oDest,object oRet,object oTrigger) { // PURPOSE: See if detected string sPID=fnSLGetAPID(oPC); int bDetected=FALSE; object oDoor1=GetLocalObject(oRet,"oDoor"); object oDoor2=GetLocalObject(oDest,"oDoor"); string sRes=GetLocalString(oTrigger,"sDoorTypeResRef"); string sDestRes=GetLocalString(oTrigger,"sDestTypeResRef"); if (GetStringLength(sRes)<1) sRes="sd_wood"; if (GetStringLength(sDestRes)<1) sDestRes=sRes; bDetected=GetLocalInt(oDest,"b"+sPID); if (!bDetected) bDetected=GetLocalInt(oRet,"b"+sPID); if (GetIsObjectValid(oDoor1)) bDetected=TRUE; // door is already revealed if (!bDetected) { // check for detection int bConcealed=GetLocalInt(oTrigger,"bConcealed"); int bStonework=GetLocalInt(oTrigger,"bStonework"); int nDistanceMod=GetLocalInt(oTrigger,"nDistanceMod"); int nModifier=GetLocalInt(oTrigger,"nModifier"); string sDumb=GetLocalString(oTrigger,"sDumb"); string sIntelligent=GetLocalString(oTrigger,"sIntelligent"); int nDC=19; int nRace=MyPRCGetRacialType(oDetector); int nRoll; if (bConcealed) { // concealed door if (nRace==RACIAL_TYPE_DWARF) { // dwarf if (bStonework) { // stonework nDC=nDC-5; } // stonework nDC=nDC-2; } // dwarf else if (nRace==RACIAL_TYPE_ELF) { // elf nDC=nDC-4; } // elf } // concealed door else { // secret door if (nRace==RACIAL_TYPE_DWARF) { // dwarf if (bStonework) { // stonework nDC=nDC-2; } // stonework nDC=nDC-1; } // dwarf else if (nRace==RACIAL_TYPE_ELF) { // elf nDC=nDC-2; } // elf } // secret door if (GetActionMode(oDetector,ACTION_MODE_DETECT)) { // searching nRoll=d20()+(GetSkillRank(SKILL_SPOT,oDetector)/2)+GetSkillRank(SKILL_SEARCH,oDetector); } // searching else { // normal nRoll=d20()+(GetSkillRank(SKILL_SPOT,oDetector)/2); } // normal nDC=nDC+nModifier; if (nDistanceMod>0) { // distance mod exists if (nModifier<1) nModifier=2; if (FloatToInt(GetDistanceBetween(oDetector,oRet))>=nDistanceMod) nDC=nDC+nModifier; // double modifier } // distance mod exists if (nRoll>=nDC) { // detected bDetected=TRUE; if (oPC==oDetector) FloatingTextStringOnCreature("** You detected a secret door. **",oPC,FALSE); else { // speak to master string sMsg; if (GetStringLength(sDumb)<1) sDumb="Here"; if (GetStringLength(sIntelligent)<1) sIntelligent="There is some sort of door here."; if (GetAbilityScore(oDetector,ABILITY_INTELLIGENCE)<9) sMsg=sDumb; else { sMsg=sIntelligent; } AssignCommand(oDetector,SpeakString(sMsg)); } // speak to master } // detected } // check for detection if (bDetected) { // set flags - and spawn doors if need be SetLocalInt(oRet,"b"+sPID,TRUE); SetLocalInt(oDest,"b"+sPID,TRUE); if (!GetIsObjectValid(oDoor1)) { // create door1 oDoor1=CreateObject(OBJECT_TYPE_PLACEABLE,sRes,GetLocation(oRet)); if (!GetIsObjectValid(oDoor1)) SendMessageToPC(oPC,"ERROR: tr_en_secretd - failed to create '"+sRes+"' door."); } // create door1 if (!GetIsObjectValid(oDoor2)) { // create door2 oDoor2=CreateObject(OBJECT_TYPE_PLACEABLE,sDestRes,GetLocation(oDest)); if (!GetIsObjectValid(oDoor2)) SendMessageToPC(oPC,"ERROR: tr_en_secretd - failed to create '"+sRes+"' door."); } // create door2 SetLocalObject(oDoor1,"oDest",oDoor2); SetLocalObject(oDoor2,"oDest",oDoor1); SetLocalObject(oRet,"oDoor",oDoor1); SetLocalObject(oDest,"oDoor",oDoor2); } // set flags - and spawn doors if need be if (!bDetected&&GetLocalInt(oPC,"bDetectingSD")) { // keep checking DelayCommand(6.0,fnDetectionRoutine(oPC,oDetector,oDest,oRet,oTrigger)); } // keep checking } // fnDetectionRoutine() void main() { object oTrigger=OBJECT_SELF; object oPC=GetEnteringObject(); string sReturnTag=GetLocalString(oTrigger,"sReturnTag"); string sDestTag=GetLocalString(oTrigger,"sDestinationTag"); object oRet=GetWaypointByTag(sReturnTag); object oDest=GetWaypointByTag(sDestTag); int bDetecting=GetLocalInt(oPC,"bDetectingSD"); if (!GetIsObjectValid(oRet)||!GetIsObjectValid(oDest)) { // error FloatingTextStringOnCreature("** ERROR: tr_en_secretd - Secret door script failed due to missing destination or return tags. **",oPC,FALSE); return; } // error if (GetIsPC(oPC)) { // PC if (!bDetecting) { // begin detection SetLocalInt(oPC,"bDetectingSD",TRUE); AssignCommand(oPC,fnDetectionRoutine(oPC,oPC,oDest,oRet,oTrigger)); } // begin detection } // PC else { // NPC object oMaster=GetMaster(oPC); if (GetIsPC(oMaster)) { // master exists if (!bDetecting) { // begin detection SetLocalInt(oPC,"bDetectingSD",TRUE); AssignCommand(oPC,fnDetectionRoutine(oMaster,oPC,oDest,oRet,oTrigger)); } // begin detection } // master exists } // NPC }