#include "cas_inc_bttltrap"

// TPS calls this when it creates the placeable.
// The exact parameter indexes depend on TPS; this pattern is safe:
// - Use GetCurrentVariableEventTarget() if available,
// - Otherwise fall back to GetEventParamObject(0/1).
//
// If your environment supports GetCurrentVariableEventTarget(), it?s documented for variable events. :contentReference[oaicite:9]{index=9}

void main()
{
    object oTarget = GetCurrentVariableEventTarget(); // typically the placeable for TPS_PLACED_SCRIPT
    object oItem0  = GetEventParamObject(0);
    object oItem1  = GetEventParamObject(1);

    object oPlace = oTarget;
    object oItem  = OBJECT_INVALID;

    // Resolve best guesses
    if (GetObjectType(oItem0) == OBJECT_TYPE_ITEM) oItem = oItem0;
    else if (GetObjectType(oItem1) == OBJECT_TYPE_ITEM) oItem = oItem1;

    if (!GetIsObjectValid(oPlace) || GetObjectType(oPlace) != OBJECT_TYPE_PLACEABLE) return;
    if (!GetIsObjectValid(oItem)) return;

    // Copy all locals (includes CAS_UID, CAS_OWNER_KEY, CAS_JAR_TYPE)
    CopyVariables(oItem, oPlace);

    // If you prefer only copying specific ones, do it manually instead.
}
