My goal is to make a script that can check when a PC speaks a specific phrase or password to gain entry to a hidden area. I’m not very good at scripting, but my research suggests I should be using the OnPlayerChat event, is that correct?
My process was to set a trigger that would set a local int on the player upon entering the trigger, signaling that the player was in the right spot to speak the password. If the player speaks the password while the int is equal to 1, teleport the player to the waypoint. If the int is equal to 0 (meaning the player is not in the correct area), do nothing.]
Since I am not a coder I tried to use the script generator to build the basic structure and then copy/paste in the right functions, but the script does not work so obviously I haven’t set it up right. This script also needs to cover multiple different passwords for different areas throughout the module since the only way I know how to perform such a puzzle is with the single OnPlayerChat event, so I tried to do an else if statement for a second puzzle to test with.
// Put this script OnPlayerChat event under module properties.
// Clears all actions and jumps the caller to the provided object.
// (Useful when this needs to be delayed.)
void ClearAndJumpToObject(object oDestination);
void ClearAndJumpToObject(object oDestination)
{
ClearAllActions();
JumpToObject(oDestination);
}
void main()
{
int nHench;
object oHench;
object oTarget;
effect eVFX;
object oPC = GetPCChatSpeaker();
if(!GetIsPC(oPC))
{ return; }
// Brotherhood Puzzle
if (GetPCChatMessage() != "My Blood for my Brothers" )
return;
if ( GetLocalInt(oPC, "bhpuzzle") == 1 )
{
// Apply a visual effect.
eVFX = EffectVisualEffect(VFX_FNF_IMPLOSION);
oTarget = GetPCChatSpeaker();
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oTarget);
// Find the location to which to teleport.
oTarget = GetWaypointByTag("wp_bhpuzzle");
// Teleport the PC.
DelayCommand(1.0, AssignCommand(oPC, ClearAndJumpToObject(oTarget)));
// Also teleport associates.
oHench = GetAssociate(ASSOCIATE_TYPE_ANIMALCOMPANION, oPC);
DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
oHench = GetAssociate(ASSOCIATE_TYPE_DOMINATED, oPC);
DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
oHench = GetAssociate(ASSOCIATE_TYPE_FAMILIAR, oPC);
DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
oHench = GetAssociate(ASSOCIATE_TYPE_SUMMONED, oPC);
DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
// Support for multiple henchmen (includes horses).
nHench = 1;
oHench = GetHenchman(oPC, 1);
while ( oHench != OBJECT_INVALID )
{
DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
// Next henchman.
oHench = GetHenchman(oPC, ++nHench);
}
}
//Secret Tunnel Puzzle
else if (GetPCChatMessage() != "Truth" )
return;
// If the local int is exactly 1.
if ( GetLocalInt(oPC, "sectunpuzzle") == 1 )
{
// Apply a visual effect.
eVFX = EffectVisualEffect(VFX_FNF_IMPLOSION);
oTarget = GetPCChatSpeaker();
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oTarget);
// Find the location to which to teleport.
oTarget = GetWaypointByTag("wp_sectunstat");
// Teleport the PC.
DelayCommand(1.0, AssignCommand(oPC, ClearAndJumpToObject(oTarget)));
// Also teleport associates.
oHench = GetAssociate(ASSOCIATE_TYPE_ANIMALCOMPANION, oPC);
DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
oHench = GetAssociate(ASSOCIATE_TYPE_DOMINATED, oPC);
DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
oHench = GetAssociate(ASSOCIATE_TYPE_FAMILIAR, oPC);
DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
oHench = GetAssociate(ASSOCIATE_TYPE_SUMMONED, oPC);
DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
// Support for multiple henchmen (includes horses).
nHench = 1;
oHench = GetHenchman(oPC, 1);
while ( oHench != OBJECT_INVALID )
{
DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
// Next henchman.
oHench = GetHenchman(oPC, ++nHench);
}
}
}