Freedom Reborn Archive

Freedom Force Forums => Scripting Forum => Topic started by: Urthman on March 01, 2007, 12:40:51 PM

Title: Adding a timed delay to an event?
Post by: Urthman on March 01, 2007, 12:40:51 PM
I'm gonna give some context to this.  There maybe a step where someone can say, "Hey why don't you do that this easier way.."

1.  I'm working with the weaponmaster code in ffxextras.py.

2.  I was having trouble getting some of the carriers to take.  For instance, I can get my weapons to successfully use a hex power swapped to reverse gravity, but I can't get a weapon to swap rally to heal.   (Could it be because the character using the weapon already has a rally power swapped to something else?)

3. So I decided to just hard-code some of the powers.  Instead of calling a built-in rally power and swapping it to heal, I cut-n-pasted the healing code from the medpack in the utility belt attribute.

4.  That worked perfectly, but then I wanted to add a dummy power to give it some FX.

5.  Dummy power works fine, but the healing happens too fast.  The target gets healed before the dummy power hits him.

6.  So can I add maybe a 3 second delay to the healing so it would happen after the power FX is done?  I know about stumpy's RegTimer2 code in the ffx.py file, but it looks like I'd have to copy over a bunch of other stuff from ffx.py in order to make it work?

7.  Any reason the weaponmaster code has to be in ffxextras?  Could I just put it at the end of my (already modified) ffx.py file?  That way it could call any function ffx.py uses?
Title: Re: Adding a timed delay to an event?
Post by: stumpy on March 01, 2007, 05:52:33 PM
Just checking that your character is a built-in, right? Otherwise, what you mention in 2 is likely the problem.

Meanwhile, it's a little tough to tell without seeing your code, but are you calling the dummy power with Trigger_Power()? If so, the fourth argument is a function that runs after the power runs, so it's great to use when you are want to do something after a power runs but you don't want to have to fine tune the timing to get it to look right.
Title: Re: Adding a timed delay to an event?
Post by: Urthman on March 01, 2007, 07:41:13 PM
What I currently have is this:


def OnUseffx_bookspell_2(target,char):
    ffx.OnUseWeapon(target,char,'ffx_spellbook','ffx_bookspell_2')
    if Object_GetSecondaryStates(target)&(SCSTATE_IRRADIATED|SCSTATE_ACID_BURNT):
        Object_SetSecondaryState(target,SCSTATE_IRRADIATED,0,REMOVE_STATE)
        Object_SetSecondaryState(target,SCSTATE_ACID_BURNT,0,REMOVE_STATE)
    healpts=Object_GetAttr(char,'energyPoints')
    Trigger_Damage(target,-healpts)


This successfully heals the target an amount equal to the spellcaster's energy points.  And uses the dummy power "ffx_bookspell_2" about 3 seconds after the target is healed.  :rolleyes:

Maybe a better way would be something like this?


def HealSpell(target,char):
    if Object_GetSecondaryStates(target)&(SCSTATE_IRRADIATED|SCSTATE_ACID_BURNT):
        Object_SetSecondaryState(target,SCSTATE_IRRADIATED,0,REMOVE_STATE)
        Object_SetSecondaryState(target,SCSTATE_ACID_BURNT,0,REMOVE_STATE)
    healpts=Object_GetAttr(char,'energyPoints')
    Trigger_Damage(target,-healpts)

def OnUseffx_bookspell_2(target,char):
     Trigger_Power(target, char, ' ffx_bookspell_2', 'HealSpell')


And yes, this is all using built-in characters.

Darn it, now you've made me break my vow to finish this mod without reading FF Scripting.doc.
Object_SetPrimaryState('can_of_worms', 'open')
Title: Re: Adding a timed delay to an event?
Post by: stumpy on March 01, 2007, 08:34:13 PM
There's a little more to it than that. First, there is an extra space in OnUseffx_bookspell_2() before ffx_bookspell_2.

The other thing is that a callback from a Trigger_Power() is a normal event callback. You will want to declare it as def HealSpell(event): and the target is event.object while char is event.string.

That will get you off the ground, but I don't know how exactly you want this to work. For example, you don't have anything that will remove a charge from the user, remove custom commands when the charges are gone, etc.

BTW, there is a good chance the weapon code would do all of that for you. But I have never tried to use it with a swap (or at all). Someone else is probably more familiar with how it works.
Title: Re: Adding a timed delay to an event?
Post by: Urthman on March 01, 2007, 08:56:29 PM
Heh.  I actually caught that typo when I was cut-n-pasting this to try it out (which I haven't yet, good thing too, apparently).

You're right about making this do all the weapon-related stuff.  I'm pretty sure I need to keep something like this in there:

ffx.OnUseWeapon(target,char,'ffx_spellbook','ffx_dummypower')

But what I could do is, as suggested by the name, use a dummy power there and do the actual healing by hardcoding it this way.  Does this look better?


def HealSpell(event):
    if Object_GetSecondaryStates(event.object)&(SCSTATE_IRRADIATED|SCSTATE_ACID_BURNT):
        Object_SetSecondaryState(event.object,SCSTATE_IRRADIATED,0,REMOVE_STATE)
        Object_SetSecondaryState(event.object,SCSTATE_ACID_BURNT,0,REMOVE_STATE)
    healpts=Object_GetAttr(event.string,'energyPoints')
    Trigger_Damage(event.object,-healpts)

def OnUseffx_bookspell_2(target,char):
    ffx.OnUseWeapon(target,char,'ffx_spellbook','ffx_dummypower')
    Trigger_Power(target,char,'ffx_bookspell_2','HealSpell')


To be clear, in the example above, ffx_dummypower is a do-nothing power with invisible FX.  ffx_bookspell_2 is a do-nothing power with the FX I want shown.  HealSpell does the actual healing.

Seems a little rube-goldburg.  I wonder if I could somehow stick the HealSpell function into the ffx.OnUseWeapon command?
Title: Re: Adding a timed delay to an event?
Post by: Urthman on March 02, 2007, 05:01:17 PM
Hmm.  That doesn't work.  The weaponmaster character gets healed instead of the target.  After looking at some of the other code in ffx.py, I thought this might fix it:

def HealSpell(event):
    char=event.string
    target=event.object
    if Object_GetSecondaryStates(event.object)&(SCSTATE_IRRADIATED|SCSTATE_ACID_BURNT):
        Object_SetSecondaryState(event.object,SCSTATE_IRRADIATED,0,REMOVE_STATE)
        Object_SetSecondaryState(event.object,SCSTATE_ACID_BURNT,0,REMOVE_STATE)
    healpts=Object_GetAttr(event.string,'energyPoints')
    Trigger_Damage(event.object,-healpts)

def OnUseffx_bookspell_2(target,char):
    ffx.OnUseWeapon(target,char,'ffx_spellbook','ffx_bookspell_2')
    Trigger_Power(target,char,'ffx_bookspell_2','HealSpell')


But no, same thing.  The 'char' gets healed instead of the 'target'.
Title: Re: Adding a timed delay to an event?
Post by: stumpy on March 02, 2007, 07:07:07 PM
Hmm. Maybe you can print out event.string and event.object from within HealSpell(). E.g.
    print 'HealSpell: event.object=%s event.string=%s' % (repr(event.object),repr(event.string))
I did a quick check in FFvT3R using ffx_sustain_urban_beam as the dummy power and it looked like attacker and target were assigned properly, but maybe it doesn't work right in FF...