Skip to content

Instantly share code, notes, and snippets.

@cacciatc
Created January 26, 2013 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cacciatc/4639353 to your computer and use it in GitHub Desktop.
Save cacciatc/4639353 to your computer and use it in GitHub Desktop.
Wolf bot functionality.
var bot = bot || plugin("bot",
{
/* helper methods for a player's bot */
get_bot: function(player){
return this.store.players[player.name];
},
set_bot: function(player,bot,inventory){
this.store.players[player.name] = {bot:bot,inventory:inventory};
},
/*
summons your bot
*/
summon: function(){
var player = getPlayerObject();
var world = player.getWorld();
// in case you already have one spawned
this.dismiss();
// place wolf two squares in front of you
var my_bot = world.spawnCreature(player.getLocation().add(0,0,2), org.bukkit.entity.EntityType.WOLF);
my_bot.setTamed(true);
my_bot.setOwner(player);
my_bot.setTarget(player);
var inventory;
var b = this.get_bot(player);
if(b == null || b.inventory == null)
inventory = player.getServer().createInventory(player, 18, "Bot's Pack");
else
inventory = b.inventory;
this.set_bot(player,my_bot,inventory);
},
/*
dismisses your bot
*/
dismiss: function(){
var b = this.get_bot(getPlayerObject());
if( b != null && b.bot !== null){
b.bot.remove();
b.bot = null;
}
},
/*
instructs your bot to stay
*/
stay: function(){
var b = this.get_bot(getPlayerObject());
if(b!= null && b.bot !== null){
b.bot.setTarget(null);
b.bot.setSitting(true);
}
},
/*
instructs your bot to follow you
*/
come: function(){
var b = this.get_bot(getPlayerObject());
if(b!= null){
b.bot.setSitting(false);
b.bot.setTarget(getPlayerObject());
}
},
/*
instructs your bot to display its pack
*/
pack: function(){
var b = this.get_bot(getPlayerObject());
if(b!= null && b.bot !== null){
b.bot.setSitting(true);
getPlayerObject().openInventory(b.inventory);
}
}
},true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment