Aller au contenu

Photo

Destroy creature


5 réponses à ce sujet

#1
Arius23

Arius23
  • Members
  • 345 messages
I figured out the script for creating creatures and spawning them in areas but how do I remove a creature that is already in the area?  Thanks. 

#2
Sunjammer

Sunjammer
  • Members
  • 926 messages
You need to get a reference to the object (so, for example, use GetObjectByTag if you know the tag) and then you destroy it (Georg says we must use Safe_Destroy_Object in the core_h library) .

Note that Safe_Destroy_Object prevents you from destroying party members and creatures flaged as plot or immortal. If you are wanting to do this then you will have to address those "issues" or (I suspect) use DestroyObject.

Modifié par Sunjammer, 28 mars 2010 - 10:56 .


#3
Arius23

Arius23
  • Members
  • 345 messages
I'm a scripting noob, can you give me an example using that script of simply remove a creature from an area?

#4
Sunjammer

Sunjammer
  • Members
  • 926 messages
A lot will depend on what event you are running it from and what triggers the event. I'm going to assume you're using this to set up an area so I'm using one of the "area load" events but it could just as easily be run from a trigger or a useable placeable or, well, pretty much anything.

#include "core_h"
#include "utility_h"
#include "wrappers_h"

void main()
{
    int bEventHandled;

    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);

    switch(nEventType)
    {                       
        //
        // (other events here)
        //
        
        case EVENT_TYPE_AREALOAD_POSTLOADEXIT:
        {
            object oTarget = GetObjectByTag("tag_of_creature_goes_here");
            if(IsObjectValid(oTarget))
            {
                // NOTE: fails for party members and creatures flagged as plot or immortal
                Safe_Destroy_Object(oTarget);
            }
            break;
        }
        //
        // (other events here)
        //
    }
    if (!bEventHandled)
    {
        HandleEvent(ev, RESOURCE_SCRIPT_AREA_CORE);
    }
}


#5
Arius23

Arius23
  • Members
  • 345 messages
it happens after a cutscene, but i figured it out thanks to the code you provided. thanks!

#6
DavidSims

DavidSims
  • BioWare Employees
  • 196 messages
You can also set a creature innactive, instead of destroying it. If there's any chance you mihgt want to bring the creatures back later, I would use this aproach. Use WR_SetObjectActive(oTarget, FALSE) instead of the safe destroy object call.