Aller au contenu

Photo

Area heartbeat


32 réponses à ce sujet

#26
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
Is it not the case that when you redirect it to the PC that the "heartbeat" will run all the time, even when the player is not in the area? If you only want it going for that one area I believe you must send the events specifically to the area, kick it off when they enter, and stop re-sending them when the player exits.


#27
FalloutBoy

FalloutBoy
  • Members
  • 580 messages

Axe_Murderer wrote...

Is it not the case that when you redirect it to the PC that the "heartbeat" will run all the time, even when the player is not in the area? If you only want it going for that one area I believe you must send the events specifically to the area, kick it off when they enter, and stop re-sending them when the player exits.


That's a good question. If an area script did a DelayEvent to send an event to itself, does it still get the event if the player leaves the area before it fires? That would mean you would be running an area script for an area that is not currently loaded. I would be surprised if that worked in any kind of predictable way. That would mean that you probably need to re-kick the heartbeat when the player returns to the area, though it warrants more testing.

#28
Sunjammer

Sunjammer
  • Members
  • 925 messages
Will probably depend if the area is in the active area list. Something to test methinks.

/me volunteers FalloutBoy

#29
FalloutBoy

FalloutBoy
  • Members
  • 580 messages
Long story short, only the current area gets events.

I made an area script template with a heartbeat event every 6 seconds and posted it here:
http://social.biowar...m/project/1261/

Or you can cut and paste it from this, assuming it pastes correctly:

//::///////////////////////////////////////////////
//:: Area Core
//:: Copyright © 2003 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Handles global area events
*/
//:://////////////////////////////////////////////
//:: Created By: Yaron
//:: Created On: July 17th, 2006
//:://////////////////////////////////////////////

#include "log_h"
#include "utility_h"
#include "wrappers_h"
#include "events_h"
#include "2da_constants_h"
        
const float HEARTBEAT_LENGTH = 6.0;

void main()
{
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);
    string sDebug;
    object oPC = GetHero();
    object oParty = GetParty(oPC);
    int nEventHandled = FALSE;

    switch(nEventType)
    {
        case EVENT_TYPE_HEARTBEAT:
        {         
            // Replace this line with your heartbeat code.
            DisplayFloatyMessage( GetHero(), "HB " + GetName(OBJECT_SELF), FLOATY_MESSAGE, 0xffffff, 2.0 );
           
            DelayEvent( HEARTBEAT_LENGTH, OBJECT_SELF, Event(EVENT_TYPE_HEARTBEAT) );
            break;
        }

        ///////////////////////////////////////////////////////////////////////
        // Sent by: The engine
        // When: it is for playing things like cutscenes and movies when
        // you enter an area, things that do not involve AI or actual game play
        ////////////////////////////////////////////////////////////////////////
        case EVENT_TYPE_AREALOAD_SPECIAL:
        {
            break;
        }
        ///////////////////////////////////////////////////////////////////////
        // Sent by: The engine
        // When: for things you want to happen while the load screen is still up,
        // things like moving creatures around
        ////////////////////////////////////////////////////////////////////////
        case EVENT_TYPE_AREALOAD_PRELOADEXIT:
        {
            break;
        }
        ////////////////////////////////////////////////////////////////////////
        // Sent by: The engine
        // When: fires at the same time that the load screen is going away,
        // and can be used for things that you want to make sure the player sees.
        ////////////////////////////////////////////////////////////////////////
        case EVENT_TYPE_AREALOAD_POSTLOADEXIT:
        {        
            // Kick start the heartbeat
            DelayEvent( HEARTBEAT_LENGTH, OBJECT_SELF, Event(EVENT_TYPE_HEARTBEAT) );
            break;
        }
        ////////////////////////////////////////////////////////////////////////
        // Sent by: The engine
        // When: A creature enters the area
        ////////////////////////////////////////////////////////////////////////
        case EVENT_TYPE_ENTER:
        {
            object oCreature = GetEventCreator(ev);

            break;
        }
        ////////////////////////////////////////////////////////////////////////
        // Sent by: The engine
        // When: A creature exits the area
        ////////////////////////////////////////////////////////////////////////
        case EVENT_TYPE_EXIT:
        {
            object oCreature = GetEventCreator(ev);

            break;
        }
    }
    if (!nEventHandled)
    {
        HandleEvent(ev, RESOURCE_SCRIPT_AREA_CORE);
    }
}



#30
georage

georage
  • Members
  • 247 messages
Strangely, using your heartbeat system fixed my problem with IsObjectValid working backwards!



Thanks.

#31
FalloutBoy

FalloutBoy
  • Members
  • 580 messages
Heh glad to hear it. B)

#32
Sunjammer

Sunjammer
  • Members
  • 925 messages
You might want to set nEventHandled to TRUE in the EVENT_TYPE_HEARTBEAT to avoid calling the area_core script. I'd also cull all the unused variables at the head of the script: saves a few instructions per heartbeat.

Modifié par Sunjammer, 10 décembre 2009 - 08:55 .


#33
FalloutBoy

FalloutBoy
  • Members
  • 580 messages
A decent compiler would strip all that out if the variables are unused. I guess we have no way to know with asking Bioware. I just wanted to add to the existing template and didn't want to remove things that people might need.