| Opening Doors Thread [MOD] | |
|
|
Author | Message |
---|
rotello Super Contributor
![Super Contributor Super Contributor](https://2img.net/i/itest/ranks/default/default5.gif)
![rotello](https://2img.net/i/fa/i/avatars/gallery/Cine_Seigneur_des_anneaux/Lotr_37.gif)
Posts : 215 Join date : 2012-12-06
![Opening Doors Thread [MOD] Empty](https://2img.net/i/empty.gif) | Subject: 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_Objectsand modifying some code.. ![Opening Doors Thread [MOD] 5ur2qa](https://2img.net/h/oi49.tinypic.com/5ur2qa.jpg) 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](https://2img.net/i/fa/i/smiles/icon_smile.gif) Something brewing here... | |
|
![Go down](https://2img.net/i/empty.gif) | |
Delurin Head of Platform Development
![avatar](https://2img.net/h/www.multiversemmo.com/forums/default-avatar.png)
Posts : 424 Join date : 2011-08-03
![Opening Doors Thread [MOD] Empty](https://2img.net/i/empty.gif) | Subject: 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) | |
|
![Go down](https://2img.net/i/empty.gif) | |
rotello Super Contributor
![Super Contributor Super Contributor](https://2img.net/i/itest/ranks/default/default5.gif)
![rotello](https://2img.net/i/fa/i/avatars/gallery/Cine_Seigneur_des_anneaux/Lotr_37.gif)
Posts : 215 Join date : 2012-12-06
![Opening Doors Thread [MOD] Empty](https://2img.net/i/empty.gif) | Subject: Re: Opening Doors Thread [MOD] Thu 28 Mar - 1:53 | |
| Hey, thanks for sharing Delurin. ![cheers](https://2img.net/i/fa/i/smiles/icon_cheers.png) 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? | |
|
![Go down](https://2img.net/i/empty.gif) | |
Delurin Head of Platform Development
![avatar](https://2img.net/h/www.multiversemmo.com/forums/default-avatar.png)
Posts : 424 Join date : 2011-08-03
![Opening Doors Thread [MOD] Empty](https://2img.net/i/empty.gif) | Subject: 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. | |
|
![Go down](https://2img.net/i/empty.gif) | |
rotello Super Contributor
![Super Contributor Super Contributor](https://2img.net/i/itest/ranks/default/default5.gif)
![rotello](https://2img.net/i/fa/i/avatars/gallery/Cine_Seigneur_des_anneaux/Lotr_37.gif)
Posts : 215 Join date : 2012-12-06
![Opening Doors Thread [MOD] Empty](https://2img.net/i/empty.gif) | Subject: Re: Opening Doors Thread [MOD] Thu 28 Mar - 2:13 | |
| Thanks, I will try that one too.
Be back with the results on this.. | |
|
![Go down](https://2img.net/i/empty.gif) | |
tichfuie Super Contributor
![Super Contributor Super Contributor](https://2img.net/i/itest/ranks/default/default5.gif)
![tichfuie](https://2img.net/h/www.multiversemmo.com/forums/default-avatar.png)
Posts : 257 Join date : 2013-02-07 Location : NA
![Opening Doors Thread [MOD] Empty](https://2img.net/i/empty.gif) | Subject: Re: Opening Doors Thread [MOD] Thu 28 Mar - 13:12 | |
| did you have any luck with the server side code rotello? | |
|
![Go down](https://2img.net/i/empty.gif) | |
rotello Super Contributor
![Super Contributor Super Contributor](https://2img.net/i/itest/ranks/default/default5.gif)
![rotello](https://2img.net/i/fa/i/avatars/gallery/Cine_Seigneur_des_anneaux/Lotr_37.gif)
Posts : 215 Join date : 2012-12-06
![Opening Doors Thread [MOD] Empty](https://2img.net/i/empty.gif) | Subject: Re: Opening Doors Thread [MOD] Thu 28 Mar - 13:24 | |
| Not yet. I will keep you posted. | |
|
![Go down](https://2img.net/i/empty.gif) | |
rotello Super Contributor
![Super Contributor Super Contributor](https://2img.net/i/itest/ranks/default/default5.gif)
![rotello](https://2img.net/i/fa/i/avatars/gallery/Cine_Seigneur_des_anneaux/Lotr_37.gif)
Posts : 215 Join date : 2012-12-06
![Opening Doors Thread [MOD] Empty](https://2img.net/i/empty.gif) | Subject: 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.txtM 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 | |
|
![Go down](https://2img.net/i/empty.gif) | |
rotello Super Contributor
![Super Contributor Super Contributor](https://2img.net/i/itest/ranks/default/default5.gif)
![rotello](https://2img.net/i/fa/i/avatars/gallery/Cine_Seigneur_des_anneaux/Lotr_37.gif)
Posts : 215 Join date : 2012-12-06
![Opening Doors Thread [MOD] Empty](https://2img.net/i/empty.gif) | Subject: 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..
| |
|
![Go down](https://2img.net/i/empty.gif) | |
rotello Super Contributor
![Super Contributor Super Contributor](https://2img.net/i/itest/ranks/default/default5.gif)
![rotello](https://2img.net/i/fa/i/avatars/gallery/Cine_Seigneur_des_anneaux/Lotr_37.gif)
Posts : 215 Join date : 2012-12-06
![Opening Doors Thread [MOD] Empty](https://2img.net/i/empty.gif) | Subject: 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) | |
|
![Go down](https://2img.net/i/empty.gif) | |
Sponsored content
![Opening Doors Thread [MOD] Empty](https://2img.net/i/empty.gif) | Subject: Re: Opening Doors Thread [MOD] ![Opening Doors Thread [MOD] Empty](https://2img.net/i/empty.gif) | |
| |
|
![Go down](https://2img.net/i/empty.gif) | |
| Opening Doors Thread [MOD] | |
|