- DAXON'S PAGE
- PERSO'S PAGE
- SGI'S PAGE
- SLADER'S PAGE
- VASJA'S PAGE
- TPTPT'S PAGE
- 01 - Get the good size
- 02 - Prepare the structure
- 03 - Textures
- 04 - Build the Skeleton
- 05 - Create new members
- 06 - Used Chiliskiner for rebuild skeleton
- 07 - Link skeleton
- 08 - Orientation of menbers
- 09 - Create Anchor
- 10 - Orientation of Anchor
- 11 - Link Anchor
- 12 - Finalise the character
- 13 - Add Edge for natural weapon
- PROSPERO'S PAGE
- 01 - Starting
- 02 - Stopping 'Ice Skating'
- 03 - A bit of boring theory
- 04 - Adding objects
- 05 - Weapons
- 06 - Enemies
- 07 - Controling enemies
- 08 - Trigger Sectors
- 09 - Cutscenes and camera stuff
- 10 - Sounds
- 11 - Doors
- 12 - De-bugging
- 13 - Sun, Water, Footsteps
- 14 - Gates
- 15 - Death of Enemies
- 16 - Classes
- 17 - Traps
- 18 - Torches
- 19 - New Races
- 20 - A Painless Way to Install New Objects
- 01 - BOD and 3DSMAX 2.5
- 02 - BOD and 3DSMAX 2.5
-
NEW CHARACTER TUTORIAL
-
BOD PYTHON SCRIPTING
BOD Python Scripting
15 - Death of Enemies
Sometimes you need to call a function when an enemy is killed. All chars have a function in their data that processes their deaths: launches death animation, drops their weapons, etc. You need to tap into this function. (It is called an ImDead func).
After enemy is created, add this after the creation code:
ork1.Data.OldImDeadFunc=ork1.ImDeadFunc ork1.ImDeadFunc= Ork1DED # In DefFuncs: def Ork1DED(entity) me=Bladex.GetEntity(entity) if me.Data.OldImDeadFunc(entity) me.Data.OldImDeadFunc(entity) print "Ork1 is dead..hahahahaha. Opening door" door1.OpenDoor()When "Ork1" is killed, "Door1" will open.
Little mention here about Scheduled functions. Sometimes you want to delay function call.
Bladex.AddScheduledFunc(Bladex.GetTime() + 5.0, door1.OpenDoor,())This will delay the call for 5.0 secs.
If the delayed function has arguments, put them in the (). (It is called a 'tuple' in Python.)
Bladex.AddScheduledFunc(Bladex.GetTime() + 5.0, OpenGate,(gate1din,))** don't forget the , after the args. (gate1din)) don't work.
But say you have group of enemies (3 Orks?) in a room. You can't get out and you have to slay them all before the exit door will open. This type of scenario occurs lots in the game. Ok, you use the ImDead
code above. BUT how do you know which one will die last? You can't rely on them being killed in order. The answer is use a variable as a counter:
Group1Orksdead = 0 # declare you var def Group1OrksDED(entity): global Group1Orksdead # declare the var as a global var me=Bladex.GetEntity(entity) if me.Data.OldImDeadFunc(entity) me.Data.OldImDeadFunc(entity) Group1Orksdead = Group1Orksdead +1 print "Another one bites the dust" if Group1Orksdead ==3: Bladex.AddScheduledFunc(Bladex.GetTime() + 5.0, door1.OpenDoor,()) print "Group1 Orks all dead - open exit door"Make it so that all three Orks have the Group1OrksDED func assigned to the ImDead routine. As each dies the function is called and the value of the Group1Orksdead var is increased by 1. As the last Ork is killed (don't matter which one) this value is increased to three and the 'if' clause becomes TRUE. The scheduled func is called and exit door opens 5.0 secs later.
Actually, there is a ready made method in darfuncs.py that does the same thing. I thought I would demostrate the counter principle as it is usefule in lots of other cases.
# define the group Group1Ork=darfuncs.E_Grup() Group1Ork.OnDeath= DoSomething # add enemies to group Group1Ork.AddGuy(ork1.Name) Group1Ork.OnDeath= DoSomething Group1Ork.AddGuy(ork2.Name) Group1Ork.OnDeath= DoSomething Group1Ork.AddGuy(ork3.Name) Group1Ork.OnDeath= DoSomethingThe DoSomething func is called when all group members are dead.