Official Community Forums
 
HomeHome  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log in  The Wiki  Website  github Project  

Share | 
 

 Opening Doors Thread [MOD]

View previous topic View next topic Go down 
AuthorMessage
rotello
Super Contributor
Super Contributor
avatar

Posts : 215
Join date : 2012-12-06

PostSubject: Opening Doors Thread [MOD]   Wed 27 Mar - 15:37

This looks like a possibility with the Pickup-able Items Tutorial:

http://www.multiversemmo.com/site/w/index.php/Creating_Pickup-able_Objects

and modifying some code..



I have managed to insert a NameValue data of instancePortal to have a hover 'Right Click to Open Door' label on it (sort of a hack) and the tutorial code above to make it an interactive world object. Now the final and tricky part of it is to have it run an open animation instead of giving me a Potion Item. Smile

Something brewing here... study
Back to top Go down
Delurin
Head of Platform Development


Posts : 424
Join date : 2011-08-03

PostSubject: Re: Opening Doors Thread [MOD]   Thu 28 Mar - 1:29

I would build an effect to open the door and depending on whether you want everyone to see the door opening or just the person click on it run it from the server or client respectively

The effect code would be something along the lines of this:
Code:
import ClientAPI
import Animation
from Axiom.MathLib import *
from System.Math import PI

class DoorOpeningEffect:

    def __init__(self, oid):
        self.OID = oid
       
    def CancelEffect(self):
        pass
       
    def UpdateEffect(self):
        pass


    def ExecuteEffect(self, doorOID):
   ClientAPI.Log("DoorOpeningEffect")
   door = ClientAPI.World.GetObjectByOID(doorOID)
   if door is None:
      ClientAPI.Log("Could not find door")
      return      
   try:
     animationOpen = CreateOpenAnimation(door)
     #animationList.append(animationt)
     animationOpen.Play(1,False)
     #ClientAPI.Write("Click on another poster to see if they match")
     yield 1200
     animationOpen.Dispose()
   
        except:
     ClientAPI.Log("Error in DoorOpeningEffect")

def CreateOpenAnimation(obj):
    """This is a utility method that produce a one second animation on the
      given object to rotate it."""
    animation = Animation.Animation("opendoor"+str(obj.OID), .5)
    animation_nodetrack = animation.CreateNodeTrack(obj.SceneNode)
    animation_nodetrack_kf0 = animation_nodetrack.CreateKeyFrame(0)
    animation_nodetrack_kf0.Translate = obj.Position
    animation_nodetrack_kf0.Orientation = obj.Orientation
    animation_nodetrack_kf1 = animation_nodetrack.CreateKeyFrame(.5)
    animation_nodetrack_kf1.Translate = obj.Position
    animation_nodetrack_kf1.Orientation = Quaternion.FromAngleAxis(.5 * PI, Vector3.UnitY) * obj.Orientation
    return animation
   

# register the effect
ClientAPI.World.RegisterEffect("DoorOpeningEffect", DoorOpeningEffect)


Add the python file you save it as to startup.py
Then you can call it by on the client with


Code:
ClientAPI.World.InvokeEffect( "DoorOpeningEffect", ClientAPI.GetLocalOID(),
       {'doorOID':worldObj.OID} )

You could easity put it in MarsCursor as the handler for the property just remember you also have to register the object as being targetable

You might consider making a default property that you add to object if you want them to be targetable


Last edited by Delurin on Thu 28 Mar - 2:17; edited 1 time in total (Reason for editing : Wrong Animation)
Back to top Go down
rotello
Super Contributor
Super Contributor
avatar

Posts : 215
Join date : 2012-12-06

PostSubject: Re: Opening Doors Thread [MOD]   Thu 28 Mar - 1:53

Hey, thanks for sharing Delurin. cheers This will help a lot, I will try this tomorrow.

Question: I would like every player to see the opening action for a realistic feel. Is this already set for the code above?
Back to top Go down
Delurin
Head of Platform Development


Posts : 424
Join date : 2011-08-03

PostSubject: Re: Opening Doors Thread [MOD]   Thu 28 Mar - 2:08

You would need to trigger it with a / command or with an extension message (more difficult to setup I would start with / command and later switch to messages)
Basically you would implement the / command just like the loot command in the tutorial but have it go to something like this:
Code:
doorOID== cmdEvent.getTarget()
doormsg = AnimationClient.InvokeEffectMessage(playerOid, "DoorOpeningEffect")
   doormsg .setProperty("doorOID", str(doorOID))
   Engine.getAgent().sendBroadcast(doormsg)

And you would need to change the door = ClientAPI.World.GetObjectByOID(long(doorOID)) so that it converts the string oid to a long. You may be able to set the property in the extension_proxy as a long but I think I had a problem with jython screwing up the cast so I cast it to a string on the server and back on the client.
Back to top Go down
rotello
Super Contributor
Super Contributor
avatar

Posts : 215
Join date : 2012-12-06

PostSubject: Re: Opening Doors Thread [MOD]   Thu 28 Mar - 2:13

Thanks, I will try that one too.

Be back with the results on this..
Back to top Go down
tichfuie
Super Contributor
Super Contributor
avatar

Posts : 257
Join date : 2013-02-07
Location : NA

PostSubject: Re: Opening Doors Thread [MOD]   Thu 28 Mar - 13:12

did you have any luck with the server side code rotello?
Back to top Go down
rotello
Super Contributor
Super Contributor
avatar

Posts : 215
Join date : 2012-12-06

PostSubject: Re: Opening Doors Thread [MOD]   Thu 28 Mar - 13:24

Not yet. I will keep you posted.
Back to top Go down
rotello
Super Contributor
Super Contributor
avatar

Posts : 215
Join date : 2012-12-06

PostSubject: Re: Opening Doors Thread [MOD]   Thu 28 Mar - 15:44

@Delurin

I was thinking of having something like this with your code on Bindings.xml

Code:

<Binding name="OPENDOOR" header="ACTIONS">
                ClientAPI.World.InvokeEffect( "DoorOpeningEffect", ClientAPI.GetLocalOID(),
      {'doorOID':worldObj.OID} )
</Binding>

Then add the letter 'M' for example as key handler to the Bindings.txt

M OPENDOOR

I have placed the effects code under /Scripts named DoorOpeningEffect.py

Code:
import ClientAPI
import Animation
from Axiom.MathLib import *
from System.Math import PI

class DoorOpeningEffect:

    def __init__(self, oid):
        self.OID = oid
       
    def CancelEffect(self):
        pass
       
    def UpdateEffect(self):
        pass


    def ExecuteEffect(self, doorOID):
  ClientAPI.Log("DoorOpeningEffect")
  #door = ClientAPI.World.GetObjectByOID(doorOID)
  door = ClientAPI.World.GetObjectByOID(long(doorOID))
  if door is None:
      ClientAPI.Log("Could not find door")
      ClientAPI.Write("Could not find door")
      return     
  try:
    animationOpen = CreateOpenAnimation(door)
    #animationList.append(animationt)
    animationOpen.Play(1,False)
    #ClientAPI.Write("Click on another poster to see if they match")
    yield 1200
    animationOpen.Dispose()
 
        except:
    ClientAPI.Log("Error in DoorOpeningEffect")

def CreateOpenAnimation(obj):
    """This is a utility method that produce a one second animation on the
      given object to rotate it."""
    animation = Animation.Animation("opendoor"+str(obj.OID), .5)
    animation_nodetrack = animation.CreateNodeTrack(obj.SceneNode)
    animation_nodetrack_kf0 = animation_nodetrack.CreateKeyFrame(0)
    animation_nodetrack_kf0.Translate = obj.Position
    animation_nodetrack_kf0.Orientation = obj.Orientation
    animation_nodetrack_kf1 = animation_nodetrack.CreateKeyFrame(.5)
    animation_nodetrack_kf1.Translate = obj.Position
    animation_nodetrack_kf1.Orientation = Quaternion.FromAngleAxis(.5 * PI, Vector3.UnitY) * obj.Orientation
    return animation
   

# register the effect
ClientAPI.World.RegisterEffect("DoorOpeningEffect", DoorOpeningEffect)

I added a chat info to debug the script
The only problem I'm getting is a worldObj undefined log error or something when I pressed the action key

Back to top Go down
rotello
Super Contributor
Super Contributor
avatar

Posts : 215
Join date : 2012-12-06

PostSubject: Re: Opening Doors Thread [MOD]   Thu 28 Mar - 16:04

Okay, I forgot to add the import DoorOpeningEffect in Startup.py

Now it's reading the code and I'm getting indentation errors, we'll see..

Back to top Go down
rotello
Super Contributor
Super Contributor
avatar

Posts : 215
Join date : 2012-12-06

PostSubject: Re: Opening Doors Thread [MOD]   Thu 28 Mar - 16:15

Here's the actual error log I'm getting:

Code:
ERROR [2013-03-28 13:10:23,966] Exception            Unable to run key binding event handler: System.MissingMemberException: 'instance' object has no attribute 'doorOID'
  at IronPython.Runtime.Operations.Ops.GetAttr(ICallerContext context, Object o, SymbolId name)
  at pythonFunction##401(ModuleScope , String )
  at Multiverse.Interface.UiSystem.HandleBinding(String bindingName, InputEventArgs args, Boolean down)
Back to top Go down
Sponsored content




PostSubject: Re: Opening Doors Thread [MOD]   

Back to top Go down
 
Opening Doors Thread [MOD]
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» TBC doors opening
» Best Fight Thread!
» Funny Fights Thread!
» NECA Toy Fair 2011 reveal thread
» Eternal Dream Official "LOL Pictures" Thread

Permissions in this forum:You cannot reply to topics in this forum
 :: Development :: Feature Requests-
Jump to: