Skip to content

Delay before CreateObject?

I am just trying to write a simple script, where : a goblin perceives the PC, runs away... and calls allies for help.

I am having trouble figuring out how to create the delay part...

void main()
{

object oSeen = GetLastPerceived();

if(GetIsPC(oSeen) && GetLastPerceptionSeen())
{

ClearAllActions();

location locSpawn = GetLocation(OBJECT_SELF);

ActionMoveAwayFromObject(oSeen, TRUE, 20.0f);

//DelayCommand? ActionWait? I'm not sure - neither of those seem to work

CreateObject(OBJECT_TYPE_CREATURE, "goblina003", locSpawn, TRUE);

}

}

thanks for any advice!!

Comments

  • DJ_WoWDJ_WoW Member Posts: 48
    Gooday to ya,

    That one is a little tricky. You can't DelayCommand a CreateObject function. You have to make a sub-function that holds the CreateObject and then AssignCommand to something to call it. i.e.


    void Spawn(string sResref, location locSpawn){
    CreateObject(OBJECT_TYPE_PLACEABLE, sResref, locSpawn);}

    void main{
    float fTimer = 2.0; //delay time
    location locSpawn = GetLocation(OBJECT_SELF);
    string sResRef = "goblina003";
    AssignCommand(GetArea(OBJECT_SELF), DelayCommand(fTimer, Spawn(sResRef, locSpawn)));}


    Something like this should work.

    DJ-WoW





  • DJ_WoWDJ_WoW Member Posts: 48
    Gooday again,

    Follow-up: I also see that you are trying to spawn a creature with OBJECT_TYPE_PLACEABLE.
    Change OBJECT_TYPE_PLACEABLE with OBJECT_TYPE_CREATURE.
  • ListenMirndtListenMirndt Member Posts: 24
    Thank you DJ, that worked perfectly...

    Wondering if you could help me with another - I've been having trouble finding what I'm looking for on NWNLexicon,

    basically - I am just wanting to spawn the additional goblins at a random distance...

    sort of like say, between 5 and 10 feet.

    (so it looks a little more like they are coming out of hiding and attacking) :)

    location locSpawn = GetLocation(OBJECT_SELF);

    so that put it's right on the main goblins location... but if I wanted to put it say between 5 and 10 feet away... how would that work? thanks again!
  • DJ_WoWDJ_WoW Member Posts: 48
    Gooday to ya,

    Try this - the only thing is make sure that you can't/don't spawn the goblin in an in-accessible location. Like on a different level of ground that the goblin then can not move to the location you want. I would just make a waypoint and spawn the goblin you are calling there.

    However this should work.


    this is a sub-function :

    location GetRandomSpawnPoint( object oPC)
    {float fDirection = IntToFloat( Random( 3601)) /10.0f;
    float fDistance = (IntToFloat( Random( 101)) /10.0f) + 2.0f;
    float fFacing = fDirection +180.0f;
    while( fFacing > 360.0f) fFacing -= 360.0f;
    return Location( GetArea( oPC), GetPosition( oPC) +(fDistance *AngleToVector( fDirection)), fFacing);}
    void main()
    {CreateObject( OBJECT_TYPE_CREATURE, "goblin003", GetRandomSpawnPoint( OBJECT_SELF));}

    This should work for you - I use this function to spawn a wandering monster at a random location.

    DJ-WoW
  • DJ_WoWDJ_WoW Member Posts: 48
    Gooday,

    I missed something - change the oPC in function to OBJECT_SELF.
  • ListenMirndtListenMirndt Member Posts: 24
    Thank you again!!

    It seems to work when I used oPC

    But changing to OBJECT_SELF

    I am getting an "Invalid Declaration Type"...

    (I think my newbie-ness to scripting is showing here)

    - - - -

    location GetRandomSpawnPoint(OBJECT_SELF); // the error shows for this line
    {
    float fDirection = IntToFloat( Random( 3601)) /10.0f;
    float fDistance = (IntToFloat( Random( 101)) /10.0f) + 2.0f;
    float fFacing = fDirection +180.0f;
    while( fFacing > 360.0f) fFacing -= 360.0f;
    return Location( GetArea( OBJECT_SELF), GetPosition( OBJECT_SELF) +(fDistance *AngleToVector( fDirection)), fFacing);
    }

    void main()
    {
    object oSeen = GetLastPerceived();

    if(GetIsPC(oSeen) && GetLastPerceptionSeen()) {

    ClearAllActions();

    location locSpawn = GetLocation(OBJECT_SELF);

    //vector vPosition = GetPosition(OBJECT_SELF);


    ActionMoveAwayFromObject(oSeen, TRUE, 20.0f);
    PlayVoiceChat(VOICE_CHAT_BATTLECRY1, OBJECT_SELF);
    DelayCommand(2.0, ActionSpeakString("Maach maach! dhec okaalkec mech!"));

    float fTimer = 2.0;

    string sResRef = "goblina003";
    string sResRef2 = "goblina004";


    CreateObject( OBJECT_TYPE_CREATURE, "goblin003", GetRandomSpawnPoint( OBJECT_SELF));
  • DJ_WoWDJ_WoW Member Posts: 48
    Gooday,

    This one compiles and runs:


    location GetRandomSpawnPoint(object oPC)
    {
    float fDirection = IntToFloat( Random( 3601)) /10.0f;
    float fDistance = (IntToFloat( Random( 101)) /10.0f) + 2.0f;
    float fFacing = fDirection +180.0f;
    while( fFacing > 360.0f) fFacing -= 360.0f;
    return Location( GetArea( OBJECT_SELF), GetPosition( OBJECT_SELF) +(fDistance *AngleToVector( fDirection)), fFacing);
    }
    /////////////////////////////////////////////////////////////////////////////////////////
    void main()
    {
    object oPC = OBJECT_SELF;
    object oSeen = GetLastPerceived();
    if(GetIsPC(oSeen) && GetLastPerceptionSeen()) ClearAllActions();
    ActionMoveAwayFromObject(oSeen, TRUE, 20.0f);
    string sResRef = "goblina003";
    string sResRef2 = "goblina004";
    if (GetLocalInt(oPC, "DO_ONCE") == 0) //set this variable so it would only do this once
    {SetLocalInt(oPC, "DO_ONCE", 1);
    AssignCommand(oPC, DelayCommand(2.0, SpeakString("Maach maach! dhec okaalkec mech!")));
    CreateObject( OBJECT_TYPE_CREATURE, sResRef, GetRandomSpawnPoint(oPC));
    CreateObject( OBJECT_TYPE_CREATURE, sResRef2, GetRandomSpawnPoint(oPC)); }
    }

    Have fun,

    DJ-WoW
  • ListenMirndtListenMirndt Member Posts: 24
    DJ, that works SO perfectly... thank you times 1 million <3:) !!!
Sign In or Register to comment.