Entities
This part refers to the class IEntityList.cs, which can be accessed through Context.Entities. This should be used when getting/finding entities/mobs/other players and will generally only return those values which have not been (yet) unloaded by the server, usually meaning that they are still in the entity render distance of the server.
Methods | Events |
GetBots | onEntityAdded |
GetClosestBot | onEntityRemoved |
GetPlayers | onEntityMoved |
GetPlayer | onPlayerMoved |
GetPlayerByUuid | |
GetClosestPlayer | |
GetEntities | |
GetEntity | |
GetClosestEntity | |
GetMobs | |
GetClosestMob | |
GetObjects | |
GetItemStackObjects | |
GetClosestObject | |
GetAllLoadedNames |
Methods
GetBots
Returns a collection of IPlayerEntity where each entry corresponds to a (rendered) bot's entity. This may not get all bot entities in cases where the other bots are outside of this bot's entity render distance.
GetClosestBot
Returns the closest other bot's entity to the given position. This may return null if no bots are connected/in entity render distance.
GetPlayers
Returns a collection of IPlayerEntity where each entry corresponds to a (rendered) player on the server. This can include bot entities depending on the parameters.
GetPlayer
Returns a single IPlayerEntity according to the specified parameters.
GetPlayerByUuid
Returns a single IPlayerEntity according to the specified uuid.
GetClosestPlayer
Returns the closest other IPlayerEntity to the specified position. This can include bot entities depending on the parameters.
* optionalValidityCheck - optional parameter, which if not null will be called with a IPlayerEntity parameter. If this functions returns true then the entity will be processed, otherwise it will not be considered for the returned collection.
Example call:
// Gets the closest player who's name starts with "Bot".
Context.Entities.GetClosestPlayer(true, playerEntity => playerEntity.GetName().StartsWith("Bot"));
GetEntities
Returns a collection of ILiving where each entry corresponds to a (rendered) entity, such as an animal, a monster, and optionally can include players.
GetEntity
Returns a single ILiving according to the specified entity id.
GetClosestEntity
Returns the closest other ILiving to the specified position. This can include player entities depending on the parameters.
* optionalValidityCheck - optional parameter, which if not null will be called with a ILiving parameter. If this functions returns true then the entity will be processed, otherwise it will not be considered for the returned collection.
GetMobs
Returns a collection of IMobEntity where each entry corresponds to a (rendered) mob, such as an animal, or a monster. The parameters of this function allow you to specify what sort of monsters can be included in the collection (e.g.: all, aggressive, passive, zombies).
GetClosestMob
Returns the closest IMobEntity to the specified position. This can look only for specific mob types, such as aggressive (MobType.Aggressive), passive (MobType.Pasive), zombies (MobType.Zomboe).
* optionalValidityCheck - optional parameter, which if not null will be called with a IMobEntity parameter. If this functions returns true then the entity will be processed, otherwise it will not be considered for the returned collection.
GetObjects
Returns a collection of IObjectEntity where each entry corresponds to an object, which is a special type of entity that will not show up when searching the internal entity list with GetEntities(). An example of an object is a dropped stack of items on the ground or an arrow.
GetItemStackObjects
Returns a collection of IObjectEntity where each entry corresponds to an object, where each entry corresponds to a stack of items on the ground. This is a wrapper function for GetObjects().
GetClosestObject
Returns the closest IObjectEntity to the specified position. This can look for specific types of objects (e.g.: arrows, item stacks).
* optionalValidityCheck - optional parameter, which if not null will be called with a IObjectEntity parameter. If this functions returns true then the entity will be processed, otherwise it will not be considered for the returned collection.
GetAllLoadedNames
Returns all loaded uuid to name links from the server.
Events
You can register a function to an event with the '+=' operator.
E.g.: Context.Events.OnChat += ChatMessageHandler;
onEntityAdded
Event that is called when any entity is added to the loaded entity list. This includes players, mobs, and other entity types. The add event can be cancelled by setting the EvenCancelToken to isCancelled = true, which would make it not add the entity to the bot's entity list.
onEntityRemoved
Event that is called when any entity is removed from the loaded entity list. This includes players, mobs, and other entity types. The add event can be cancelled by setting the EvenCancelToken to isCancelled = true, which would make it not remove the entity from the bot's entity list.
onEntityMoved
Event that is called when any entity moves/is moved. This includes players, mobs, and other entity types.
onPlayerMoved
Event that is called when a player entity moves/is moved.
Example code using Entities
The code below searches for an player entity with the name "OnlyQubes". If the player is not found then the bot does nothing, otherwise if the player is found then we move to it's location and attempt to hit the closest aggressive mob while moving.
Last updated