Created
January 26, 2013 01:01
-
-
Save cacciatc/4639353 to your computer and use it in GitHub Desktop.
Wolf bot functionality.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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