Blade of Darkness holds true to the greatest of hack and slash legends, combining sorcery, knights, and swords with god forsaken enemies that deserve to have their arms slashed off with a broadsward. Blade of Darkness looked excellent in 2001, and still delivers its gore well today. Holding True to it's genre it offers modders both custom maps and scripts. Relevent Links Fansite Mod List Modding Community

Post tutorial Report RSS Level Editing Scripting by Prospero. Part. 14

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).

Posted by on - Basic Client Side Coding

Tut15. 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:

python code:
ork1.Data.OldImDeadFunc=ork1.ImDeadFunc
ork1.ImDeadFunc= Ork1DED

# In DefFuncs:

python code:
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.

python code:
Bladex.AddScheduledFunc(Bladex.GetTime() + 5.0,  door1.OpenDoor,())


This will delay the call for 5 secs.

If the delayed function has arguments, put them in the (). (It is called a 'tuple' in Python.)

python code:
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:

python code:
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 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.

python code:
# 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= DoSomething

The DoSomething func is called when all group members are dead.

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: