Help with custom script, please?

Howdy all,
A vital component of my swimming system is the trigger drawn around riverbank/shore/water tiles that have been altered to make them walkable. While the OnEnter script of this trigger (given below) works perfectly for PCs, it does not fire when a henchperson enters it.
I thought (wrongly) that the GetIsPC function included all types of associates, but it seems that is not so.
Nor is there a GetIsHenchman function to help me out as far as I can see!

If anyone can suggest a way of including henchmen in this script, I would be very grateful indeed.

////////////////////////////////////////////////////////////////////////////////
//
// swim_trig.nss
//
// This is the OnEnter script for the trigger allowing PCs to swim in areas of
// River or Walkable Water terrain.
//
// It changes the PC's phenotype to the Crawl/Swim phenotype, removes a torch
// or shield (if carried) and applies a 65% speed decrease to movement.
//
// If the PC is wearing armour of AC3 or above, it is unequipped automatically
// and an Undroppable item with the Tag "pc_clothing" is equipped in its stead.
// N.B: These items created in the PC's inventory at generation!!
//
// Also, a message is sent to the entering PC informing him he is in swim mode.
//
// Note that this script fires whenever a PC enters the trigger, which is fine
// when entering the water conventionally, but NOT when transitioning BACK from
// another area such as a ship's cabin or hold to the deck of the ship....
//
// As soon as the transition completes, the PC re-enters the swimming trigger
// and adopts the crawl animation and the associated movement penalty!!
//
// As a workaround, a SECOND trigger is used, drawn outside the doorway leading
// to the other area. The OnEnter script of this second trigger resets the PC's
// phenotype to normal and does away with the movement penalty.
//
// The "Area Trigger - Swimming" and the Transition Triggers are all found in:
// Triggers -> Custom -> Special -> Custom 2.
//
////////////////////////////////////////////////////////////////////////////////

void main()
{
    object oPC = GetEnteringObject();
    // Object must be a PC/Associate/Henchman/DM-Possessed creature to swim.
    if (!GetIsPC (oPC)) {return;}
    // Object must only have the "Normal" Phenotype to swim.
    if (GetPhenoType (oPC) >0) {return;}

    // Unequips Torches or Shields.
    object oTorch = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC);
    int iIsTorch = GetBaseItemType(oTorch);
    if(iIsTorch = BASE_ITEM_TORCH || (iIsTorch = BASE_ITEM_SMALLSHIELD || (iIsTorch = BASE_ITEM_LARGESHIELD || (iIsTorch = BASE_ITEM_TOWERSHIELD))))
    {
    AssignCommand(oPC, ActionUnequipItem(oTorch));
    }

    // Unequips Armour of AC 3/4/5.
    object oItem = GetItemInSlot(INVENTORY_SLOT_CHEST, oPC);
    int nAC = GetItemACValue(oItem);
    if(nAC >= 3)
    {
    AssignCommand(oPC, ActionUnequipItem(oItem));
    // Define the replacement clothing.
    object oArmor = GetItemPossessedBy(oPC, "pc_clothing");
    // Now equip the replacement clothing.
    DelayCommand(0.5, AssignCommand(oPC, ActionEquipItem(oArmor, INVENTORY_SLOT_CHEST)));
    }

    // Set the object's phenotype to "Crawl/Swim"
    SetPhenoType(20,oPC);

    // Define the Movement Speed effect.
    effect eSlow=ExtraordinaryEffect(EffectMovementSpeedDecrease(65));
    // Apply the Movement Speed effect.
    ApplyEffectToObject(DURATION_TYPE_PERMANENT,eSlow,oPC);

    // Routine for sending the swim-mode message only one time.
    int doOnce = GetLocalInt(oPC,"swimming");
    if (0 == doOnce)
    {
        SetLocalInt(oPC,"swimming",1);
        // Send warning message to PCs entering the trigger.
        FloatingTextStringOnCreature("You are now in Swim Mode. Please do not use any Emotes or Movement Feats while swimming.",oPC);
    }

}

Many thanks,
PT

Your script returns immediately if the entering object is not a PC. Either remove that line or adjust it for associates, henchmen, …

if (!GetIsPC (oPC)) 
{
if(!GetIsPC(GetMaster(oPC)) return;
//This will check if the entering object has a Master who is a PC
//if it doesn't, then the return, otherwise the script continues
}

Sorry for not replying sooner, Mannast - been away for a few days.

Thank you very much indeed! My henchman now goes swimming as he is supposed to! Not being a scripter, I would never have been able to solve the issue myself.
All I have to do now is work out why (unlike his master PC) he doesn’t unequip his AC4 armour and his shield :frowning:
Thanks again!

1 Like

You could try

AssignCommand(oPC, ClearAllActions());

before the line

// Unequips Torches or Shields.

Kamiryn, you are an absolute star!!!
Your suggestion worked perfectly, and the henchman now unequips his armour, shield and cloak exactly in the manner of the master PC.
Thank you SO much for your interest and advice. Due to yourself and Mannast, the swimming system is done and dusted!!
Happy days :smile:

1 Like