Prospero's pages

Updated October 24, 2005



Tut8. Trigger Sectors.

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

import Bladex

at the top and exec it in 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:

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

def UnhideOrk1(sector,entity):

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 '

def UnhideOrk1(sector,entity):
    # Check it is the Player
    if entity == "Player1":

== 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 in 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:

def UnhideOrk1(sector,entity):
    if entity == "Player1":
        # Add this bit

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.
GS 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 GS later.

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

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

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


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