Region/xChatChannelRegion Questions

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

Region/xChatChannelRegion Questions

Postby DanTheMystFan » Sun Aug 22, 2010 11:20 am

I have two questions that hopefully someone can help me out with.

I'm building some rooms that are supposed to function like the private rooms in the Neighborhood, except my doors aren't supposed to open after a set time like the Neighborhood ones do. I'm using XChatChannelRegion inside the room. Two problems occur if someone decides to link to Relto from inside the room:

1. If everyone links to Relto, the door will stay shut. I check for this condition already when a player links in to the Age when no one else is there, but I'd like a more robust solution.

2. I remember in MOUL, if you linked out of the private rooms while the door was closed, it would break your chat. I assume this is the case on Alcugs as well.

One possible way I could fix the second problem is to disable the Relto book within the room, but I'd like to avoid that if possible. Is there some event I can run if someone links to Relto?

Thanks,
Dan
User avatar
DanTheMystFan
 
Posts: 24
Joined: Sat Aug 09, 2008 9:42 am

Re: Region/xChatChannelRegion Questions

Postby Branan » Wed Aug 25, 2010 8:58 am

DanTheMystFan wrote:...Is there some event I can run if someone links to Relto?

Thanks,
Dan


There's a BeginAgeUnLoad() function you can use in your ptResponder subclass. I'm not sure if that's early enough in the link out process to do what you need, though.
Image
Your friendly neighborhood shard admin
User avatar
Branan
Gehn Shard Admin
 
Posts: 694
Joined: Fri Nov 16, 2007 9:45 pm
Location: Portland, OR

Re: Region/xChatChannelRegion Questions

Postby diafero » Wed Aug 25, 2010 9:45 am

Alternatively, you can use the behaviour notifier - that's what I am using in Offline KI to do the magic to get GZ marker games working across ages.
Do this during init:
Code: Select all
PtGetLocalAvatar().avatar.registerForBehaviorNotify(self.key)


And then add this function
Code: Select all
    def OnBehaviorNotify(self, type, id, state):
        if (type == PtBehaviorTypes.kBehaviorTypeLinkOut) and state:
            # whatever code you want
I prefer e-mails to "diafero arcor de" (after adding the at and the dot) over PMs.

"Many people's horizon is a circle with a radius of zero. They call it their point of view."

Deep Island Shard | Offline KI
diafero
Deep Island Admin
 
Posts: 2806
Joined: Mon May 05, 2008 5:50 am
Location: Germany

Re: Region/xChatChannelRegion Questions

Postby DanTheMystFan » Fri Aug 27, 2010 1:07 pm

Thanks.

I *almost* have it working, except if I link to Relto from the room, I can see the door opening, but it isn't open when I link back in.

EDIT 8-29: I'M PRETTY SURE THIS CODE IS WRONG, NOT INCLUDING THIS PROBLEM. DO NOT USE.
Here's my Python for the region:
Code: Select all
from Plasma import *
from PlasmaTypes import *

Region = ptAttribActivator(2, 'Region')
SDLVarName = ptAttribString(3,'SDL Var Name')
MemberList = []
testObj = None
class LightPubPrivRoomControl(ptResponder):
    def __init__(self):
        ptResponder.__init__(self)
        #self.id = <insert ID here>
        self.version = 1
   
    def BeginAgeUnload(self, avObj):
        locAv = PtGetLocalAvatar()
        if(avObj == locAv):
            locAv.avatar.unregisterForBehaviorNotify(self.key)
           
    def OnBehaviorNotify(self, type, id, state):
        if (type == PtBehaviorTypes.kBehaviorTypeLinkOut) and state:
            self.RegionSub(PtGetLocalAvatar())
           
    def OnFirstUpdate(self):
        global AgeStartedIn
        AgeStartedIn = PtGetAgeName()
        PtGetLocalAvatar().avatar.registerForBehaviorNotify(self.key)

    def OnSDLNotify(self, VARname, SDLname, PlayerID, tag):
        if(VARname != SDLVarName.value):
            return
        if (AgeStartedIn != PtGetAgeName()):
            return
        ageSDL = PtGetAgeSDL()
        PtDebugPrint('DEBUG: LPPRC:OnSDLNotify:Door SDL has changed.')
   
    def OnServerInitComplete(self):
        if (AgeStartedIn == PtGetAgeName()):
            ageSDL = PtGetAgeSDL()
           

    def OnNotify(self, state, id, events):
        for event in events:
            print(event)
            if (event[0] != kCollisionEvent):
                continue
            if event[1]:
                self.RegionAdd(event[2])
            else:
                self.RegionSub(event[2])

   
    def RegionAdd(self, member):
        myID = PtGetClientIDFromAvatarKey(member.getKey())
        if (myID not in MemberList):
            MemberList.append(myID)
   
    def RegionSub(self, member):
        self.ageSDL = PtGetAgeSDL()
        myID = PtGetClientIDFromAvatarKey(member.getKey())
        print('Removing avatarID=%d from region' % myID)
        MemberList.remove(myID)
        #Check if anyone's left in region
        if (len(MemberList) == 0 and self.ageSDL[SDLVarName.value][0] == 1):
            self.ageSDL.setTagString(SDLVarName.value, 'auto')
            self.ageSDL[SDLVarName.value] = (0,)


Here's my Python for the doors (I temporarily set AutoOpen to false so I could test LightPubPrivRoomControl):
Code: Select all
from Plasma import *
from PlasmaTypes import *

SDLVarName = ptAttribString(1,'SDL Var Name')
OpenResp = ptAttribResponder(2,'Open Responder')
CloseResp = ptAttribResponder(3,'Close Responder')
AutoOpen = ptAttribBoolean(4,'Force Open if Age Empty')
class LightPubDoorControl(ptResponder):
    def __init__(self):
        ptResponder.__init__(self)
        #self.id = <insert ID here>
        self.version = 1

           
    def OnFirstUpdate(self):
        pass


    def OnServerInitComplete(self):
        global AutoOpen     
        print('Light Pub Python running')
        self.ageSDL = PtGetAgeSDL()
        self.ageSDL.setFlags(SDLVarName.value,1,1)
        self.ageSDL.sendToClients(SDLVarName.value)
        self.ageSDL.setNotify(self.key,SDLVarName.value,0)

        if(AutoOpen.value):
            print("AutoOpen is true")
            if (len(PtGetPlayerList()) == 0):
                print("I'm the only one here")
                if(self.ageSDL[SDLVarName.value][0] == 1):
                    print("I'm the only one here, so opening closed door")
                    self.ageSDL[SDLVarName.value] = (0,)
                    self.ageSDL.setTagString(SDLVarName.value, ' ')
                    print(self.ageSDL[SDLVarName.value])
                else:
                    print('Door is open, so doing nothing')
            else:
                print('There is more than one player in the age -- proceeding as normal')

           
        if(self.ageSDL[SDLVarName.value][0] == 1):
            CloseResp.run(self.key, fastforward=1)
        else:
            OpenResp.run(self.key, fastforward=1)   


    def OnNotify(self, state, id, events):
        pass
 
           
       
    def OnSDLNotify(self, VARname, SDLname, playerID, tag):
        if (SDLname !='LightPub'):
            pass
        else:
            print('LightPubDoorControl: OnSDLNotify called for ')
            print(VARname)
            self.ageSDL = PtGetAgeSDL()
            if tag == 'avatar' and playerID:
                Av = ptSceneobject(PtGetAvatarKeyFromClientID(playerID), self.key)
                ff = 0
            elif tag == 'auto':
                Av = None
                ff = 1
            else:
                Av = None
                ff = 1
            if (VARname ==  SDLVarName.value):
                if(self.ageSDL[SDLVarName.value][0] == 1):
                    print('Running responder to close door')
                    CloseResp.run(self.key, avatar=Av, fastforward = ff)
                else:
                    print('Running responder to open door')
                    OpenResp.run(self.key, avatar=Av, fastforward = ff)
Last edited by DanTheMystFan on Sun Aug 29, 2010 2:26 pm, edited 2 times in total.
User avatar
DanTheMystFan
 
Posts: 24
Joined: Sat Aug 09, 2008 9:42 am

Re: Region/xChatChannelRegion Questions

Postby diafero » Sat Aug 28, 2010 3:30 am

So, does it set the SDL correctly? You can read it using "/getsdl varname".

A problem could be that, if I remember correctly, the current age information is already set to the target age when you link out, so maybe these "AgeStartedIn != PtGetAgeName()" checks (of which I never understood the purpose anyway) are failing on you. I suggest using PtPrintToScreen('text') to check what exactly is happening in which order and what not during link-out.
I prefer e-mails to "diafero arcor de" (after adding the at and the dot) over PMs.

"Many people's horizon is a circle with a radius of zero. They call it their point of view."

Deep Island Shard | Offline KI
diafero
Deep Island Admin
 
Posts: 2806
Joined: Mon May 05, 2008 5:50 am
Location: Germany

Re: Region/xChatChannelRegion Questions

Postby DanTheMystFan » Sat Aug 28, 2010 8:19 am

The weird thing is, it works perfectly if you spawn or flymode out of the region, but not if you link out. In all cases, the door opens, but the SDL variable only persists on the next visit if you *didn't* link out the last time.

If this is just a consequence of the age being empty, my other check will fix that problem.

Also, will this code cause multiple players to request the same SDL change? I never quite understood when that happened and when it didn't.
User avatar
DanTheMystFan
 
Posts: 24
Joined: Sat Aug 09, 2008 9:42 am

Re: Region/xChatChannelRegion Questions

Postby D'Lanor » Sat Aug 28, 2010 8:29 am

DanTheMystFan wrote:2. I remember in MOUL, if you linked out of the private rooms while the door was closed, it would break your chat. I assume this is the case on Alcugs as well.

One possible way I could fix the second problem is to disable the Relto book within the room, but I'd like to avoid that if possible. Is there some event I can run if someone links to Relto?

Thanks,
Dan

Wouldn't it be better to tackle the problem at the source? xChatChannelRegion can be fixed. It fails because the global variable AreWeInRoom is not set to 1 due to a missing global statement. I'm not sure why Python does not throw the error it normally does when that happens.

Anyway, this is the fix.
xChatChannelRegion.zip
(3.56 KiB) Downloaded 144 times

The included logfile from Uru:CC shows that we are now correct removed from the private chat channel during the page unload (and not by that same routine duplicated under __del__ which is executed first).

If this could be added to the Offline KI we'd have Alcugs covered. This same file does the trick for MOUL but that is out of reach for now.
"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: Region/xChatChannelRegion Questions

Postby diafero » Sat Aug 28, 2010 8:37 am

Be careful with using Flymode, it disabled physics so taht the engine does not notice region changes. Better use /spawn, /a, /jump or similar for testing.

So, did you try and create some debug log? Without knowing what is actually going on, I can't tell anything, sorry. Me best guess currently is that "self.ageSDL = PtGetAgeSDL()" might actually get the SDL for the target age already when you link out, so you should better store the SDL somewhere when initializing the Python File Mod. it could however also be that the offline vault already stored the SDL and does not make any further changes, in which case the behaviour would be differently online.

Also, will this code cause multiple players to request the same SDL change? I never quite understood when that happened and when it didn't.
That's a good question ;-) . The link-out behaviour mod will only be triggered for your avatar, since you registered only for it. In the OnNotify code, you should add some "if PtWasLocallyNotified(self.key)" because otherwise this will trigger if someone else left/entered the region. For the rest... I don't know ;-)

Also, what D'Lanor said - I will add that patch to the next Offline KI. The reason why there is no error is that the variable is only written to, which implicitly creates a new one in Python.
I prefer e-mails to "diafero arcor de" (after adding the at and the dot) over PMs.

"Many people's horizon is a circle with a radius of zero. They call it their point of view."

Deep Island Shard | Offline KI
diafero
Deep Island Admin
 
Posts: 2806
Joined: Mon May 05, 2008 5:50 am
Location: Germany

Re: Region/xChatChannelRegion Questions

Postby DanTheMystFan » Sat Aug 28, 2010 9:07 am

Here's a partial log--I hope it's enough. I moved some print statements around and called RegionSub a few more places as well. I also added a check to RegionSub to only subtract the avatar if it's there (I wasn't sure if the errors stopped the rest of the code from running.)
I wrote notes where applicable. The two look identical to me.

Code: Select all
Linking in, closing door, and /spawning out:

(08/28 11:42:22) DEBUG: xAgeSDLBoolToggle.OnServerInitComplete():   PrivRoom4DoorClosed = 0
(08/28 11:42:34) DEBUG: xAgeSDLBoolToggle.OnNotify():    local player requesting PrivRoom4DoorClosed change via PrivRoom4Btn_B4Click
(08/28 11:42:34) DEBUG: xAgeSDLBoolToggle.OnNotify():   set age SDL var PrivRoom4DoorClosed to 1
(08/28 11:42:34) DEBUG: XChatChannel:OnSDLNotify:   closing door
(08/28 11:42:34) DEBUG: xAgeSDLBoolToggle.OnSDLNotify():    VARname:PrivRoom4DoorClosed, SDLname:LightPub, tag:avatar, value:1
(08/28 11:42:34) LightPubDoorControl: OnSDLNotify called for
(08/28 11:42:34) PrivRoom4DoorClosed
(08/28 11:42:34) Running responder to close door
(08/28 11:42:34) LPDC OnSDLNotify done
(08/28 11:42:39) Removing avatarID=20001 from region
(08/28 11:42:39) No one's in the region, so I'm opening the door
(08/28 11:42:39) DEBUG: XChatChannel:OnSDLNotify:   opening door
(08/28 11:42:39) DEBUG: xAgeSDLBoolToggle.OnSDLNotify():    VARname:PrivRoom4DoorClosed, SDLname:LightPub, tag:auto, value:0
(08/28 11:42:39) LightPubDoorControl: OnSDLNotify called for
(08/28 11:42:39) PrivRoom4DoorClosed
(08/28 11:42:39) Running responder to open door
(08/28 11:42:39) LPDC OnSDLNotify done
[Back to Relto]

Linking back, closing door, and linking to Relto from inside the room:
Door is open this time on link

(08/28 11:43:25) DEBUG: xAgeSDLBoolToggle.OnServerInitComplete():   PrivRoom4DoorClosed = 0
(08/28 11:43:37) DEBUG: xAgeSDLBoolToggle.OnNotify():    local player requesting PrivRoom4DoorClosed change via PrivRoom4Btn_B4Click
(08/28 11:43:37) DEBUG: xAgeSDLBoolToggle.OnNotify():   set age SDL var PrivRoom4DoorClosed to 1
(08/28 11:43:37) DEBUG: XChatChannel:OnSDLNotify:   closing door
(08/28 11:43:37) DEBUG: xAgeSDLBoolToggle.OnSDLNotify():    VARname:PrivRoom4DoorClosed, SDLname:LightPub, tag:avatar, value:1
(08/28 11:43:37) LightPubDoorControl: OnSDLNotify called for
(08/28 11:43:37) PrivRoom4DoorClosed
(08/28 11:43:37) Running responder to close door
(08/28 11:43:37) LPDC OnSDLNotify done
(08/28 11:43:44) Removing avatarID=20001 from region
(08/28 11:43:44) No one's in the region, so I'm opening the door
(08/28 11:43:44) DEBUG: XChatChannel:OnSDLNotify:   opening door
(08/28 11:43:44) DEBUG: xAgeSDLBoolToggle.OnSDLNotify():    VARname:PrivRoom4DoorClosed, SDLname:LightPub, tag:auto, value:0
(08/28 11:43:44) LightPubDoorControl: OnSDLNotify called for
(08/28 11:43:44) PrivRoom4DoorClosed
(08/28 11:43:44) Running responder to open door
(08/28 11:43:44) LPDC OnSDLNotify done
[Link to Relto]

Linking back
Note:  Door is closed this time on link

(08/28 11:44:10) DEBUG: xAgeSDLBoolToggle.OnServerInitComplete():   PrivRoom4DoorClosed = 1



EDIT: I forgot to mention that I checked the age name in RegionSub, and it was correct.
EDIT2: I was a bit overzealous in what I removed.d
User avatar
DanTheMystFan
 
Posts: 24
Joined: Sat Aug 09, 2008 9:42 am

Re: Region/xChatChannelRegion Questions

Postby DanTheMystFan » Sun Aug 29, 2010 2:23 pm

Sorry for the double post, but I'm pretty sure I screwed up the code from looking at other examples. From what I can see, it will not work in multiplayer. I'm going to try to fix it and then test it on one of the shards to see if it works.

--Dan
User avatar
DanTheMystFan
 
Posts: 24
Joined: Sat Aug 09, 2008 9:42 am


Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest