Last active
December 13, 2015 10:34
-
-
Save nickelpro/098e7158019365f67de6 to your computer and use it in GitHub Desktop.
Example of movement with new pathfinding
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
from spockbot.plugins.tools.event import EVENT_UNREGISTER | |
from spockbot.plugins.base import PluginBase | |
from spockbot.vector import Vector3 | |
class NickelproFollow(PluginBase): | |
requires = ( | |
'Chat', 'ClientInfo', 'Entities', 'Event', 'Movement', 'Interact' | |
) | |
events = { | |
'chat': 'handle_chat', | |
'entity_player_spawn': 'handle_player_spawn', | |
'movement_path_done': 'handle_path_done' | |
} | |
def __init__(self, ploader, settings): | |
super(NickelproFollow, self).__init__(ploader, settings) | |
self.handle_gaming_chat = True | |
self.player_list = {} | |
def handle_chat(self, name, data): | |
if self.handle_gaming_chat: | |
data['message'] = ' '.join(data['text'].split(' ')[1:]) | |
if not data['message']: | |
return | |
# print(data['message']) | |
m = data['message'].split(' ') | |
if len(m) == 2 and m[0] == 'target' and m[1] in self.player_list: | |
self.target = m[1] | |
self.chat.chat('Targeting ' + m[1]) | |
return | |
elif data['message'] == 'path': | |
target_eid = self.player_list.get(self.target, None) | |
if target_eid not in self.entities.players: | |
return | |
p = Vector3(self.entities.players[target_eid]) | |
self.movement.move_to(p) | |
def handle_player_spawn(self, name, player): | |
if player.uuid in self.clientinfo.player_list: | |
name = self.clientinfo.player_list[player.uuid].name | |
self.player_list[name] = player.eid | |
def handle_path_done(self, _, __): | |
self.event.reg_event_handler('action_tick', self.look_at_target) | |
def look_at_target(self, _, __): | |
if not self.movement.is_moving: | |
return EVENT_UNREGISTER | |
self.interact.look_at(self.movement.final_target + Vector3(0, 1.8, 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment