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

You can put the code for trigger sectors in any *.py file

Posted by on - Basic Client Side Coding

Tut8. Trigger Sectors.

You can put the code for trigger sectors in any *.py file (NOT DefFuncs.py) I like to put them all in a seperate file (triggers.py?)

import Bladex
at the top and exec it in cfg.py as with others.

Ok, say you have an Ork 'hidden' around a corner. You want to 'unhide' him as the Player rounds the corner. Select a sector that the Player will enter out of veiw from the place where the Ork is 'hidden'. Note the sector coords. You need a point anywhere within the sector (somewhere near the middle?) .

To assign a function use this:

python code:
sect_ork1=Bladex.GetSector(10000,  -3000, -550000)
sect_ork1.OnEnter= UnhideOrk1

The details about the sector are contained in the variable sect_ork1
and the function UnhideOrk1 bound to it.

Define the function in DefFuncs:

python code:
def UnhideOrk1(sector,entity):
    darfuncs.UnhideBadGuy("Ork1")

Notice that the function will expect two arguments. The Enter Sector
Event will pass two parameters to the function: the sector id and the id of the entity that enters. There is a glitch here. As the function stands, it will be triggered by any entity that enters the sector. This could be an wandering enemy, a stray arrow or flying limb. To cure this, it is time to introduce the concept of the 'if'.

---------------------------------------------------------------------

python code:
def UnhideOrk1(sector,entity):
    # first, 'get' the info on the entity and assign to a var
    per= Bladex.GetEntity(entity)
    # Check it is the Player
    if per == "Player1":
        darfuncs.UnhideBadGuy("Ork1")
    else:
        pass


-------------------------------------------------------------------
Enormous Mistake Here The code above in yellow is wrong. It should be:

python code:
def UnhideOrk1(sector,entity):
    # Check it is the Player
    if entity == "Player1":
        darfuncs.UnhideBadGuy("Ork1")
    else:
        pass

Apologies to all who have been wondering why their Ork doesn't appear.
I have only used this code about a million times and I still screwed up. (There is a moral to this story, but I can't think what it is.)
-------------------------------------------------------------------

The == is a 'comparision operator'.(NOT the same as =). It means 'is equal to'. Others are:

!= Is not equal to
> Is greater than
< Is less than

What happens is, the argument 'entity', that is the thing that enters the sector is compared after the 'if' to "Player1".
If it does equal "Player1" then the indented code that follows is executed and the Ork is unhidden. If it is not "Player1", then the comparision is False and Python will skip the code and move to the 'else', which in this case has a pass statement. This tells Python to do nothing. (The 'else' clause is not strictly necessary. It can be omitted)

There is one other glitch with the function as it is. The function will be called everytime the sector is entered by the Player. This is bad, because the Ork only needs to be unhidden once. Next time the sector is entered, he will probably be dead.

You must cancel the function after it is called:

python code:
def UnhideOrk1(sector,entity):
        if entity == "Player1":
                darfuncs.UnhideBadGuy("Ork1")
                # Add this bit
                sect_ork1.OnEnter=None
        else:
                pass


That's it.

Another form of sector is the 'Ghost Sector' These areas in the map that are defined purely in script. You can use the tools in LED to define them and save the code settings, but they have no affect on the structure of the map. They are not compiled as info in the .bw file. They are defined in files with the ext .sf.
Ghost Sectors are used widely to assign sounds (wind, etc) to a wide area, but they can be assigned OnEnter / OnLeave events like ordinary sectors. This is often convienient where map sectors don't quite fit in with what you want, of you need to cover a wide area that would need assigning triggers to many sectors (this can get complicated).
I'll come back to Ghost Sestors later.

btw. You can't assign two functions to the same sector. There is a function in darfuncs that is sometimes handy for triggers:

python code:
darfuncs.EnterSectorEvent(67400, 7000, 8750,  DoSomething)


When the sector is entered (only by Player) is entered the function 'DoSomething' is called and the assignment cancelled. The advantage of using the first method is that sometimes you want other
NPcs to tigger things (if per== "Glofror") of you may want to assign another function to the sector later, once the first has been called.

More useful conditionals......

python code:
def DemoFunc1(entity):
    per=Bladex.GetEntity(entity)
    # check race
    if per.Kind=="Ork":
        # Check he is still alive
        if per.Life>0:
            # Check his weapon
            if per.InvRight == "Ork1WP":
                DoSomething()
    elif per.Kind=="Knight_Traitor" and pers.Life>0:
        if per.Level<7:
                DoAntherThing()
    else:
        DoSomethingCompletelyDifferent()

DemoFunc1("Enemy1")

In the above function an entity id is passed in the function call. His Kind is first checked. If he is an Ork his life is checked. If he is alive his weapon is checked. If all these conditions are True, the DoSomething func is called and the function ends. However, if he is not an Ork the first condition is False and Python skips to the 'elif' clause (you can have lots of elifs). If the entity id a Knight_Traitor and he is alive, his Level is checked and DoAnotherThing func is called and the function ends. But if the entity is neither Ork nor Knight, Python will skip these clauses and go to the else clause and DoSomethingCompletelyDifferent func is called.

Notice how clauses can be nested and several conditions can be put on one line using the 'and'. (Watch the indentation.)

Post a comment

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