new g_HamsNotRegistered new g_CZBotPlayerID new g_MaxPlayers new cvar_bot_quota
new Array:g_PluginID new Array:g_PluginCallback new Array:g_HamFunctionID new Array:g_HamFunctionIsPost new Array:g_HamForwardHandle new Array:g_HamForwardEnable new g_BotHooksCount
// Hook is already disabled if (!ArrayGetCell(g_HamForwardEnable, ham_hook_index)) return true;
// Is this forward already registered? if (ArrayGetCell(g_HamForwardHandle, ham_hook_index) != INVALID_HANDLE) { // We have the forward handle, disable right away new ham_forward_handle = ArrayGetCell(g_HamForwardHandle, ham_hook_index) DisableHamForward(HamHook:ham_forward_handle) }
// If we don't have a forward handle, disable it once it's registered ArraySetCell(g_HamForwardEnable, ham_hook_index, false) return true; }
public native_enable_ham_forward_bots(plugin_id, num_params) { new ham_hook_index = get_param(1)
// Hook is already enabled if (ArrayGetCell(g_HamForwardEnable, ham_hook_index)) return true;
// Is this forward already registered? if (ArrayGetCell(g_HamForwardHandle, ham_hook_index) != INVALID_HANDLE) { // We have the forward handle, enable right away new ham_forward_handle = ArrayGetCell(g_HamForwardHandle, ham_hook_index) EnableHamForward(HamHook:ham_forward_handle) }
// If we don't have a forward handle, enable it once it's registered ArraySetCell(g_HamForwardEnable, ham_hook_index, true) return true; }
public client_disconnect(id_leaving) { // Our CZ Bot used for registering hooks is leaving if (id_leaving == g_CZBotPlayerID) { // Can we find a replacement? new index = 1 while ((!is_user_connected(index) || !is_user_bot(index) || index == id_leaving) && (index <= g_MaxPlayers)) index++ // keep looping
// Update player ID if (index <= g_MaxPlayers) g_CZBotPlayerID = index else g_CZBotPlayerID = 0 } }
public client_putinserver(id) { // CZ bots seem to use a different "classtype" for player entities // (or something like that) which needs to be hooked separately if (is_user_bot(id) && cvar_bot_quota) { // Set a task to let the private data initialize set_task(0.1, "register_ham_czbots", id) } }
// Register Ham Forwards for CZ bots public register_ham_czbots(id_bot) { // Make sure it's a CZ bot and it's still connected if (!is_user_connected(id_bot) || !get_pcvar_num(cvar_bot_quota)) return;
// Save CZ Bot Player ID in case we need to register any more forwards later g_CZBotPlayerID = id_bot
// Nothing to hook? if (!g_HamsNotRegistered) return;
new index, plugin_id, plugin_filename[64], ham_function_id, plugin_callback[64], is_post, func_id, ham_forward_handle, plugin_is_paused for (index = 0; index < g_BotHooksCount; index++) { // Already registered if (ArrayGetCell(g_HamForwardHandle, index) != INVALID_HANDLE) continue;
// Ham forward was disabled if (!ArrayGetCell(g_HamForwardEnable, index)) { DisableHamForward(HamHook:ham_forward_handle) } else if (ham_function_id == _:Ham_Spawn && is_user_alive(id_bot) && !plugin_is_paused) { // If the bot has already spawned, call Ham_Spawn forward manually for him (bugfix) func_id = get_func_id(plugin_callback, plugin_id) callfunc_begin_i(func_id, plugin_id) callfunc_push_int(id_bot) callfunc_end() } }
// Ham forwards for CZ bots succesfully registered g_HamsNotRegistered = false }