Warn if the id parameter of ::remove is out of bounds.

This commit is contained in:
Major-
2014-02-21 20:58:45 +00:00
parent 2d3522dea1
commit b06bd36d55
+24 -18
View File
@@ -1,33 +1,39 @@
require 'java'
java_import 'org.apollo.game.model.def.ItemDefinition'
# Adds the specified item to the player's own inventory.
on :command, :item, RIGHTS_ADMIN do |player, command|
args = command.arguments
if (1..2).include? args.length
id = args[0].to_i
amount = args.length == 2 ? args[1].to_i : 1
if (id < 0 || id >= ItemDefinition.count)
player.send_message('The item id you specified is out of bounds!')
next
end
player.inventory.add(id, amount)
else
player.send_message('Syntax: ::item [id] [amount=1]')
unless (1..2).include? args.length
player.send_message('Invalid syntax - ::item [id] [amount]')
next
end
id = args[0].to_i, amount = args.length == 2 ? args[1].to_i : 1
if (id < 0 || id >= ItemDefinition.count)
player.send_message('The item id you specified is out of bounds!')
next
end
player.inventory.add(id, amount)
end
# Removes the specified item from the player's own inventory.
on :command, :remove, RIGHTS_MOD do |player, command|
args = command.arguments
if (1..2).include? args.length
id = args[0].to_i
amount = args.length == 2 ? args[1].to_i : 1
player.inventory.remove(id, amount)
else
player.send_message('Syntax: ::remove [id] [amount=1]')
unless (1..2).include? args.length
player.send_message('Invalid syntax - ::remove [id] [amount]')
next
end
id = args[0].to_i, amount = args.length == 2 ? args[1].to_i : 1
if (id < 0 || id >= ItemDefinition.count)
player.send_message('The item id you specified is out of bounds!')
next
end
player.inventory.remove(id, amount)
end
# Clears the player's own inventory.