Aller au contenu

Photo

"Change" the "OnHeartBeat" timing


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

#1
Fabb_u

Fabb_u
  • Members
  • 20 messages
Hi there, someone can answer to this question?

is there a trick in Neverwinter Nights 2 scripting (or other) to change the timing of the "OnHeartbeat" of an Area (that is about 6 seconds)  ??

If i have to do an operation in my script about 4 times per second how can i do it ??

Maybe a "while cicle" in the script assigned to the "OnHeartbeat" event of the Area ??

thanks for answers !!

#2
kamal_

kamal_
  • Members
  • 5 240 messages
http://nwn.wikia.com...seudo-heartbeat

Same for nwn2.

#3
Fabb_u

Fabb_u
  • Members
  • 20 messages
Thanks a lot !!

I will try it, obviously are welcome even other solutions or tricks :-)

#4
Tchos

Tchos
  • Members
  • 5 042 messages
I use the SetCustomHeartbeat() function. To make it 4 seconds, write:

object oArea = GetObjectByTag("your_area_tag");
SetCustomHeartbeat(oArea, 4000);

Edit:

Ah, you want 4 times per second, not every 4 seconds.  In that case,

SetCustomHeartbeat(oArea, 250);

Modifié par Tchos, 11 juillet 2013 - 02:13 .


#5
Fabb_u

Fabb_u
  • Members
  • 20 messages
Great !! :-)

#6
Dann-J

Dann-J
  • Members
  • 3 161 messages
It's good to hear that SetCustomHeartbeat() works on areas as well as on creatures. It certainly doesn't work on placeables (including iPoints).

#7
Tchos

Tchos
  • Members
  • 5 042 messages
It should be said that I haven't tried it on an area. My experience has been from using it on creatures. Some testing would have to be done.

#8
Tchos

Tchos
  • Members
  • 5 042 messages

DannJ wrote...
SetCustomHeartbeat() [...] certainly doesn't work on placeables (including iPoints).

I went and tested this, and I think you'll be happy to find that it does.  I have a heartbeat script on the two placeables in this video (a wine crate, and an ipoint), and I've used SetCustomHeartbeat(OBJECT_SELF, 1000) to give them 1-second heartbeats.  In the video, you can see that their SpeakString() calls are being executed every 1 second.

Demo

Modifié par Tchos, 12 juillet 2013 - 06:20 .


#9
Darin

Darin
  • Members
  • 282 messages
You could always use a general script, not a heartbeat...

adding the following to the area oncliententer:

void MyOperation(object oObject)
{
//something to make sure this only runs while the player is in the area
//change this or remove it depending on what you want done... could also use a
// GetIsObjectValid(oObject) to make sure you're not running it when object is gone
// too many heartbeat functions in a module will ruin other things, like Kaedrin's
if(GetTag(GetArea(GetFirstPC()))==GetTag(GetArea(oObject)))
{
//***insert whatever you want done here***
// a delay of 0.25 s to run this again...
DelayCommand(0.25,MyOperation(oObject))
}
}

#10
Fabb_u

Fabb_u
  • Members
  • 20 messages
Excuse me Tchos but exactly how should i use your trick ?

Must i put the two lines of code in a script assigned to the "OnHeartbeat" of the area ??

#11
kamal_

kamal_
  • Members
  • 5 240 messages

Tchos wrote...

DannJ wrote...
SetCustomHeartbeat() [...] certainly doesn't work on placeables (including iPoints).

I went and tested this, and I think you'll be happy to find that it does.  I have a heartbeat script on the two placeables in this video (a wine crate, and an ipoint), and I've used SetCustomHeartbeat(OBJECT_SELF, 1000) to give them 1-second heartbeats.  In the video, you can see that their SpeakString() calls are being executed every 1 second.

Demo

In Crimmor, the item Evercarpet relies on ipoints with very short custom heartbeats to produce it's effect when used.

#12
Tchos

Tchos
  • Members
  • 5 042 messages

Fabb_u wrote...
Excuse me Tchos but exactly how should i use your trick ?
Must i put the two lines of code in a script assigned to the "OnHeartbeat" of the area ??

You could do that, but I wouldn't recommend it.  It would be more efficient to put the lines in some place where they'd only be run once (or at least only once per visit), because you don't need to set the heartbeat over and over.  You could put it in your area's On Client Enter slot, for instance.

If you do put it in the actual area's script set, then you don't need the first line.  You could use "OBJECT_SELF" to refer to the area.


kamal_ wrote...
In Crimmor, the item Evercarpet relies on ipoints with very short custom heartbeats to produce it's effect when used.

I'll have to check that out.  :)

Modifié par Tchos, 12 juillet 2013 - 04:30 .


#13
Fabb_u

Fabb_u
  • Members
  • 20 messages
Mmmm something doesn't work :-(

1- I have an area whose Tag is "area1"

2- I assign a script to the "On clientEnter" event of this area; the script is the follow:

void main()
{
object oArea = GetObjectByTag("OBJECT_SELF");
SetCustomHeartbeat(oArea, 250);
}

3- I assign a script to the "On HeartBeat" event of the area; the script is the follow:

void main()
{
int h = GetCustomHeartbeat(GetObjectByTag("OBJECT_SELF"));
SendMessageToPC(GetFirstPC(), "message ! " + IntToString© + " heart= " + IntToString(h));
}

The value of "h" is always "0" and the message appears every 6 seconds, so the new definition of the heartbeat doesn't work !!!

#14
Tchos

Tchos
  • Members
  • 5 042 messages
I'm sorry, let me explain. There are certain constants in the game like "OBJECT_SELF", which always refer to the object that fires the script. For those objects, you don't need to use GetObjectByTag() (although you could if you wanted to -- just not with "OBJECT_SELF" as a tag, because it's not a tag). Since the script is fired by the Area object, OBJECT_SELF is the area. This is how it should look.

void main()
{
    object oArea = OBJECT_SELF;
    SetCustomHeartbeat(oArea, 250);
}

Or, you can skip the first line entirely, and write:

void main()
{
    SetCustomHeartbeat(OBJECT_SELF, 250);
}

Or, you could also write it like this, since your area's tag is "area1":

void main()
{
    object oArea = GetObjectByTag("area1");
    SetCustomHeartbeat(oArea, 250);
}

Modifié par Tchos, 13 juillet 2013 - 11:07 .


#15
Fabb_u

Fabb_u
  • Members
  • 20 messages
Thanks of the explain Tchos... but the problem remains ! :-(
Maybe the SetCustomHeartbeat doesn't work with an area?

Could you send me the module which you used to do yours "Demo" video ???

#16
Fabb_u

Fabb_u
  • Members
  • 20 messages
Ok, i tried the scripts with a creature and seems to work... so i think that is the Area object the problem

#17
Tchos

Tchos
  • Members
  • 5 042 messages
I did my own test on an area, and I confirm that it doesn't seem to work on areas. Sorry for the false lead. You probably don't need the test module anymore.

From this point, though, if you still want to use the custom heartbeat, could you put your script (whatever you want to do with this heartbeat) on an ipoint in the area instead of on the area itself?

Modifié par Tchos, 13 juillet 2013 - 01:23 .


#18
Fabb_u

Fabb_u
  • Members
  • 20 messages
I put the scripts in a creature which will follow the player and which is immortal ... is it possible to made this creature "like there isn't in", so invisible to opponents, ecc .. ?

#19
Tchos

Tchos
  • Members
  • 5 042 messages
It would help give better advise if you explain what you're trying to do with it.

#20
Fabb_u

Fabb_u
  • Members
  • 20 messages
I need to gather some info from the game (i.e. position of the player, health, inventory, ecc) and save them in the log file.
I think to use this creature like an "observer" to take this info about 4 times per second: this creature has to be "invisible", not a member of the party ... it must not enjoy battles, not interact with enemies or npc ecc.

#21
Tchos

Tchos
  • Members
  • 5 042 messages
Then you don't need to have a creature follow the PC around. An ipoint can be placed anywhere and gather that information from the player. It doesn't even have to be in the same area.

#22
Dann-J

Dann-J
  • Members
  • 3 161 messages
I tried altering the HB rate of an iPoint once, and it didn't seem to work. It was on an overland map, but I don't think that should have any effect (although I *have* noticed some things that behave strangely on OLMs). I ended up using a script-hidden rat with its AI on, which did the trick.

I wanted fading footsteps to appear behind the player as they moved across the overland map, and once every six seconds wasn't nearly frequent enough (unless the player was a kangaroo). 'Track Rat' does his job brilliantly though. He even offsets the tracks slightly to either side in alternate directions to make them look like actual foot or hoof prints.

#23
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
In my tactics script, I just call a function from the heartbeat multiple times on a delay (DelayCommand(1.5,...), DelayCommand(3.0,...), DelayCommand(4.5,...)). Calling it from the main heartbeat means it gets shut down within a heartbeat's time if it's no longer needed.

#24
Fabb_u

Fabb_u
  • Members
  • 20 messages
It seems that only a creature could do what i want, in other items it is impossible to change the heartbeat

#25
Tchos

Tchos
  • Members
  • 5 042 messages
I must have a magic toolset, then.

Regardless, even if you use a creature, it doesn't have to follow the player around.

Modifié par Tchos, 15 juillet 2013 - 01:20 .