This commit is contained in:
Major-
2014-02-14 23:04:26 +00:00
parent 8038833df8
commit e899528f45
+11 -7
View File
@@ -4,17 +4,19 @@ java_import 'org.apollo.game.model.Npc'
java_import 'org.apollo.game.model.World' java_import 'org.apollo.game.model.World'
java_import 'org.apollo.game.model.Position' java_import 'org.apollo.game.model.Position'
# An array of npcs that cannot be spawned.
blacklist = [] blacklist = []
# Spawns a non-blacklisted npc in the specified position, or the player's position if both 'x' and 'y' are not supplied.
on :command, :spawn, RIGHTS_ADMIN do |player, command| on :command, :spawn, RIGHTS_ADMIN do |player, command|
args = command.arguments args = command.arguments
unless [1, 3].include? args.length and (id = args[0].to_i) > -1 unless [1, 3].include? args.length and (id = args[0].to_i) > -1
player.send_message("Invalid syntax - ::spawn [npc id] [x] [y]") player.send_message('Invalid syntax - ::spawn [npc id] [optional-x] [optional-y]')
return return
end end
if blacklist.include? id if blacklist.include? id
player.send_message("Sorry, that npc is blacklisted!") player.send_message("Sorry, npc #{id} is blacklisted!")
return return
end end
@@ -23,16 +25,16 @@ on :command, :spawn, RIGHTS_ADMIN do |player, command|
World.world.register(Npc.new(id, position)) World.world.register(Npc.new(id, position))
end end
# Mass spawns npcs around the player.
on :command, :mass, RIGHTS_ADMIN do |player, command| on :command, :mass, RIGHTS_ADMIN do |player, command|
args = command.arguments args = command.arguments
unless args.length == 2 and (id = args[0].to_i) > -1 and (1..5).include? (range = args[1].to_i) unless args.length == 2 and (id = args[0].to_i) > -1 and (1..5).include? (range = args[1].to_i)
player.send_message("Invalid syntax - ::spawn [npc id] [range (1-5)]") player.send_message('Invalid syntax - ::spawn [npc id] [range (1-5)]')
return return
end end
if blacklist.include? id if blacklist.include? id
player.send_message("Sorry, that npc is blacklisted!") player.send_message("Sorry, npc #{id} is blacklisted!")
return return
end end
@@ -42,19 +44,21 @@ on :command, :mass, RIGHTS_ADMIN do |player, command|
minY = center_position.y - range minY = center_position.y - range
maxX = center_position.x + range maxX = center_position.x + range
maxY = center_position.y + range maxY = center_position.y + range
z = center_position.height
for x in minX..maxX do for x in minX..maxX do
for y in minY..maxY do for y in minY..maxY do
World.world.register(Npc.new(id, Position.new(x, y, center_position.height))) World.world.register(Npc.new(id, Position.new(x, y, z)))
end end
end end
player.send_message("Mass spawning npcs with id #{id}.") player.send_message("Mass spawning npcs with id #{id}.")
end end
# Unregisters all npcs from the world npc repository.
on :command, :clearnpcs, RIGHTS_ADMIN do |player, command| on :command, :clearnpcs, RIGHTS_ADMIN do |player, command|
iterator = World.world.npc_repository.iterator iterator = World.world.npc_repository.iterator
while iterator.has_next while iterator.has_next
World.world.unregister(iterator.next) World.world.unregister(iterator.next)
end end
player.send_message("All npcs removed.") player.send_message('Unregistered all npcs from the world.')
end end