mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 16:49:12 +00:00
Update lookup plugin to use entity-spawning plugin instead of duplicating code.
This commit is contained in:
@@ -8,21 +8,21 @@ java_import 'org.apollo.game.model.def.ObjectDefinition'
|
|||||||
on :command, :lookup, RIGHTS_ADMIN do |player, command|
|
on :command, :lookup, RIGHTS_ADMIN do |player, command|
|
||||||
args = command.arguments.to_a
|
args = command.arguments.to_a
|
||||||
unless args.length > 1
|
unless args.length > 1
|
||||||
player.send_message("Invalid syntax - ::lookup [npc/object/item] [name]")
|
player.send_message('Invalid syntax - ::lookup [npc/object/item] [name]')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
type = args.shift.downcase
|
type = args.shift.downcase
|
||||||
name = args.join(" ").downcase
|
name = args.join(' ').downcase
|
||||||
|
|
||||||
if ['npc', 'object', 'item'].index(type) == nil
|
if ['npc', 'object', 'item'].index(type) == nil
|
||||||
player.send_message("Invalid syntax - ::lookup [npc/object/item] [name]")
|
player.send_message('Invalid syntax - ::lookup [npc/object/item] [name]')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
ids = locate_entity(type, name).join(" ")
|
ids = locate_entity(type, name).join(", ")
|
||||||
|
|
||||||
message = ids.empty? ? "Could not find an #{type} called #{name}." : "Possible ids are: #{ids}"
|
message = ids.empty? ? "Could not find an #{type} called #{name}." : "Possible ids are: #{ids}."
|
||||||
player.send_message(message)
|
player.send_message(message)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -30,14 +30,14 @@ end
|
|||||||
on :command, :iteminfo, RIGHTS_ADMIN do |player, command|
|
on :command, :iteminfo, RIGHTS_ADMIN do |player, command|
|
||||||
args = command.arguments
|
args = command.arguments
|
||||||
unless args.length == 1
|
unless args.length == 1
|
||||||
player.send_message("Invalid syntax - ::iteminfo [item id]")
|
player.send_message('Invalid syntax - ::iteminfo [item id]')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
id = args[0].to_i
|
id = args[0].to_i
|
||||||
definition = ItemDefinition.lookup(id)
|
definition = ItemDefinition.lookup(id)
|
||||||
|
|
||||||
members = definition.is_members_only ? "members" : "not members"
|
members = definition.is_members_only ? 'members' : 'not members'
|
||||||
player.send_message("Item #{id} is called #{definition.name}, is #{members} only, and has a team of #{definition.team}.")
|
player.send_message("Item #{id} is called #{definition.name}, is #{members} only, and has a team of #{definition.team}.")
|
||||||
player.send_message("Its description is \"#{definition.description}\".")
|
player.send_message("Its description is \"#{definition.description}\".")
|
||||||
end
|
end
|
||||||
@@ -56,15 +56,4 @@ on :command, :npcinfo, RIGHTS_ADMIN do |player, command|
|
|||||||
is_combative = definition.has_combat_level ? "has a combat level of #{definition.combat_level}" : "does not have a combat level"
|
is_combative = definition.has_combat_level ? "has a combat level of #{definition.combat_level}" : "does not have a combat level"
|
||||||
player.send_message("Npc #{id} is called #{definition.name} and #{is_combative}.")
|
player.send_message("Npc #{id} is called #{definition.name} and #{is_combative}.")
|
||||||
player.send_message("Its description is \"#{definition.description}\".")
|
player.send_message("Its description is \"#{definition.description}\".")
|
||||||
end
|
|
||||||
|
|
||||||
# Locates an entity with the specified type (e.g. npc) and name, returning possible ids as an array.
|
|
||||||
def locate_entity(type, name, limit=5)
|
|
||||||
ids = []
|
|
||||||
name.downcase!
|
|
||||||
Kernel.const_get("#{type.capitalize}Definition").definitions.each do |definition|
|
|
||||||
break if ids.length == limit
|
|
||||||
ids << definition.id.to_i if definition.name.to_s.downcase == name
|
|
||||||
end
|
|
||||||
return ids
|
|
||||||
end
|
end
|
||||||
@@ -10,5 +10,7 @@
|
|||||||
<scripts>
|
<scripts>
|
||||||
<script>lookup.rb</script>
|
<script>lookup.rb</script>
|
||||||
</scripts>
|
</scripts>
|
||||||
<dependencies />
|
<dependencies>
|
||||||
|
<dependency>entity-spawning</dependency>
|
||||||
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
Reference in New Issue
Block a user