Making a function into an action function.
#1
Posté 31 mai 2011 - 03:25
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
Posté 31 mai 2011 - 03:41
Or, check this out here, there is an example of making PlayCustomAnimation() into a wrapper function: http://nwn2.wikia.co...CustomAnimation
#3
Posté 31 mai 2011 - 07:09
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
Posté 31 mai 2011 - 09:45
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
Posté 31 mai 2011 - 09:49
_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
Posté 31 mai 2011 - 11:29
FYI: the function FaceAndPause() is from either ginc_wp or x0_i0_walkway. I can't remember which one right now.
#7
Posté 01 juin 2011 - 01:37
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
Posté 01 juin 2011 - 07:46
Keep it goin man
Modifié par Morbane, 01 juin 2011 - 07:47 .
#9
Posté 01 juin 2011 - 11:27
#10
Posté 01 juin 2011 - 11:29
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
Posté 01 juin 2011 - 04:14
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
Posté 01 juin 2011 - 05:00
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
Posté 01 juin 2011 - 05:09
I also wanted to see how many times I could get the word queue to show up in a thread... 12 and counting!
#14
Posté 01 juin 2011 - 07:54
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
Posté 02 juin 2011 - 04:45
I don't have the code with me. I'll post it later.
#16
Posté 04 juin 2011 - 08:45
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
Posté 04 juin 2011 - 11:46
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.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).
#18
Posté 04 juin 2011 - 06:30
ActionDoCommand(ApplyEffectToObject()), it works as intended, putting the application of the effect into the action queue.
#19
Posté 05 juin 2011 - 09:09
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
Posté 05 juin 2011 - 12:41
#21
Posté 05 juin 2011 - 06:12
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.)





Retour en haut






