Specifically, can I go from a CBaseClient pointer to a player index/pointer/instance with a SP conversion function?
Syntax: Select all
from memory import make_object, get_object_pointer
from memory.hooks import PreHook
from entities.helpers import index_from_edict
from filters.players import PlayerIter
from players import BaseClient, PlayerGenerator
from players.entity import Player
from engines.server import server, engine_server
def preSetName(args):
base_client_pointer = args[0]
for edict in PlayerGenerator():
if base_client_pointer == (get_object_pointer(server.get_client(index_from_edict(edict) - 1)) - 4):
player = Player(index_from_edict(edict))
def load_when_human(args=False):
global pre_hook_set_name
for player in PlayerIter():
base_client = make_object(BaseClient, player.base_client)
pre_hook_set_name = PreHook(base_client.set_name)
pre_hook_set_name(preSetName)
if args:
event_manager.unregister_for_event("player_activate", load_when_human)
break
else:
raise ValueError('No human player found!')
try:
load_when_human()
except ValueError:
from events.manager import event_manager
event_manager.register_for_event("player_activate", load_when_human)