Show/Hide Object Based on Time of Day

If you feel like you're up to the challenge of building your own Ages in Blender or 3ds Max, this is the place for you!

Re: Show/Hide Object Based on Time of Day

Postby Tsar Hoikas » Tue Nov 29, 2011 8:43 pm

OnServerInitComplete is called when the age's state is first available during each (and every) link process. This state is fetched from the server, hence the method name. It is important to NOT call any function or instantiate any object that requires data from the server until this method is called! In other words, don't do PtGetAgeSDL() or ptVault() in __init__ or OnFirstUpdate

OnFirstUpdate is called the first time the script is evaluated.

OnServerInit ... does not exist.

Therefore, you would have calls that look something like:
  • __init__
  • OnFirstUpdate
  • OnServerInitComplete
  • On Notify
    ...
  • OnServerInitComplete
  • On Notify
    ...

These are your callback functions. OnBackdoorMsg will not work unless you have an Internal client, btw. Futhermore, anything listed after OnAvatarSpawn (except for gotPublicAgeList) does not exist in PotS/UU.

Code: Select all
const char* plPythonFileMod::fFunctionNames[] =
{
    "OnFirstUpdate",        // kfunc_FirstUpdate
    "OnUpdate",             // kfunc_Update
    "OnNotify",             // kfunc_Notify
    "OnTimer",              // kfunc_AtTimer
    "OnControlKeyEvent",    // kfunc_OnKeyEvent
    "Load",                 // kfunc_Load
    "Save",                 // kfunc_Save
    "OnGUINotify",          // kfunc_GUINotify
    "OnPageLoad",           // kfunc_PageLoad
    "OnClothingUpdate",     // kfunc_ClothingUpdate
    "OnKIMsg",              // kfunc_KIMsg,
    "OnMemberUpdate",       // kfunc_MemberUpdate,
    "OnRemoteAvatarInfo",   // kfunc_RemoteAvatarInfo,
    "OnRTChat",             // kfunc_RTChat,
    "OnVaultEvent",         // kfunc_VaultEvent,
    "AvatarPage",           // kfunc_AvatarPage,
    "OnSDLNotify",          // kfunc_SDLNotify
    "OnOwnershipChanged",   // kfunc_OwnershipNotify
    "OnAgeVaultEvent",      // kfunc_AgeVaultEvent
    "OnInit",               // kfunc_Init,
    "OnCCRMsg",             // kfunc_OnCCRMsg,
    "OnServerInitComplete", // kfunc_OnServerInitComplete
    "OnVaultNotify",        // kfunc_OnVaultNotify
    "OnDefaultKeyCaught",   // kfunc_OnDefaultKeyCaught
    "OnMarkerMsg",          // kfunc_OnMarkerMsg,
    "OnBackdoorMsg",        // kfunc_OnBackdoorMsg,
    "OnBehaviorNotify",     // kfunc_OnBehaviorNotify,
    "OnLOSNotify",          // kfunc_OnLOSNotify,
    "BeginAgeUnLoad",       // kfunc_OnBeginAgeLoad,
    "OnMovieEvent",         // kfunc_OnMovieEvent,
    "OnScreenCaptureDone",  // kfunc_OnScreenCaptureDone,
    "OnClimbingBlockerEvent",// kFunc_OnClimbingBlockerEvent,
    "OnAvatarSpawn",        // kFunc_OnAvatarSpawn
    "OnAccountUpdate",      // kFunc_OnAccountUpdate
    "gotPublicAgeList",     // kfunc_gotPublicAgeList
    "OnGameMgrMsg",         // kfunc_OnGameMgrMsg
    "OnGameCliMsg",         // kfunc_OnGameCliMsg
    "OnAIMsg",              // kfunc_OnAIMsg
    nil
};
Image
Tsar Hoikas
Councilor of Technical Direction
 
Posts: 2180
Joined: Fri Nov 16, 2007 9:45 pm
Location: South Georgia

Re: Show/Hide Object Based on Time of Day

Postby Christopher » Wed Nov 30, 2011 2:49 am

TheMagician wrote:And one more question: how can I trigger a Python script by clicking on an object in the scene? As far as I can tell there is no way of calling a Python script from a responder.


If you want that, you have to give a Detector (or Activator) to Python. In our scripts you have a line called "RespDoorAppear = ptAttribResponder(1, 'Resp: Door appears')". If you want to have an Activator you have to use "ptAttribActivator" instead. If you then click the on the Activator (or enter a region) a so called Notify with the ID you specified behind the ptAttribActivator is send to your pythonfile. If your file received the Notify it starts the def "OnNotify".

Here a short example:
Code: Select all
from Plasma import *
from PlasmaTypes import *

Mixbut1     = ptAttribActivator(1,"Mixerbutton1") # Variablename = ptAttribActivator(ID, String in 3DS Max)

class ercafix(ptResponder):
   
    def __init__(self):
        ptResponder.__init__(self)
        self.id = 5920
        self.version = 1
   
    def OnNotify(self,state,id,events):
       
        if (id == 1): #The ID you specified in the ptAttribActivator
            PtConsole("logic.TriggerDetector cClkMixerBtn1") #What you want to do when your Activator is triggered

I hope you understand me, I am not so good in explaining stuff ;)

EDIT: I forgot the callbackfunctions:
Hoikas already listed them all, but here some explanations to some of the functions:
OnGUINotify - This is used if you press a button or something like that in an GUI.
AvatarPage - This def is executed if an avatar is linking in your age (this includes yourself)
OnVaultNotify - it's like OnSDLNotify, but for the Vault
OnDefaultKeyCaught - It's like OnControlKeyEvent, but for all keys on your keyboard. The problem with it is, that all time I use this command I can't write Chatmessages anymore.
OnBehaviorNotify - It's like OnSDLNotify, but for Avataranimations. You can register a special Action for the avatar (for example Linking out). If your Avatar does this action, this function is executed
BeginAgeUnLoad - This is executed when your age is unloaded, but on this time, you can't make something with the age anymore (because it is unloaded)
OnAccountUpdate - I am not exactly sure about this, but I think this is executed if you change your password, Accountname or active player

That's all I know about. If something is wrong, please correct me.

Christopher
User avatar
Christopher
 
Posts: 276
Joined: Mon Jul 19, 2010 3:25 am

Re: Show/Hide Object Based on Time of Day

Postby TheMagician » Wed Nov 30, 2011 11:50 am

Thanks for all your help. I understand that this is going a bit off topic but it's nice to have everything in one place ;)
Tutorials on Python in URU are rare and the information is scattered over many different places on the Web.

I've now understood the theory behind linking a Python file to a detector (I didn't know that detectors are also called activators).
However, my attempt at creating such a link didn't produce any results. The Python file shows up in Max and I can select my activator (and responder) but when I click the detector in the game there is no reaction.

Here is the code I use
Code: Select all
from Plasma import *
from PlasmaTypes import *

ClickableObject = ptAttribActivator(1,'Detector: Clickable Object')
ResponderAnimationPlay = ptAttribResponder(2, 'Responder: Play Anim')

class tagePythonTest(ptResponder):
    def __init__(self):
        ptResponder.__init__(self)
        self.id = 554002
        self.version = 1

    def OnFirstUpdate(self):
        pass

    def OnServerInitComplete(self):
        pass

    def OnNotify(self, state, id, events):
        if (id==1):
            #whatever I place here doesn't get run
            ResponderAnimationPlay.run(self.key, avatar=PtGetLocalAvatar())

    def OnSDLNotify(self, VARname, SDLname, playerID, tag):
        pass

And yes, I do have a global Python file.

Two more general questions:
1) What's the difference between a ptResponder and a ptModifier class?
2) Are there any tutorials on setting up GUIs (with Python) for URU? For example how to set up a slider. Or is my best bet to study Cyan's existing files?
TheMagician
 
Posts: 110
Joined: Mon Mar 29, 2010 3:14 pm

Re: Show/Hide Object Based on Time of Day

Postby Christopher » Wed Nov 30, 2011 12:33 pm

I am not exactly sure why you are writing a n "avatar=PtGetLocalAvatar()" behind the self.key. Maybe this is the problem... I don't know why it doesn't work.

Because of the questions with the GUI. There are a lot of GUI Components. I only used a few of them (e.g. when I redesigned the Startup age in MOULa). Maybe I can make some tutorials about using GUIs, but I am very busy. The best thing is to take the Plasma Python API and try out some of the GUI-functions.

Opa
User avatar
Christopher
 
Posts: 276
Joined: Mon Jul 19, 2010 3:25 am

Re: Show/Hide Object Based on Time of Day

Postby TheMagician » Wed Nov 30, 2011 2:25 pm

I am not exactly sure why you are writing an "avatar=PtGetLocalAvatar()" behind the self.key.

Is saw it coded like that in some of Cyan's ages. But I've also tried a version without this and it still doesn't work.

All I have to do to make Drizzle correctly use the Python file is to place it in the 'python' subdirectory inside the 3D Max output folder, right? Or do I have to place copies of it somewhere else?

Tutorials are always appreciated but of course I can understand that you're busy - same thing with me. Some of my tutorials just don't get finished because I never find the time.
TheMagician
 
Posts: 110
Joined: Mon Mar 29, 2010 3:14 pm

Re: Show/Hide Object Based on Time of Day

Postby Christopher » Wed Nov 30, 2011 2:34 pm

If you are using this File in tPots you have to pack it in a .pak-file (for example with Plasma Shop) and put this pak into your Uru/python-folder. If you are using an internal client with Moula you have to put your Pythonfile into the Uru/Python folder.

Opa
User avatar
Christopher
 
Posts: 276
Joined: Mon Jul 19, 2010 3:25 am

Re: Show/Hide Object Based on Time of Day

Postby TheMagician » Wed Nov 30, 2011 2:50 pm

If you are using this File in tPots you have to pack it in a .pak-file

Oh, of course your right. This means that I always have to do a re-pack of the pak file whenever I change the .py files in it or does PlasmaShop do that automatically?

So I added the new Plasma file into .pak file. There are already two Python files in there. One is the global age Python file and the other one is controlling the day/night cycle (and it works as it should).
Unfortunately the new file still doesn't have any effect on the game. The OnNotify doesn't seem to get triggered by the clickable object.

Do I have to add any other components to the clickable object to link it to the Plasma file correctly?
Last edited by TheMagician on Wed Nov 30, 2011 3:33 pm, edited 1 time in total.
TheMagician
 
Posts: 110
Joined: Mon Mar 29, 2010 3:14 pm

Re: Show/Hide Object Based on Time of Day

Postby tachzusamm » Wed Nov 30, 2011 3:11 pm

TheMagician wrote:This means that I always have to to a re-pack of the pak file whenever I change the .py files in it

Yes.

or does PlasmaShop do that automatically?

No.


To find out what happens, you could add some debug output to your code, to check if it's called at all, or just not triggered, or if if simply does not fire the animation:
Code: Select all
from Plasma import *
from PlasmaTypes import *

ClickableObject = ptAttribActivator(1,'Detector: Clickable Object')
ResponderAnimationPlay = ptAttribResponder(2, 'Responder: Play Anim')

class tagePythonTest(ptResponder):
    def __init__(self):
        ptResponder.__init__(self)
        self.id = 554002
        self.version = 1
        print "tagePythonTest.__init__()"

    def OnFirstUpdate(self):
        print "tagePythonTest.OnFirstUpdate()"
        pass

    def OnServerInitComplete(self):
        print "tagePythonTest.OnServerInitComplete()"
        pass

    def OnNotify(self, state, id, events):
        print "tagePythonTest.OnNotify()"
        if (id==1):
            print "TRIGGERED"
            #whatever I place here doesn't get run
            ResponderAnimationPlay.run(self.key, avatar=PtGetLocalAvatar())

    def OnSDLNotify(self, VARname, SDLname, playerID, tag):
        pass

and have a look into python.0.elf later to see the log. Can be opened in PlasmaShop as well.

By the way, insted of "if (id==1):" better write "if (id==ClickableObject.id)"; makes it more obvious what is meant, and easier to maintain in case you renumber the parameters on top later. Only needed for huge projects, of course. ;)


Funny:
users.png
users.png (2.92 KiB) Viewed 6055 times
User avatar
tachzusamm
 
Posts: 575
Joined: Thu May 29, 2008 2:03 am
Location: Germany

Re: Show/Hide Object Based on Time of Day

Postby TheMagician » Wed Nov 30, 2011 3:33 pm

Somehow on the way to implement the Python file into the .pak file in PlasmaShop I must have forgotten to save or something like that.
Now that I've updated all files again the Python file works and reacts to clicks :)

I guess I'll open a new topic for further questions because the original problem has been more than solved ;)

Thanks again for all your input!
Last edited by TheMagician on Thu Dec 01, 2011 10:28 am, edited 1 time in total.
TheMagician
 
Posts: 110
Joined: Mon Mar 29, 2010 3:14 pm

Re: Show/Hide Object Based on Time of Day

Postby Tsar Hoikas » Wed Nov 30, 2011 4:35 pm

Random note: it's bad practice to fire responders using avatar=PtGetLocalAvatar(). Use PtFindAvatar(events) in an OnNotify method, which will ensure that the responder is only played on the avatar who used the activator. Otherwise, you will run the animation on everyone in the age (the script gets executed for everyone in the age when one person clicks, and then they animate their own avatar...)
Image
Tsar Hoikas
Councilor of Technical Direction
 
Posts: 2180
Joined: Fri Nov 16, 2007 9:45 pm
Location: South Georgia

Previous

Return to Building

Who is online

Users browsing this forum: No registered users and 3 guests