Aller au contenu

Photo

Making a function into an action function.


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

#1
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
I want to use the function PlayCustomAnimation() in the scripted waypoint system.  Right now it doesn't work and I suspect this is because the function does not go into the action cue.  I tried to make a wrapper function like this:



action ActionPlayCustomAnimation( variables go here)
{
PlayCustomAnimation(OBJECT_SELF,other variables go here);
}


But that didn't compile.  Is there a way to do this or am I trying to do the impossible?

#2
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
Can you use the function ActionPlayAnimation()?

Or, check this out here, there is an example of making PlayCustomAnimation() into a wrapper function: http://nwn2.wikia.co...CustomAnimation

#3
MasterChanger

MasterChanger
  • Members
  • 686 messages

M. Rieder wrote...

action ActionPlayCustomAnimation( variables go here)
{
PlayCustomAnimation(OBJECT_SELF,other variables go here);
}


But that didn't compile.  Is there a way to do this or am I trying to do the impossible?


The reason it's not compiling is that you're promising it that it will return an "action" and then you're not returning anything.

#4
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
@ MasterChanger,

Oh yeah.... duh. Thanks. One of my hobbies is asking obvious questions on the forums here. Can't believe I didn't see that.

#5
M. Rieder

M. Rieder
  • Members
  • 2 530 messages

_Knightmare_ wrote...

Can you use the function ActionPlayAnimation()?

Or, check this out here, there is an example of making PlayCustomAnimation() into a wrapper function: http://nwn2.wikia.co...CustomAnimation



I want to use the animation "disableground".  I don't know how to use that animation with ActionPlayAnimation().  If I could get that animation to work with ActionPlayAnimation(), that would be great. 

I'll try the void wrapper function.  Is there a way to make a wrapper function tell the engine to see it as an action function, or is that sort of thing hardcoded?

#6
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Okay, problem solved. I didn't ever figure out how to make PlayCustomAnimation() into an action function, but I found out if I use the function FaceAndPause() before the function PlayCustomAnimation() and allow enough time for the animation to play, it works great.

FYI: the function FaceAndPause() is from either ginc_wp or x0_i0_walkway. I can't remember which one right now.

#7
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
You create a void function, which you can put into a delay or assigncommand as needed. ( read the link to know more ) or ActiondoCommand

You don't create new actions, you create functions which get put into the queue, remember to use clear all actions in your scripts to fix issues with this.

void CSLPlayCustomAnimation_Void(object oPC, string sAnimationName, int nLooping = FALSE, float fSpeed = 1.0f)
{
   PlayCustomAnimation(oPC, sAnimationName, nLooping, fSpeed);
}


Example of usage ( using both delay and assign )
sCurrentAnimation = CSLNth_GetNthElement( sAnimationName, iCurrentAnimation, sDelimiter );
	fDuration = CSLGetAnimationDuration( sCurrentAnimation, GetGender( oObject ) );
		DelayCommand( fTotalDuration, AssignCommand(oObject, CSLPlayCustomAnimation_Void(oObject, sCurrentAnimation, nLooping, fSpeed)) );


( note that CSLGetAnimationDuration is based on Cerea2's list of animation durations, and is very useful in fixing animation issues by delaying them the correct amount so they start just as the previous one finishes )

#8
Morbane

Morbane
  • Members
  • 1 883 messages
You know Matt - you are pushing the boundaries of NWN2 - it is no wonder your mods are in the top list on the Vault - makes me think my mod is just another anonymous project - I mean I have cc and lots of handy scripts and clever dialog -  but not the kind of things that really hook a player.

Keep it goin man

Modifié par Morbane, 01 juin 2011 - 07:47 .


#9
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Ah yes, ActionDoCommand(). That makes sense. That is pretty handy that the CSL has a function that automatically determines the right delay for custom animations. I'm already hooked. I can't wait to get in it and start working on my battle AI.

#10
M. Rieder

M. Rieder
  • Members
  • 2 530 messages

Morbane wrote...

You know Matt - you are pushing the boundaries of NWN2 - it is no wonder your mods are in the top list on the Vault - makes me think my mod is just another anonymous project - I mean I have cc and lots of handy scripts and clever dialog -  but not the kind of things that really hook a player.

Keep it goin man


Thanks for the encouragement, Morbane.  God knows as builders who work months and years on projects we need it.  I'm sure Master of Inifinity will be anything but anonymous.

#11
SkywingvL

SkywingvL
  • Members
  • 351 messages
Let me clarify a few things here.

1) The "action" type doesn't have anything to do with whether something goes into an object's action queue or not. It has to do with saving the state of the script away so that part of it can be run later. (It's a bad name, IMO.)

2) The only  way to add custom script code that lives in an object's action queue and runs when it's at the top of the queue and the queue is enabled is the ActionDoCommand engine function.  AssignCommand and DelayCommand cause some custom script code to run at a later time by placing the request in the object's event queue.  These are different things; the user can't (directly) cause the event queue for an object to be cleared out (but they can cancel action queue entries, i.e. ActionDoCommand requests, that haven't run yet).  Additionally, AssignCommand/DelayCommand requests will run even while there are still action queue entries that haven't finished yet (for example, a long Wait action added by calling ActionWait won't block queued DelayCommand requests).)

3) The "action" type isn't actually a normal type; you can't declare a variable of that type, declare your own functions taking an argument of that type, nor declare your own functions returning that type. It requires special handling in the engine for each engine function that takes an "action" argument; it's not really a normal type in that respect.  When the "action" type is encountered, this is really an instruction to the compiler to add some code to save the state of the script.  Then the engine function being called uses the saved state in some way (for example, saving it away to run later).

Modifié par SkywingvL, 01 juin 2011 - 04:20 .


#12
The Fred

The Fred
  • Members
  • 2 516 messages
I think PlayCustomAnimation simply puts the animation at the top of the queue, like the JumpXXX() functions. Playing an animation is still an action, so it will still be treated as such anyway.

As mentioned, ActionDoCommand() is the way to make something an action. You can queue things up like this (for example, if you want someone to run an uninterruptable sequence, give them the actions followed by ActionDoCommand(SetCommandable(TRUE)) and then call SetCommandable(FALSE). They now can't be commanded to do something else without using SetCommandable again, but when they've finished what they're doing, they un-uncommandable-ise themselves - though this is a whole nother topic).

Any void-type command can be passed into ActionDoCommand. I remember trying to use the action type in functions (as an imput I think, but anyway) a while ago and it doesn't work, as Skywing says.

#13
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Thanks for the clarification. That helped alot. I still don't fully understand the use of the "action" type, but based on what you said, I probably don't need it, so its okay. My main concern was making new functions and getting them into the action queue.

I also wanted to see how many times I could get the word queue to show up in a thread... 12 and counting!

#14
SkywingvL

SkywingvL
  • Members
  • 351 messages

The Fred wrote...

I think PlayCustomAnimation simply puts the animation at the top of the queue, like the JumpXXX() functions. Playing an animation is still an action, so it will still be treated as such anyway.

As mentioned, ActionDoCommand() is the way to make something an action. You can queue things up like this (for example, if you want someone to run an uninterruptable sequence, give them the actions followed by ActionDoCommand(SetCommandable(TRUE)) and then call SetCommandable(FALSE). They now can't be commanded to do something else without using SetCommandable again, but when they've finished what they're doing, they un-uncommandable-ise themselves - though this is a whole nother topic).

Any void-type command can be passed into ActionDoCommand. I remember trying to use the action type in functions (as an imput I think, but anyway) a while ago and it doesn't work, as Skywing says.


Actually, PlayCustomAnimation doesn't use the action queue at all; the server simply immediately broadcasts wthe animation to all players regardless of other considerations.  It is immediate even if the action queue is otherwise frozen, e.g. due to pause (although clients may elect to freeze the animation until pause thaws).

#15
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
I tried using ActionDoCommand() with a void function I made consisting of PlayCustomAnimation. It didn't seem to behave like an action. That is, I scripted the command 3 times without a delay and ran it and only the 1st one happened. I wonder if I'm doing it incorrectly.

I don't have the code with me. I'll post it later.

#16
SkywingvL

SkywingvL
  • Members
  • 351 messages
This is about what I would expect.

The custom animation support is somewhat of a basic bolt-on in that it's fire-and-forget, instantaneous and stateless as far as the server is concerned. Only players currently in the area are told of a custom animation (new players joining aren't), and the server doesn't track progress in actually playing the animation if you attempt to overlap custom animations.  Literally all that PlayCustomAnimation does is ship a message off to clients in the area telling them to play an animation file right now.

In other words, script code is wholly responsible for 1) rebroadcasting standing custom animations when new players enter an area, and 2) ensuring appropriate timing between issuing new custom animations.

Modifié par SkywingvL, 04 juin 2011 - 08:48 .


#17
The Fred

The Fred
  • Members
  • 2 516 messages

SkywingvL wrote...
Actually, PlayCustomAnimation doesn't use the action queue at all; the server simply immediately broadcasts wthe animation to all players regardless of other considerations.  It is immediate even if the action queue is otherwise frozen, e.g. due to pause (although clients may elect to freeze the animation until pause thaws).

Oh, I see. What I was getting at is that it fires right away even if there are other animations. I was probably thinking of PlayAnimation(), though; not sure if this works in the same way, but IIRC it also fires straight away.

#18
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
I notice that if I use the code:

ActionDoCommand(ApplyEffectToObject()), it works as intended, putting the application of the effect into the action queue.

#19
SkywingvL

SkywingvL
  • Members
  • 351 messages

M. Rieder wrote...

I notice that if I use the code:

ActionDoCommand(ApplyEffectToObject()), it works as intended, putting the application of the effect into the action queue.


ActionDoCommand is a generic mechanism to put a request to run some script snippet (in this case, "ApplyEffectToObject()") in the action queue.  You can use this to package any sort of scripted change into the action queue, however if the action queue is editable, the user can clear the queue entry out, so be aware of this.

#20
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
So ActionDoCommand() should also work with PlayCustomAnimation(). I wonder what I did wrong. I'll have to run some tests on it.

#21
SkywingvL

SkywingvL
  • Members
  • 351 messages

M. Rieder wrote...

So ActionDoCommand() should also work with PlayCustomAnimation(). I wonder what I did wrong. I'll have to run some tests on it.


It will place the animation in the action queue.  However, ActionDoCommand action queue entries don't have any delays associated with their execution, so once the action queue entry runs, the next one immediately runs.  (If you queued up multiple PlayCustomAnimations this way, the end result will not be what you want.  You will need to manually time them with ActionWait interspersed in between according to the animation timing.)