Aller au contenu

Photo

Destroy visual body


  • Veuillez vous connecter pour répondre
2 réponses à ce sujet

#1
diophant

diophant
  • Members
  • 116 messages
First, here is what I'm planning to do:

I'm working on a new corpse system. If you kill an NPC, he leaves a corpse (as usual). You can loot this corpse, but you can also drag it into a dark corner, or burn it (to remove any evidence of your murderers). When you click on the corpse, a dialogue with the different possible actions pops up.

The NPCs are set to no decay, no lootable corpse, and not selectable. In the onDeath script, an invisible corpse object is created, the whole inventory of the NPC transfered to this object, and the original NPC set as a local object of the corpse object. Every action goes now via this corpse object.

This is the onDeath script:

[nwscript]
// Transfers the whole inventory of OBJECT_SELF to oTarget
void transferItems(object oTarget)
{
    object item = GetFirstItemInInventory(OBJECT_SELF);
    object copy;
    int i;
   
    // cycle through normal inventory   
    while (GetIsObjectValid(item))
    {
        copy = CopyItem(item, oTarget, TRUE);
        SetIdentified(copy, FALSE);
        DestroyObject(item);
        item = GetNextItemInInventory(OBJECT_SELF);
    }
    // cycle through slots
    for (i = 0; i < 14; ++i)
    {
        item = GetItemInSlot(i);
        if (GetIsObjectValid(item))
        {
            copy = CopyItem(item, oTarget, TRUE);
            SetIdentified(copy, FALSE);
            SetDroppableFlag(item, FALSE);
            item = GetNextItemInInventory(OBJECT_SELF);
        }
    }
}


void main()
{
    int nclass = GetLevelByclass(class_TYPE_COMMONER);
    int nAlign = GetAlignmentGoodEvil(OBJECT_SELF);
    object oKiller = GetLastKiller();
    object corpse;
    object pc;

    // If we're a good/neutral commoner,
    // adjust the killer's alignment evil
    if(nclass > 0 && (nAlign == ALIGNMENT_GOOD || nAlign == ALIGNMENT_NEUTRAL))
        AdjustAlignment(oKiller, ALIGNMENT_EVIL, 5);
    // Call to allies to let them know we're dead
    SpeakString("NW_I_AM_DEAD", TALKVOLUME_SILENT_TALK);
    //Shout Attack my target, only works with the On Spawn In setup
    SpeakString("NW_ATTACK_MY_TARGET", TALKVOLUME_SILENT_TALK);
   
    // Leave a corpse
    corpse = CreateObject(OBJECT_TYPE_PLACEABLE, "rb_corpse", GetLocation(OBJECT_SELF));
    SetLocalObject(corpse, "oCorpse", OBJECT_SELF);
    transferItems(corpse);

    // Forward the event   
    if (GetSpawnInCondition(NW_FLAG_DEATH_EVENT))
        SignalEvent(OBJECT_SELF, EventUserDefined(1100));
}
[/nwscript]

It all works fine, except for burning the corpse. The corpse just remains there (as visual object). I triple checked that the local object is valid, and no plot flag is set. I remembered that I had it already working, but I overwrote the backup scripts. I guess it might have something to do with the flags you have to set on the NPC, but I just don't get it.
Here is the corresponding script of the conversation:

[nwscript]

void main()
{
    effect fire = EffectVisualEffect(VFX_DUR_FIRE);
    location loc;
   
    // quest update: if this is a witness and burned in the storage room,
    // decrease the number of witnesses by one
    loc = GetLocation(OBJECT_SELF);
    // fire effect
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, fire, OBJECT_SELF, 5.0f);
    SetPlotFlag(OBJECT_SELF, FALSE);
    SetUseableFlag(OBJECT_SELF, FALSE);
    DestroyObject(GetLocalObject(OBJECT_SELF, "oCorpse"), 4.5f);
    DestroyObject(OBJECT_SELF, 5.0f);
}
[/nwscript]

Does anybody know how to destroy the visual body of the dead NPC?

#2
Guest_Chaos Wielder_*

Guest_Chaos Wielder_*
  • Guests
You have to tell the dead object to Execute a script via the ExecuteScript function. In that executed script, you have to call this:



void main()

{

SetIsDestroyable(TRUE, FALSE, FALSE);

DestroyObject(OBJECT_SELF);

}



This *should* work.

#3
diophant

diophant
  • Members
  • 116 messages
Works like a charm :-) Many thanks!