Update of /cvsroot/wpdev/xmlscripts/scripts/commands
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10481/commands
Modified Files:
skillinfo.py tags.py
Log Message:
Taginfo command and wolfpack.findobject function
Index: tags.py
===================================================================
RCS file: /cvsroot/wpdev/xmlscripts/scripts/commands/tags.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** tags.py 26 May 2004 13:07:21 -0000 1.2
--- tags.py 5 Jul 2004 12:55:35 -0000 1.3
***************
*** 24,30 ****
--- 24,175 ----
"""
+ """
+ \command taginfo
+ \description This command shows a menu with all tags assigned to the
+ targetted object.
+ \usage - <code>taginfo</code>
+ """
+
import wolfpack
from wolfpack.utilities import hex2dec
+ from wolfpack.gumps import cGump
+ from wolfpack.consts import *
+ def taginfo_callback(player, tagnames, response):
+ if response.button != 1:
+ return
+
+ object = wolfpack.findobject(tagnames[0])
+ if not object:
+ return
+ tagnames = tagnames[1:]
+
+ switches = response.switches
+ for i in range(0, len(tagnames)):
+ # Should the tag be deleted?
+ if i * 2 + 1 in switches:
+ oldvalue = object.gettag(tagnames[i])
+ player.log(LOG_MESSAGE, u"Deleting tag '%s' from object 0x%x. Was: '%s' (%s).\n" % \
+ (tagnames[i], object.serial, unicode(oldvalue), type(oldvalue).__name__))
+ object.deltag(tagnames[i])
+ continue
+
+ if response.text.has_key(i * 2 + 0) and response.text.has_key(i * 2 + 1):
+ # Get value and name of the tag
+ name = response.text[i * 2]
+ value = response.text[i * 2 + 1]
+
+ # Should the value be interpreted as a number?
+ if i * 2 in switches:
+ if '.' in value or ',' in value:
+ try:
+ value = float(value)
+ except:
+ player.socket.sysmessage("Invalid floating point value for tag '%s': '%s'." % (name, value))
+ continue # Skip to next tag
+ else:
+ try:
+ value = int(value)
+ except:
+ player.socket.sysmessage("Invalid integer value for tag '%s': '%s'." % (name, value))
+ continue # Skip to next tag
+
+ try:
+ name = str(name)
+ except:
+ player.socket.sysmessage("Invalid tagname: '%s'." % name)
+ continue # Skip to next tag
+
+ # Set the new tag value for the player
+ oldvalue = object.gettag(tagnames[i])
+ change = (name != tagnames[i]) or (type(oldvalue) != type(value)) or (oldvalue != value)
+
+ if change:
+ player.log(LOG_MESSAGE, u"Settings tag '%s' on object 0x%x to '%s' (%s).\n" % (unicode(name), object.serial, unicode(value), type(value).__name__))
+ object.deltag(tagnames[i])
+ object.settag(name, value)
+
+ def taginfo_response(player, arguments, target):
+ if target.char:
+ object = target.char
+ elif target.item:
+ object = target.item
+ else:
+ player.socket.sysmessage('You have to target an item or a character.')
+ return
+
+ tags = object.tags
+
+ dialog = wolfpack.gumps.cGump()
+ dialog.setCallback("commands.tags.taginfo_callback")
+ dialog.setArgs([object.serial] + tags)
+
+ dialog.startPage(0)
+ dialog.addResizeGump(35, 12, 9260, 460, 504)
+ dialog.addGump(1, 12, 10421, 0)
+ dialog.addGump(30, -1, 10420, 0)
+ dialog.addResizeGump(66, 40, 9200, 405, 65)
+ dialog.addText(108, 52, "Wolfpack Taginfo Command", 2100)
+ dialog.addTiledGump(90, 11, 164, 17, 10250, 0)
+ dialog.addGump(474, 12, 10431, 0)
+ dialog.addGump(439, -1, 10430, 0)
+ dialog.addGump(14, 200, 10422, 0)
+ dialog.addGump(468, 200, 10432, 0)
+ dialog.addGump(249, 11, 10254, 0)
+ dialog.addGump(74, 45, 10464, 0)
+ dialog.addGump(435, 45, 10464, 0)
+ dialog.addGump(461, 408, 10412, 0)
+ dialog.addGump(-15, 408, 10402, 0)
+ dialog.addTiledGump(281, 11, 158, 17, 10250, 0)
+ dialog.addGump(265, 11, 10252, 0)
+ dialog.addButton(60, 476, 247, 248, 1)
+ dialog.addButton(136, 476, 242, 241, 0)
+
+ # This is a group
+ count = (len(tags) + 3) / 4
+
+ for i in range(0, count):
+ page = i + 1
+ dialog.startPage(page)
+
+ if page > 1:
+ dialog.addText(88, 445, "Previous Page", 2100)
+ dialog.addPageButton(59, 444, 9909, 9911, page - 1)
+
+ if page < count:
+ dialog.addText(376, 445, "Next Page", 2100)
+ dialog.addPageButton(448, 445, 9903, 9905, page + 1)
+
+ for j in range(0, 4):
+ tagid = i * 4 + j
+ if tagid >= len(tags):
+ continue
+
+ tag = tags[tagid]
+ value = object.gettag(tag)
+ yoffset = j * 80
+ dialog.addResizeGump(65, 109 + yoffset, 9200, 405, 68)
+ dialog.addText(78, 117 + yoffset, "Name", 2100)
+ dialog.addText(78, 146 + yoffset, "Value", 2100)
+ dialog.addResizeGump(123, 144 + yoffset, 9300, 250, 26)
+ dialog.addInputField(129, 147 + yoffset, 240, 20, 2100, tagid * 2 + 1, unicode(value))
+ dialog.addResizeGump(123, 115 + yoffset, 9300, 250, 26)
+ dialog.addInputField(128, 118 + yoffset, 240, 20, 2100, tagid * 2 + 0, tag)
+
+ dialog.addCheckbox(380, 118 + yoffset, 208, 209, tagid * 2 + 1, 0)
+ dialog.addText(405, 118 + yoffset, "Delete", 2100)
+
+ dialog.addCheckbox(380, 147 + yoffset, 208, 209, tagid * 2 + 0, type(value) == float or type(value) == int)
+ dialog.addText(405, 147 + yoffset, "Number", 2100)
+
+ dialog.send(player)
+
+ #
+ # Tag info
+ #
+ def commandTaginfo(socket, command, arguments):
+ socket.sysmessage("Select an object you want to use this command on.")
+ socket.attachtarget("commands.tags.taginfo_response", [])
+
#
# Target response
***************
*** 38,47 ****
return
! target.char.settag(name, value)
! target.char.resendtooltip()
player.socket.sysmessage('You modify the tag of the character.')
elif target.item:
! target.item.settag(name, value)
! target.item.resendtooltip()
player.socket.sysmessage('You modify the tag of the item.')
--- 183,209 ----
return
! if not target.char.hastag(name):
! change = 1
! else:
! oldvalue = target.char.gettag(name)
! change = (type(oldvalue) != type(value)) or (oldvalue != value)
!
! if change:
! player.log(LOG_MESSAGE, u"Settings tag '%s' on object 0x%x to '%s' (%s).\n" % (unicode(name), target.char.serial, unicode(value), type(value).__name__))
! target.char.settag(name, value)
! target.char.resendtooltip()
player.socket.sysmessage('You modify the tag of the character.')
elif target.item:
! if not target.item.hastag(name):
! change = 1
! else:
! oldvalue = target.item.gettag(name)
! change = (type(oldvalue) != type(value)) or (oldvalue != value)
!
! if change:
! player.log(LOG_MESSAGE, u"Settings tag '%s' on object 0x%x to '%s' (%s).\n" % (unicode(name), target.item.serial, unicode(value), type(value).__name__))
! target.item.settag(name, value)
! target.item.resendtooltip()
!
player.socket.sysmessage('You modify the tag of the item.')
***************
*** 72,76 ****
socket.sysmessage('You specified an invalid floating point value.')
return
! elif argtype != 'string':
socket.sysmessage('Usage: settag name (int|string|float) value...')
return
--- 234,240 ----
socket.sysmessage('You specified an invalid floating point value.')
return
! elif argtype == 'string':
! value = unicode(value)
! else:
socket.sysmessage('Usage: settag name (int|string|float) value...')
return
***************
*** 92,95 ****
--- 256,262 ----
player.socket.sysmessage("This character has no tag named '%s'." % name)
else:
+ oldvalue = target.char.gettag(name)
+ player.log(LOG_MESSAGE, u"Deleting tag '%s' from object 0x%x. Was: '%s' (%s).\n" % \
+ (name, target.char.serial, unicode(oldvalue), type(oldvalue).__name__))
target.char.deltag(name)
target.char.resendtooltip()
***************
*** 99,102 ****
--- 266,272 ----
player.socket.sysmessage("This item has no tag named '%s'." % name)
else:
+ oldvalue = target.item.gettag(name)
+ player.log(LOG_MESSAGE, u"Deleting tag '%s' from object 0x%x. Was: '%s' (%s).\n" % \
+ (name, target.item.serial, unicode(oldvalue), type(oldvalue).__name__))
target.item.deltag(name)
target.item.resendtooltip()
***************
*** 171,172 ****
--- 341,343 ----
wolfpack.registercommand('gettag', commandGettag)
wolfpack.registercommand('deltag', commandDeltag)
+ wolfpack.registercommand('taginfo', commandTaginfo)
\ No newline at end of file
Index: skillinfo.py
===================================================================
RCS file: /cvsroot/wpdev/xmlscripts/scripts/commands/skillinfo.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** skillinfo.py 2 Jul 2004 13:40:45 -0000 1.3
--- skillinfo.py 5 Jul 2004 12:55:35 -0000 1.4
***************
*** 16,47 ****
#
def response(player, arguments, response):
! if response.button == 0:
! return
! target = wolfpack.findchar(arguments[0])
! if not target:
! return
! # Iterate trough all skills and see what changed
! for skill in range(0, ALLSKILLS):
! try:
! newvalue = int(floor(float(response.text[0x1000 | skill]) * 10))
! newcap = int(floor(float(response.text[0x2000 | skill]) * 10))
! except:
! player.socket.sysmessage('You have entered invalid values for %s.' % SKILLNAMES[skill])
! return
! oldvalue = target.skill[skill]
! oldcap = target.skillcap[skill]
! if oldvalue != newvalue or oldcap != newcap:
! message = "Changed %s for character 0x%x to value %u [%d] and cap %u [%d].\n"
! message = message % (SKILLNAMES[skill], target.serial, newvalue, newvalue - oldvalue, newcap, newcap - oldcap)
! player.log(LOG_MESSAGE, message)
! player.socket.sysmessage(message)
! target.skill[skill] = newvalue
! target.skillcap[skill] = newcap
#
--- 16,47 ----
#
def response(player, arguments, response):
! if response.button == 0:
! return
! target = wolfpack.findchar(arguments[0])
! if not target:
! return
! # Iterate trough all skills and see what changed
! for skill in range(0, ALLSKILLS):
! try:
! newvalue = int(floor(float(response.text[0x1000 | skill]) * 10))
! newcap = int(floor(float(response.text[0x2000 | skill]) * 10))
! except:
! player.socket.sysmessage('You have entered invalid values for %s.' % SKILLNAMES[skill])
! return
! oldvalue = target.skill[skill]
! oldcap = target.skillcap[skill]
! if oldvalue != newvalue or oldcap != newcap:
! message = "Changed %s for character 0x%x to value %u [%d] and cap %u [%d].\n"
! message = message % (SKILLNAMES[skill], target.serial, newvalue, newvalue - oldvalue, newcap, newcap - oldcap)
! player.log(LOG_MESSAGE, message)
! player.socket.sysmessage(message)
! target.skill[skill] = newvalue
! target.skillcap[skill] = newcap
#
***************
*** 49,118 ****
#
def callback(player, arguments, target):
! if not target.char:
! return
! dialog = wolfpack.gumps.cGump()
! dialog.setCallback("commands.skillinfo.response")
! dialog.setArgs([target.char.serial])
! dialog.startPage(0)
! dialog.addResizeGump(35, 12, 9260, 460, 504)
! dialog.addGump(1, 12, 10421, 0)
! dialog.addGump(30, -1, 10420, 0)
! dialog.addResizeGump(66, 40, 9200, 405, 65)
! dialog.addText(108, 52, "Wolfpack Skillinfo Command", 2100)
! dialog.addTiledGump(90, 11, 164, 17, 10250, 0)
! dialog.addGump(474, 12, 10431, 0)
! dialog.addGump(439, -1, 10430, 0)
! dialog.addGump(14, 200, 10422, 0)
! dialog.addGump(468, 200, 10432, 0)
! dialog.addGump(249, 11, 10254, 0)
! dialog.addGump(74, 45, 10464, 0)
! dialog.addGump(435, 45, 10464, 0)
! dialog.addGump(461, 408, 10412, 0)
! dialog.addGump(-15, 408, 10402, 0)
! dialog.addTiledGump(281, 11, 158, 17, 10250, 0)
! dialog.addGump(265, 11, 10252, 0)
! dialog.addButton(60, 476, 247, 248, 1)
! dialog.addButton(136, 476, 242, 241, 0)
! pages = int(ceil(ALLSKILLS / 5.0))
! for page in range(1, pages + 1):
! dialog.startPage(page)
! if page > 1:
! dialog.addPageButton(60, 444, 9909, 9911, page - 1)
! dialog.addText(88, 444, "Previous Page", 2100)
! if page < pages:
! dialog.addPageButton(448, 444, 9903, 9905, page + 1)
! dialog.addText(376, 448, "Next Page", 2100)
! yoffset = 0
! for i in range(0, 5):
! skill = (page - 1) * 5 + i
! if skill >= ALLSKILLS:
! break
! skillname = SKILLNAMES[skill]
! skillname = skillname[0].upper() + skillname[1:]
! dialog.addResizeGump(65, 109 + yoffset, 9200, 405, 62)
! dialog.addText(76, 115 + yoffset, "Skill: %s (%u)" % (skillname, skill), 2100)
! dialog.addResizeGump(123, 135 + yoffset, 9300, 63, 26)
! dialog.addText(76, 137 + yoffset, "Value:", 2100)
! dialog.addText(187, 138 + yoffset, "%", 2100)
! dialog.addInputField(128, 138 + yoffset, 50, 20, 2100, 0x1000 | skill, "%0.01f" % (target.char.skill[skill] / 10.0))
! dialog.addText(232, 138 + yoffset, "Cap:", 2100)
! dialog.addText(329, 139 + yoffset, "%", 2100)
! dialog.addResizeGump(264, 135 + yoffset, 9300, 63, 26)
! dialog.addInputField(268, 139 + yoffset, 53, 20, 2100, 0x2000 | skill, "%0.01f" % (target.char.skillcap[skill] / 10.0))
! yoffset += 65
! dialog.send(player)
#
--- 49,119 ----
#
def callback(player, arguments, target):
! if not target.char:
! return
! dialog = wolfpack.gumps.cGump()
! dialog.setCallback("commands.skillinfo.response")
! dialog.setArgs([target.char.serial])
! dialog.startPage(0)
! dialog.addResizeGump(35, 12, 9260, 460, 504)
! dialog.addGump(1, 12, 10421, 0)
! dialog.addGump(30, -1, 10420, 0)
! dialog.addResizeGump(66, 40, 9200, 405, 65)
! dialog.addText(108, 52, "Wolfpack Skillinfo Command", 2100)
! dialog.addTiledGump(90, 11, 164, 17, 10250, 0)
! dialog.addGump(474, 12, 10431, 0)
! dialog.addGump(439, -1, 10430, 0)
! dialog.addGump(14, 200, 10422, 0)
! dialog.addGump(468, 200, 10432, 0)
! dialog.addGump(249, 11, 10254, 0)
! dialog.addGump(74, 45, 10464, 0)
! dialog.addGump(435, 45, 10464, 0)
! dialog.addGump(461, 408, 10412, 0)
! dialog.addGump(-15, 408, 10402, 0)
! dialog.addTiledGump(281, 11, 158, 17, 10250, 0)
! dialog.addGump(265, 11, 10252, 0)
! dialog.addButton(60, 476, 247, 248, 1)
! dialog.addButton(136, 476, 242, 241, 0)
! # 80 pixel diameter
! pages = int(ceil(ALLSKILLS / 5.0))
! for page in range(1, pages + 1):
! dialog.startPage(page)
! if page > 1:
! dialog.addPageButton(60, 444, 9909, 9911, page - 1)
! dialog.addText(88, 444, "Previous Page", 2100)
! if page < pages:
! dialog.addPageButton(448, 444, 9903, 9905, page + 1)
! dialog.addText(376, 448, "Next Page", 2100)
! yoffset = 0
! for i in range(0, 5):
! skill = (page - 1) * 5 + i
! if skill >= ALLSKILLS:
! break
! skillname = SKILLNAMES[skill]
! skillname = skillname[0].upper() + skillname[1:]
! dialog.addResizeGump(65, 109 + yoffset, 9200, 405, 62)
! dialog.addText(76, 115 + yoffset, "Skill: %s (%u)" % (skillname, skill), 2100)
! dialog.addResizeGump(123, 135 + yoffset, 9300, 63, 26)
! dialog.addText(76, 137 + yoffset, "Value:", 2100)
! dialog.addText(187, 138 + yoffset, "%", 2100)
! dialog.addInputField(128, 138 + yoffset, 50, 20, 2100, 0x1000 | skill, "%0.01f" % (target.char.skill[skill] / 10.0))
! dialog.addText(232, 138 + yoffset, "Cap:", 2100)
! dialog.addText(329, 139 + yoffset, "%", 2100)
! dialog.addResizeGump(264, 135 + yoffset, 9300, 63, 26)
! dialog.addInputField(268, 139 + yoffset, 53, 20, 2100, 0x2000 | skill, "%0.01f" % (target.char.skillcap[skill] / 10.0))
! yoffset += 65
! dialog.send(player)
#
***************
*** 120,125 ****
#
def edit(socket, command, arguments):
! socket.sysmessage('Please select a character whose skills you want to view.')
! socket.attachtarget('commands.skillinfo.callback', [])
#
--- 121,126 ----
#
def edit(socket, command, arguments):
! socket.sysmessage('Please select a character whose skills you want to view.')
! socket.attachtarget('commands.skillinfo.callback', [])
#
***************
*** 127,129 ****
#
def onLoad():
! wolfpack.registercommand('skillinfo', edit)
--- 128,130 ----
#
def onLoad():
! wolfpack.registercommand('skillinfo', edit)
|