OnEnter functionality

I’m still trying to get back into the swing of things but hitting a wall. I turned to the script generator but it just doesn’t seem to be working. I want to check for an item on the PC, if they don’t have it then a random chance of teleporting them to a pocket dimension. This is for an on enter script, what am I missing?

string sSayThis;
int iTalkVolume = TALKVOLUME_TALK;
int iTalkFlag = 0;


void ClearAndJumpToObject(object oDestination);
void ClearAndJumpToObject(object oDestination)
{
ClearAllActions();
JumpToObject(oDestination);
}


void main()
{
effect eVFX;
object oTarget;

// Get the creature who triggered this event.
object oPC = GetEnteringObject();

// Only fire for (real) PCs.
if ( !GetIsPC(oPC) || GetIsDMPossessed(oPC) )
return;

// Abort if the PC has the item "IT_Pocket_Token".
if ( GetItemPossessedBy(oPC, "IT_Pocket_Token") != OBJECT_INVALID )
return;

// Decide what to do based on a die roll.
switch ( d100() )
{
case 2:
{
// Send a message to the player's chat window.
SendMessageToPC(oPC, "You suddenly feel very strange...");

// Find the location to which to teleport.
oTarget = GetWaypointByTag("WP_Pocket_Dimension");

// Teleport the PC.
eVFX = EffectVisualEffect(VFX_IMP_UNSUMMON);
DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oPC));
DelayCommand(4.0, AssignCommand(oPC, ClearAndJumpToObject(oTarget)));
}

}
} 

The problem is with your switch statement.

Try this instead:

void ClearAndJumpToObject(object oDestination);

void main()
{
    object oPC=GetEnteringObject();
    if (!GetIsPC(oPC)||GetIsDMPossessed(oPC)) return;

    //No reason to declare these as global variables.
    string sSayThis;
    int iTalkVolume = TALKVOLUME_TALK;
    int iTalkFlag = 0;



    // Abort if the PC has the item "IT_Pocket_Token".
    if ( GetItemPossessedBy(oPC, "IT_Pocket_Token") != OBJECT_INVALID )
    return;

    // Decide what to do based on a die roll.
    switch ( d100() )
    {
        case 1:
            break;
        default:
            // Send a message to the player's chat window.
            SendMessageToPC(oPC, "You suddenly feel very strange...");

            // Find the location to which to teleport.
            object oTarget = GetWaypointByTag("WP_Pocket_Dimension");

            // Teleport the PC.
            effect eVFX = EffectVisualEffect(VFX_IMP_UNSUMMON);
            DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oPC));
            DelayCommand(4.0, AssignCommand(oPC, ClearAndJumpToObject(oTarget)));
    }
}

void ClearAndJumpToObject(object oDestination)
{
    ClearAllActions();
    JumpToObject(oDestination);
}

You could also use an if statement:

    if (d100()>1)
    {
         // Send a message to the player's chat window.
         SendMessageToPC(oPC, "You suddenly feel very strange...");

         // Find the location to which to teleport.
         object oTarget = GetWaypointByTag("WP_Pocket_Dimension");

         // Teleport the PC.
         effect eVFX = EffectVisualEffect(VFX_IMP_UNSUMMON);
         DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oPC));
         DelayCommand(4.0, AssignCommand(oPC, ClearAndJumpToObject(oTarget)));
    }

I assume you’re using a switch because at some point you might want to add extra functionality (e.g. jumps to different locations). This might help: https://www.tutorialspoint.com/cprogramming/switch_statement_in_c.htm
if you want to use switches in the future.

Aside from indentation, that looks reasonable. The switch is fine. But you do have to roll a 2 and only a 2 on d100 to teleport. Chances are you have not ever done that. That’s a 1% chance. The code wendigo211 posted will teleport with a 99% chance, which is more or less automatic and not the same as what you started with.

Thank you both for the quick reply, I had posted on the beamdog forum last night but have yet to get a response, I will post here from now on.

Yes I want it to be a very low chance of initiating the very 1st time someone is sent to the pocket dimension, once there they will get an item and should not be automatically sent there again as long as they have the item. I did add 20 or so more cases to the original script that just spoke a string so I would know if it was indeed firing and after 200 plus enters to areas I figured it wasn’t working. I’ll keep at it.

1% is a pretty low chance. I had assumed you were trying to use fall through to implement the code I had written. Anyway replace the d100() in your code with 2 for your first test and/or use the default functionality to print your debug message.

This is the Witts End syndrome (named after a location in the classic Colossal Adventure that had a 1% chance of escape). Well, almost - the version I played actually had zero chance because the author didn’t spot that Random(100) is never 100. @Wendigo211’s suggestion should do it.

I will give that a go. Thanks all.

Proleric its kind of a Faust makes a deal with the devil scenario. The “Gentleman” in the pocket dimension gives buffs to the player and also a token to return for more buffs when they run out. All along the player is being sucked into a binding deal with the devil as once you reach a certain number of buffs he calls you on what you owe and sends you on an interesting quest.