Skip to content

Making corpse NPCs

I found this tutorial which is very useful but I decided to add a twist to that:

If using an OnSpawn script on an NPC will make its corpse lie face down, and having the area do the same thing will make the corpse lie face up, is there a way to randomize that? I tried using a Random Int but as the actions are based on different events, I'm not really sure how that could be achieved. Any ideas?

Comments

  • EzRemakeEzRemake Member Posts: 15
    SetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_Y, 90.0);
  • gpeddinogpeddino Member Posts: 51
    edited September 2019
    Thanks, for the tip, EZRemake!

    I devised a system that will randomize the corpses (their position, if they're face down or up, and also add bloodstains underneath them) and it turned out great, so I thought I'd share it here for anyone who's interested:

    On every area that will have corpses, go to its OnUserDefined event and add:
    void main()
    {
        switch(GetUserDefinedEventNumber())
        {
            case 107:
    
            switch (Random(1))
            {
                case 0:
                ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDeath(), GetLocalObject(OBJECT_SELF, "Corpse"));
            }
            break;
        }
        return;
    }
    

    Create an NPC, change its tag to "Corpse" and remove all of its scripts. Then, on its OnDeath, add:
    void main()
    {
        SetIsDestroyable(FALSE);
    }
    

    And on its OnSpawn, add:
    #include "x0_i0_position"
    location GetBloodLocation(object oTarget, float fDistance)
    {
        float fDir = GetFacing(oTarget);
        float fAngleOpposite = GetOppositeDirection(fDir);
        return GenerateNewLocation(oTarget,
                                   fDistance,
                                   IntToFloat(Random(360)),
                                   fDir);
    }
    
    void main()
    {
        object oArea = GetArea(OBJECT_SELF);
        float fDirection = IntToFloat(Random(360));
        vector vPos = GetPositionFromLocation(GetLocation(OBJECT_SELF));
    
        if (d2(1) == 1)
        {
            ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDeath(), OBJECT_SELF);
        }
        else
        {
            SetLocalObject(oArea, "Corpse", OBJECT_SELF);
            SignalEvent(oArea, EventUserDefined(107));
        }
    
        /// Turn body to a random direction.
        SetObjectVisualTransform(OBJECT_SELF, OBJECT_VISUAL_TRANSFORM_ROTATE_X, fDirection);
    
        /// Create bloodstain:
        CreateObject(OBJECT_TYPE_PLACEABLE, "plc_bloodstain", GetBloodLocation(OBJECT_SELF, 0.4));
        CreateObject(OBJECT_TYPE_PLACEABLE, "plc_bloodstain", GetBloodLocation(OBJECT_SELF, 0.7));
    
        /// Turn bloodstains to random directions.
        SetObjectVisualTransform(GetNearestObjectByTag("Bloodstain"), OBJECT_VISUAL_TRANSFORM_ROTATE_X, fDirection);
        SetObjectVisualTransform(GetNearestObjectByTag("Bloodstain"), OBJECT_VISUAL_TRANSFORM_ROTATE_X, fDirection);
    }
    

    There it is. You can change the name (e.g. "Mauled Corpse", "Strangled Woman", etc) and clothing of the corpses and give them weapons and items to create variation, as long as you keep their "Corpse" tag and use those same scripts.
  • TarotRedhandTarotRedhand Member Posts: 1,481
    FWIW If all someone wants is to have a dead creature in an area just put this in its OnSpawn event -
    x2_spn_dead
    

    TR
Sign In or Register to comment.