Script to check for certain Shifter Forms

Hi, I’m new to scripting and am trying to create a script that checks if a Shifter is in one of several forms and if so fly them to a waypoint. If they are not the proper form it should either do nothing or give them a message that they will need some way to cross the gap. Thanks for any suggestions or help with this. I couldn’t figure out how else to identify the shifted forms than by their appearance. Here’s what I came up with that doesn’t do it:

void main()
{
object oTarget;

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

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

// If the Shifter is a certain Shift type.

if ( GetAppearanceType(oPC) == 419 || 73 || 366 || 468 || 156 || 376 || 377 || 378 || 379 || 380 || 41 || 42 || 43 || 44 || 45 || 46 || 47 || 48 || 49 || 50 )
{

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

    effect eFly = EffectDisappearAppear(GetLocation(oTarget));
    effect eVis = EffectVisualEffect(VFX_IMP_PULSE_WIND);
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oPC);
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eFly, oPC, 10.0);
    SendMessageToPC(oPC, "You barely fly across the gap. You will need to practice this more");
}
else
{
    // Send a message to the player's chat window.
    SendMessageToPC(oPC, "You will need to find some way across this gap");

}
}

I have not looked into if GetAppearanceType() returns the right value here. But assuming so then you need to fix your if statement a bit.

This will be true all the time since 73 is not 0 and 366 is not 0 etc. Any non-zero value is considered true. In spoken language you can say “if appearance is 419 or 73 or 366…” but in code you need to be more explicit: “if appearance is 419 or appearance is 73 or appearance is 366 …”.

Since you’d need the value over and over again put it in a variable instead of calling GetAppearanceType() over and over.

int iApp = GetAppearanceType(oPC);
if (iApp == 419 || iApp ==  73 || ...) {
...

You could also do it with a switch statement which might be a little less typing. But either way you need to check each number explicitly. Actually there are some ranges so you could get fancy with the if using >= and <= and save some characters that way too.

2 Likes

Thank you very much!! This works exactly as needed now.

You could also write

if (FindSubString("419|73|366|468|156|376|377|378|379|380|41|42|43|44|45|46|47|48|49|50|", IntToString(GetAppearanceType(oPC))+"|")!=-1)
{
   ...
}

Maybe execution is not faster but it’s much less code.

Thanks for the suggested fix. Now that I have gotten that to work I’m thinking of making it more complex and would love feedback on which would be better to try to add in a listening component instead of just identifying if the shifter shape is right and doing the jump.

Would I be able to create a listening event if they were in the right shape on the trigger point and if they said “Fly” it would do the action of flying them to the waypoint OR should I have the trigger create an invisible listener only if they are the proper shape and then they could say “Fly” to fly them to the waypoint?

These days, you don’t really need a listener - the OnPlayerChat module event is arguably easier.

Can I use the OnPlayerChat module event for a specific part of an area only? i.e. If I only want to allow the command to be used next to a cliffside.

Your OnPlayerChat script needs to check the context. For example, a flag set on entering a trigger, and cleared on exit. When the context is not right, simply echo the chat and exit.