Triggering Python with a Region

Help bring our custom Ages to life! Share tips and tricks, as well as code samples with other developers.

Triggering Python with a Region

Postby GPNMilano » Thu Aug 28, 2008 11:25 pm

Hey, I know its possible to trigger a python script by entering a region, rather than use a clickable. (Or so I've been told it is) I was just curious as to what the tags are in alcscript for the region itself, as its not picking, is there another setting for a non picking region that activates python?
You can't stop the truth. IC Blog
User avatar
GPNMilano
 
Posts: 1155
Joined: Mon Apr 21, 2008 5:50 am

Re: Triggering Python with a Region

Postby Robert The Rebuilder » Fri Aug 29, 2008 4:38 am

Here's the AlcScript for the regions in Ahra Pahts that trigger the paging mechanism:

Code: Select all
Portal41To44:
    physical:
        physlogic: detect
    logic:
        modifiers:
          - tag: mod
            flags:
              - multitrigger
            activators:
              - type: objectinvolume
                triggers:
                  - enter
            conditions:
              - type: volumesensor
                satisfied: true
                direction: enter
            actions:
              - type: pythonfile
                ref: $click
        actions:
          - type: pythonfile
            tag: click
            pythonfile:
                file: PahtsPortal
                parameters:
                  - type: activator
                    ref: $mod
                  - type: string
                    value: Portal41To44
Can we rebuild it? Yes, we can - here's how.

MOULagain KI# 1299

Myst Movie coming soon - spread the word!
User avatar
Robert The Rebuilder
 
Posts: 1383
Joined: Sat Sep 29, 2007 7:24 am
Location: Virginia, US

Re: Triggering Python with a Region

Postby GPNMilano » Fri Aug 29, 2008 6:54 am

Thanks Robert, The Volume Sensor tag and conditions was what I was looking for. But I couldn't find it on the alcscript page.
You can't stop the truth. IC Blog
User avatar
GPNMilano
 
Posts: 1155
Joined: Mon Apr 21, 2008 5:50 am

Re: Triggering Python with a Region

Postby D'Lanor » Fri Aug 29, 2008 7:10 am

And if you need both the enter and exit trigger: viewtopic.php?f=18&t=1550

At home I also have the scripts for a nifty activatorlist (I am currently at work). ;)

Edit: Hmm, I spotted a difference with my script. I wonder if "enter" needs to be specified twice here: under objectinvolume and under volumesensor.

I think I have used scripts with and without those extra lines under objectinvolume and they all seem to work. :?
"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

Re: Triggering Python with a Region

Postby GPNMilano » Fri Aug 29, 2008 9:17 am

You know, I never thought to ask this, and perhaps I should. With the Python hook file for an age, the hook line is supposed to work like this:

Code: Select all
def __init__(self):
        ptResponder.__init__(self)
        self.id =
        self.version = 1


I always use the same self.id number, is that a problem? Or should each one be unique to an age?
You can't stop the truth. IC Blog
User avatar
GPNMilano
 
Posts: 1155
Joined: Mon Apr 21, 2008 5:50 am

Re: Triggering Python with a Region

Postby D'Lanor » Fri Aug 29, 2008 9:53 am

I never use the self.id and never had problems. A plasma object id is assigned automatically.

Here is a version I have used recently which has an activatorlist. Not for any reason in particular, just to try something different. :D It does come in handy when you need to call some of Cyan's global Python files.

AlcScript
Code: Select all
Door:
    logic:
        modifiers:
          - name: Enter_Door_Rgn
            cursor: nochange
            flags:
              - multitrigger
            activators:
              - type: objectinvolume
                remote: <door region>
                triggers:
                  - enter
            conditions:
              - type: volumesensor
                satisfied: true
                direction: enter
            actions:
              - type: pythonfile
                ref: :Pyth_Door
          - name: Exit_Door_Rgn
            cursor: nochange
            flags:
              - multitrigger
            activators:
              - type: objectinvolume
                remote: <door region>
                triggers:
                  - exit
            conditions:
              - type: volumesensor
                satisfied: true
                direction: exit
            actions:
              - type: pythonfile
                ref: :Pyth_Door
        actions:
          - type: pythonfile
            name: Pyth_Door
            pythonfile:
                file: <python file>
                parameters:
                  - type: activatorlist
                    refs: ['logicmod:Enter_Door_Rgn', 'logicmod:Exit_Door_Rgn']

The list items must have quotes. Since the script is not under the region object itself I defined the region as a remote. And I had to set the cursor to nochange otherwise it gives the door a hotspot.

Python code
Code: Select all
from Plasma import *
from PlasmaTypes import *
actDoorRegion = ptAttribActivator(1, 'Door region activator')

class <python file>(ptModifier,):

    def __init__(self):
        ptModifier.__init__(self)
        self.named = self.__class__.__name__



    def OnNotify(self, state, id, events):
        if (not state):
            return
        if (id == actDoorRegion.id):
            for event in events:
                if (event[0] == kCollisionEvent):
                    if event[1]:
                        PtDebugPrint('%s: OnNotify: id = %d: Someone entered the region' % (self.named, id))
                    else:
                        PtDebugPrint('%s: OnNotify: id = %d: Someone left the region' % (self.named, id))
                    break
"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

Re: Triggering Python with a Region

Postby GPNMilano » Fri Aug 29, 2008 10:36 am

D'Lanor, Okay, now here's a question. Exclude Regions are used to warp an avatar from one point to another open being in a region they're not supposed to be. (Like getting warped out from underneath a recently killed Bahro who's falling from the sky). Are exclude regions operational in pyprp yet. Since we're getting close to multiplayer age creation for things like doors, and other objects that are triggered by clickables or regions won't we need to have exclude regions set on these objects to warp any haphazard explorer who decides to, I don't know, play around in the inside of a machine as another explorer sets out to turn the thing on and bake whatever is inside of it till its fried to a crisp?
You can't stop the truth. IC Blog
User avatar
GPNMilano
 
Posts: 1155
Joined: Mon Apr 21, 2008 5:50 am

Re: Triggering Python with a Region

Postby D'Lanor » Fri Aug 29, 2008 12:13 pm

From what I can see the exregionmod has not been implemented.
"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 Scripting

Who is online

Users browsing this forum: No registered users and 4 guests