cmd_set.rb
znmud-0.0.1/cmd/zombie/cmd_set.rb · 2.9 KB
From the archive znmud-minimal-0.0.1.tar.gz
Download the archive « Back to the archive contents
#
# file:: cmd_set.rb
# author:: Jon A. Lambert
# version:: 2.8.0
# date:: 02/21/2005
#
# Additional Contributor: Craig Smith
#
# This source code copyright (C) 2005, 2006 by Jon A. Lambert
# All rights reserved.
#
# Released under the terms of the TeensyMUD Public License
# See LICENSE file for additional information.
#
module Cmd
# sets the description or timer for an object
# Syntax:
# @set desc #<id> <description>
# @set key #<id> <description>
# @set timer #<id> <on|off>
# @set attr #<id> <attribute> (ex. :stuck)
# @set val #<id> <key>=<value>
# @set alias #<id> <alias>
# @set weight #<id> #
# (ex. @set desc #1 A beautiful rose.)
def cmd_set(args)
case args
when nil, ""
sendto("What??")
when /desc\s+#(\d+)\s+(.*)/
o = get_object($1.to_i)
case o
when nil, 0
sendto("No object.")
else
o.desc = $2
sendto("Object #" + $1 + " description set.")
end
when /key\s+#(\d+)\s+(.*)/
o = get_object($1.to_i)
case o
when nil, 0
sendto("No object.")
else
o.key = $2
sendto("Object #" + $1 + " key set.")
end
when /timer\s+#(\d+)\s+(on|off)\s+(.*)/
o = get_object($1.to_i)
case o
when nil
sendto("No object.")
else
if $2 == 'on'
if $3 =~ /(\w+)\s+(\d+)/
world.set_timer(o.id, $1.to_sym, $2.to_i)
sendto("Object ##{o.id} registered with timer.")
else
sendto("Bad symbol or missing time")
end
else
if $3 =~ /(\w+)/
world.unset_timer(o.id, $1.to_sym)
sendto("Object ##{o.id} unregistered with timer.")
else
sendto("Bad symbol")
end
end
end
when /attr\s+#(\d+)\s+(\S+)/
o = get_object($1.to_i)
if o
if o.has_attribute? $2
o.del_attribute $2
sendto("Attribute removed")
else
o.add_attribute $2
sendto("Attribute set")
end
else
sendto("Object not found")
end
when /^val\s+#(\d+)\s+(\w+)\s*=\s*(.*)/
o = get_object($1.to_i)
if o
key = $2
value = $3
value = $1.to_i if value=~/^(\d+)$/
if not value == ""
o.add_val(key, value)
sendto("Attribute value set")
else
o.del_val(key)
sendto("Attribute value unset")
end
else
sendto("Object not found")
end
when /^alias\s+#(\d+)\s+(.+)/
o = get_object($1.to_i)
if o
a = $2
if o.aliases.include? a
o.aliases.delete a
sendto("Removed alias.")
else
o.aliases << a
sendto("Added alias.")
end
else
sendto("Object not found")
end
when /weight #(\d+) (\d+)/
o = get_object($1.to_i)
w = $2.to_i
if o
o.weight = w
sendto("Weight set.")
end
else
sendto("@set what? Type @wizhep @set for more info")
end
end
end