News:

Happy 20th, FFvT3R!

Main Menu

Hero Point Revival

Started by bearded, May 09, 2022, 12:42:08 PM

Previous topic - Next topic

bearded

I was browsing through script document and came across the revive code. I've always been annoyed by getting KO'ed when you have points left. Looking at some other code, I put this together.
def OnHeroDeath(event):
        ahero=event.object
        if Object_GetAttr(ahero, 'heroPoints') > 0:
            revive(ahero)
            newheropoints = Object_GetAttr(ahero, 'heroPoints') - 1
            Object_SetAttr(ahero, 'heroPoints', newheropoints)
        else:
            Object_Destroy(ahero)

This works. Destroy is there to open a spot to spawn a replacement hero. It happens instantly. How to slow it down for a pip?

Epimethee

Nice one, Bearded!

I imagine that mission-critical character deaths (ex.: last hero standing) would still usually cause a game over. But overcoming that problem reliably is probably not worth the trouble.

QuoteHow to slow it down for a pip?
This should do the trick if using FFX:

else:
            RegTimer('Object_Destroy',4.0,0,ahero)


For non-FFX, it's slightly more verbose:

else:
            js.Event_RegisterSink(EVENT_TIMER, 'Object_Destroy', ahero, '', 4.0, 0, 0)


FWIW, destroying the object could have consequences in certain missions or, in FFvsTTR, prevent resurrection powers.
FFX add-on for FFvsTTR at ffx.freedomforce4ever.com

bearded

I'll try it tonight. I'm wondering, if I have this in a file named CodeSnip.py, could I import it by adding import CodeSnips to mission files? Or do I need the word from *?

Epimethee

Yes, you could use an import statement. Using the asterisk from * import module_name format simply means that you wouldn't have to prefix imported functions with their module name.

import codesnip
...
codesnip.function_name()

vs
import codesnip
from codesnip import *
...
function_name()


The * form is really not recommended (cue music: we were young and naive, and the Python language was very much in its infancy; it's now one of the 2-3 most popular programming languages). It causes problems if you have two modules with the same function name. In addition, modern programming editors offer autocomplete when you prefix the function name.

I also suggest keeping your file names all lowercase, as Python is case sensitive and Windows isn't really.
FFX add-on for FFvsTTR at ffx.freedomforce4ever.com