PageRenderTime 107ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/Python/ercaSDLIntShowHide.py

https://github.com/boq/moul-scripts
Python | 145 lines | 92 code | 0 blank | 53 comment | 0 complexity | f9bc829d90b20d0583666caf18f422ac MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. """ *==LICENSE==*
  3. CyanWorlds.com Engine - MMOG client, server and tools
  4. Copyright (C) 2011 Cyan Worlds, Inc.
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. Additional permissions under GNU GPL version 3 section 7
  16. If you modify this Program, or any covered work, by linking or
  17. combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
  18. NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
  19. JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
  20. (or a modified version of those libraries),
  21. containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
  22. PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
  23. JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
  24. licensors of this Program grant you additional
  25. permission to convey the resulting work. Corresponding Source for a
  26. non-source form of such a combination shall include the source code for
  27. the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
  28. work.
  29. You can contact Cyan Worlds, Inc. by email legal@cyan.com
  30. or by snail mail at:
  31. Cyan Worlds, Inc.
  32. 14617 N Newport Hwy
  33. Mead, WA 99021
  34. *==LICENSE==* """
  35. """
  36. Module: ercaSDLIntShowHide
  37. Age: Ercana
  38. Date: December 2003
  39. Author: Chris Doyle, based on script by xAgeSDLIntShowHide by Adam Van Ornum
  40. Ercana-specific version of script which detects age SDL variable change and shows (on unspecified states) or hides (on unspecified states) the object it's attached to
  41. Enter in the states you wish the item to be *INvisible* in as a comma separated list
  42. """
  43. from Plasma import *
  44. from PlasmaTypes import *
  45. import string
  46. stringVarName = ptAttribString(1,"Age SDL Var Name")
  47. stringShowStates = ptAttribString(2,"States in which hidden")
  48. AgeStartedIn = None
  49. class ercaSDLIntShowHide(ptMultiModifier):
  50. def __init__(self):
  51. ptMultiModifier.__init__(self)
  52. self.id = 7032
  53. self.version = 2
  54. self.enabledStateList = []
  55. def OnFirstUpdate(self):
  56. global AgeStartedIn
  57. AgeStartedIn = PtGetAgeName()
  58. def OnServerInitComplete(self):
  59. if type(stringVarName.value) == type("") and stringVarName.value != "":
  60. ageSDL = PtGetAgeSDL()
  61. ageSDL.setFlags(stringVarName.value,1,1)
  62. ageSDL.sendToClients(stringVarName.value)
  63. try:
  64. self.enabledStateList = stringShowStates.value.split(",")
  65. for i in range(len(self.enabledStateList)):
  66. self.enabledStateList[i] = int(self.enabledStateList[i].strip())
  67. except:
  68. PtDebugPrint("ERROR: ercaSDLIntShowHide.OnFirstUpdate():\tERROR: couldn't process start state list")
  69. pass
  70. else:
  71. PtDebugPrint("ERROR: ercaSDLIntShowHide.OnFirstUpdate():\tERROR: missing SDL var name")
  72. pass
  73. if AgeStartedIn == PtGetAgeName():
  74. ageSDL = PtGetAgeSDL()
  75. if type(stringVarName.value) == type("") and stringVarName.value != "":
  76. #PtDebugPrint("Setting notify on %s..." % stringVarName.value)
  77. ageSDL.setNotify(self.key,stringVarName.value,0.0)
  78. try:
  79. SDLvalue = ageSDL[stringVarName.value][0]
  80. except:
  81. PtDebugPrint("ERROR: ercaSDLIntShowHide.OnServerInitComplete():\tERROR: age sdl read failed, SDLvalue = 0 by default. stringVarName = %s" % (stringVarName.value))
  82. SDLvalue = 0
  83. try:
  84. if SDLvalue in self.enabledStateList:
  85. PtDebugPrint("DEBUG: ercaSDLIntShowHide.OnServerInitComplete: Attempting to disable drawing and collision on %s..." % self.sceneobject.getName())
  86. self.sceneobject.draw.disable()
  87. self.sceneobject.physics.suppress(true)
  88. else:
  89. PtDebugPrint("DEBUG: ercaSDLIntShowHide.OnServerInitComplete: Attempting to enable drawing and collision on %s..." % self.sceneobject.getName())
  90. self.sceneobject.draw.enable()
  91. self.sceneobject.physics.suppress(false)
  92. except:
  93. PtDebugPrint("ERROR: ercaSDLIntShowHide.OnServerInitComplete():\tERROR enabling/disabling object %s" % self.sceneobject.getName())
  94. pass
  95. else:
  96. PtDebugPrint("ERROR: ercaSDLIntShowHide.OnServerInitComplete():\tERROR: missing SDL var name")
  97. pass
  98. def OnSDLNotify(self,VARname,SDLname,playerID,tag):
  99. if VARname != stringVarName.value:
  100. return
  101. if AgeStartedIn == PtGetAgeName():
  102. ageSDL = PtGetAgeSDL()
  103. SDLvalue = ageSDL[stringVarName.value][0]
  104. if SDLvalue in self.enabledStateList:
  105. self.DisableObject()
  106. else:
  107. self.EnableObject()
  108. def EnableObject(self):
  109. PtDebugPrint("DEBUG: ercaSDLIntShowHide.EnableObject: Attempting to enable drawing and collision on %s..." % self.sceneobject.getName())
  110. self.sceneobject.draw.enable()
  111. self.sceneobject.physics.suppress(false)
  112. def DisableObject(self):
  113. PtDebugPrint("DEBUG: ercaSDLIntShowHide.DisableObject: Attempting to disable drawing and collision on %s..." % self.sceneobject.getName())
  114. self.sceneobject.draw.disable()
  115. self.sceneobject.physics.suppress(true)
  116. def OnBackdoorMsg(self, target, param):
  117. if type(stringVarName.value) != type(None) and stringVarName.value != "":
  118. if target == stringVarName.value:
  119. if param.lower() in self.enabledStateList:
  120. self.DisableObject()
  121. else:
  122. self.EnableObject()