View Single Post
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-18-2021 , 11:01   Re: ham_spawn not works for yapb bot
Reply With Quote #8

Quote:
Originally Posted by WATCH_DOGS UNITED View Post
Hi! We were able to make our code work with bots. But this required to duplicate the code (1 for humans and 1 for bots). Could you show us the code registering with RegisterHamFromEntity?
Here
PHP Code:
#include <amxmodx>
#include <hamsandwich>

new bool:registeredHamForBots

public plugin_init()
{
    
RegisterHam(Ham_Spawn"player""SpawnHook"1)
}


public 
client_putinserver(id)
{
    if(
is_user_bot(id) && !registeredHamForBots)
    {
        
registeredHamForBots true
        set_task
(0.1"registerHamForBots"id)
    }
}

public 
registerHamForBots(id)
{
    
RegisterHamFromEntity(Ham_Spawnid"SpawnHook"true)
}

public 
SpawnHook(id)
{
    if(
is_user_alive(id))
    {
        
//do stuff for both players and bots here
    
}

No need to duplicate any code.
__________________

Last edited by HamletEagle; 09-24-2021 at 02:40.
HamletEagle is offline