Make an Object Invisible and Visible

From Multiverse

Jump to: navigation, search
This is a work in progress. It will be incomplete and may contain errors or omissions until it is finished.

This example has been modified to conform to the Release 1.1 API, and tested with the 1.1 server. It succeeds in setting the mob invisible, but setting the mob visible again does not work for undiagnosed reasons.

Thanks to rjyoung for contributing this example.

The first time this command is executed it will turn a mob or object invisible; the second time, it turns the object visible again. So, it essentially toggles the visibility of the targeted object.

class ToggleObjInvisible (ProxyPlugin.CommandParser):
   def parse(self, cmdEvent):
      cmd = cmdEvent.getCommand()
      playerOid = cmdEvent.getObjectOid()
      targetOid = cmdEvent.getTarget()
      invis = int(EnginePlugin.getObjectProperty(targetOid, WorldManagerClient.NAMESPACE, "myprop.invisible"))
      if invis == 0:
          # turn obj invisible
          Log.debug("ToggleObjInvisible: Attempting to make obj invisible")
          dc = WorldManagerClient.getDisplayContext(targetOid)
          EnginePlugin.setObjectProperty(targetOid,  WorldManagerClient.NAMESPACE, "myprop.old_dc_meshname", str(dc.getMeshFile()))
          x = ArrayList()
          sub = dc.getSubmeshes()
          for i in range(0, sub.size()):
            sub1 = sub[i]
            x.add(sub1)
          EnginePlugin.setObjectProperty(targetOid, WorldManagerClient.NAMESPACE, "myprop.old_dc_submeshes", x)
          submeshes = ArrayList()
          submeshes.add(DisplayContext.Submesh("None", ""))
          WorldManagerClient.modifyDisplayContext(targetOid,
                                                  WorldManagerClient.modifyDisplayContextActionReplace,
                                                  str(dc.getMeshFile()),
                                                  submeshes)
          EnginePlugin.setObjectProperty(targetOid, WorldManagerClient.NAMESPACE, "myprop.invisible", int(1))
          WorldManagerClient.sendObjChatMsg(playerOid, 1, "BECOME INVISIBLE!!")  
      else:
          Log.debug("ToggleObjInvisible: Attempting to make obj visible")
          dc_meshname = str(EnginePlugin.getObjectProperty(targetOid, WorldManagerClient.NAMESPACE,  "myprop.old_dc_meshname"))
          dc_submeshes = EnginePlugin.getObjectProperty(targetOid, WorldManagerClient.NAMESPACE, "myprop.old_dc_submeshes")
          submeshes = ArrayList()
          for i in range(0, len(dc_submeshes)):
              submesh = dc_submeshes[i]
              submeshes.add(submesh)
          WorldManagerClient.modifyDisplayContext(targetOid,
                                                  WorldManagerClient.modifyDisplayContextActionReplace,
                                                  dc_meshname, 
                                                  submeshes)
          EnginePlugin.setObjectProperty(targetOid, WorldManagerClient.NAMESPACE, "myprop.invisible", int(0))
          WorldManagerClient.sendObjChatMsg(playerOid, 1, "LET ME SEE YOU AGAIN!")       
          return None

proxyPlugin.registerCommand("/toggleinvis", ToggleObjInvisible()) 

Add the following line to templates.py:

mob.put(WorldManagerClient.NAMESPACE, "myprop.invisible", Integer(0)) 

where mob is the name of the mob template to which to apply the function. For example, to apply it to the zombie in sampleworld, add

tmpl.put(WorldManagerClient.NAMESPACE, "myprop.invisible", Integer(0)) 

Important: You must add this code before the line

ObjectManagerClient.registerTemplate(mob)

To execute the command, target the mob, then type /toggleinvis to toggle its visibility.

Personal tools