void SpeakStringDelayed(object oTarget, string sString)
{
    ActionSpeakString(sString);
}

// Custom function to drag the target towards the player
/* vector SubtractVectors(vector vVector1, vector vVector2)
{
    vector vResult;
    vResult.x = vVector1.x - vVector2.x;
    vResult.y = vVector1.y - vVector2.y;
    vResult.z = vVector1.z - vVector2.z;
    return vResult;
}

// Custom function to calculate an intermediate location
location GetIntermediateLocation(object oTarget, object oUser, float fFraction)
{
    vector vTarget = GetPosition(oTarget);
    vector vUser = GetPosition(oUser);
    vector vDirection = SubtractVectors(vUser, vTarget);
    vector vIntermediate = Vector(vTarget.x + vDirection.x * fFraction, 
                                  vTarget.y + vDirection.y * fFraction, 
                                  vTarget.z + vDirection.z * fFraction);
    return Location(GetArea(oTarget), vIntermediate, GetFacing(oTarget));
}

// Custom function to 'jump' the target towards the player
void JumpTarget(object oTarget, object oUser, int nTimes, float fFraction)
{
    if(nTimes > 0)
    {
        location lIntermediate = GetIntermediateLocation(oTarget, oUser, fFraction);
        ActionJumpToLocation(lIntermediate);
        DelayCommand(1.0, JumpTarget(oTarget, oUser, nTimes - 1, fFraction)); // Continue jumping
    }
} */

void ForceMoveTarget(object oTarget, object oUser, int nTimes, float fFraction)
{
    if(nTimes > 0)
    {
        // Force the target to move to the user
        ActionForceMoveToObject(oUser, FALSE, fFraction * GetDistanceBetween(oTarget, oUser));
        DelayCommand(1.0, ForceMoveTarget(oTarget, oUser, nTimes - 1, fFraction)); // Continue moving
    }
}

void main()
{
    // Badger note:
    /*
    Sinfar uses variable events for this.
    oUser = OBJECT_SELF;
    oItemUsed = GetEventParamObject(0);
    oTarget = GetEventParamObject(1);
    */
    object oItem = GetItemActivated();
    object oTarget = GetItemActivatedTarget();
    object oUser = GetItemActivator();

    // Check if the script should verify the target's equipment.
    int nCheckTag = GetLocalInt(oItem, "P_1B66_ICHECKTAG");
    if(nCheckTag == 1)
    {
        object oChestItem = GetItemInSlot(INVENTORY_SLOT_CHEST, oTarget);
        if(GetTag(oChestItem) != "I_AM_PREY")
        {
            SendMessageToPC(oUser, "Target does not have the required item equipped.");
            return;
        }
    }

    // Check distance
    if(GetDistanceBetween(oUser, oTarget) > 20.0)
    {
        SendMessageToPC(oUser, "The target is not close enough.");
        return;
    }

    // Apply effects
    effect eBeam = EffectBeam(VFX_BEAM_CHAIN, oUser, BODY_NODE_CHEST);
    effect eEntangleVFX = EffectVisualEffect(VFX_DUR_ENTANGLE);
    //effect eImmobilize = EffectParalyze();

    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBeam, oTarget, 5.0); // 5 seconds
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEntangleVFX, oTarget, 60.0); // 10 minutes
   // ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eImmobilize, oTarget, 60.0); // 10 minutes




    // Start 'jumping' the target towards the player
 float fMoveFraction = 0.1; // Adjust this for how far each move should be (0.1 for 10% of the distance, etc.)
    int nMoveTimes = 10; // Adjust the number of moves as needed
    DelayCommand(5.0, ForceMoveTarget(oTarget, oUser, nMoveTimes, fMoveFraction));
}