Attaching Python script to a region

Special tutorials, usually for the exporter plugin, but also general modeling tutorials.

Attaching Python script to a region

Postby D'Lanor » Tue Apr 15, 2008 4:50 am

This subject came up in another thread but since it is generally useful I am reposting it here.

PyPRP can easily assign sounds to regions, but wouldn't it be nice if you could trigger other events with a region? Below is the code to hook up a Python script to a region. With Python code we have a wide range of possibilities at our disposal. Anything that can be done with Python can be tied to a region this way.

Only the basic principle is given here. There are no examples but I will probably refer to this small tutorial in other posts.


The Alcscript:
Code: Select all
<region>:
    logic:
        modifiers:
          - tag: Enter_Rgn
            flags:
              - multitrigger
            activators:
              - type: objectinvolume
            conditions:
              - type: volumesensor
                satisfied: true
                direction: enter
            actions:
              - type: pythonfile
                ref: $Region
          - tag: Exit_Rgn
            flags:
              - multitrigger
            activators:
              - type: objectinvolume
            conditions:
              - type: volumesensor
                satisfied: true
                direction: exit
            actions:
              - type: pythonfile
                ref: $Region
        actions:
          - type: pythonfile
            tag: Region
            pythonfile:
                file: <pythonfile>
                parameters:
                  - type: activator
                    ref: logicmod:$Enter_Rgn
                  - type: activator
                    ref: logicmod:$Exit_Rgn


The basic Python code:
Code: Select all
from Plasma import *
from PlasmaTypes import *
actEnter = ptAttribActivator(1, 'Enter region activator')
actExit = ptAttribActivator(2, 'Exit region activator')

class <pythonfile>(ptModifier,):

    def OnNotify(self, state, id, events):
        if (not PtWasLocallyNotified(self.key)):
            return
        if ((id == actEnter.id) and state):
            #start enter event here
        elif ((id == actExit.id) and state):
            #start exit event here
"It is in self-limitation that a master first shows himself." - Goethe
User avatar
D'Lanor
 
Posts: 1980
Joined: Sat Sep 29, 2007 4:24 am

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 0 guests

cron