Raised This Month: $12 Target: $400
 3% 

[TUT] Registering hams on bots.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-09-2017 , 18:42   [TUT] Registering hams on bots.
Reply With Quote #1

[TUT] Registering hams on bots.

I'm not sure, but it seems to me that some of those acquisitions module hamsandwich whose entityClass is "player" are not understood by bots, it ends up causing a certain headache who used to test your plugins in local mode.

Well, it's very simple. We just need to register the ham directly in the entity of the bot.

First of all, let's add some includes.
PHP Code:
#include <amxmodx>
#include <hamsandwich> 
Now, let's create some variables.
PHP Code:
new g_hambots// This variable will check if the hams have been recorded
new cvar_botquota// This variable will check if there is bots in the game 
Now, let's store in varialvel cvar_botquota, the value of bots found in the game and register a test Ham_TakeDamage.
PHP Code:
public plugin_init()
{
    
register_plugin("Register Ham Bots""v0.1""Crazy");
    
    
// Get bot_quota number
    
cvar_botquota get_cvar_pointer("bot_quota");
    
    
// Register Ham_TakeDamage
    
RegisterHam(Ham_TakeDamage"player""fw_TakeDamage");

Now, let's call a task when the bot enter the game to register the hams.
PHP Code:
public client_putinserver(id)
{
    
// If the ID dont is bot
    
if (!is_user_bot(id))
        return;
        
    
// If the ham already registered
    
if (g_hambots)
        return;
        
    
// If dont have any bot in game
    
if (!cvar_botquota)
        return;
        
    
// Set a register ham bots task into bot id
    
set_task(0.1"fw_RegisterHamBots"id);

Now let's create our function to log ham in bots.
PHP Code:
public fw_RegisterHamBots(id)
{
    
// Ham Forwards
    
RegisterHamFromEntity(Ham_TakeDamageid"fw_TakeDamage"); // In this case, Ham_TakeDamage

    // Here you add any Ham you need
    
    // Register complete
    
g_hambots true;

Last, but not least, let's create our Ham_TakeDamage.
PHP Code:
public fw_TakeDamage(victiminflictorattackerFloat:damage)
{
    
// If dont is alive attacker
    
if (!is_user_alive(attacker))
        return 
HAM_IGNORED;
        
    
// Do something...
    
    
return HAM_SUPERCEDE;

And at the end we get this:
PHP Code:
#include <amxmodx>
#include <hamsandwich>

new g_hambots// This variable will check if the hams have been recorded
new cvar_botquota// This variable will check if there is bots in the game

public plugin_init()
{
    
register_plugin("Register Ham Bots""v0.1""Crazy");
    
    
// Get bot_quota number
    
cvar_botquota get_cvar_pointer("bot_quota");
    
    
// Register Ham_TakeDamage
    
RegisterHam(Ham_TakeDamage"player""fw_TakeDamage");
}

public 
client_putinserver(id)
{
    
// If the ID dont is bot
    
if (!is_user_bot(id))
        return;
        
    
// If the ham already registered
    
if (g_hambots)
        return;
        
    
// If dont have any bot in game
    
if (!cvar_botquota)
        return;
        
    
// Set a register ham bots task into bot id
    
set_task(0.1"fw_RegisterHamBots"id);
}

public 
fw_RegisterHamBots(id)
{
    
// Ham Forwards
    
RegisterHamFromEntity(Ham_TakeDamageid"fw_TakeDamage"); // In this case, Ham_TakeDamage

    // Here you add any Ham you need
    
    // Register complete
    
g_hambots true;
}

public 
fw_TakeDamage(victiminflictorattackerFloat:damage)
{
    
// If dont is alive attacker
    
if (!is_user_alive(attacker))
        return 
HAM_IGNORED;
        
    
// Do something...
    
    
return HAM_SUPERCEDE;

If you are in any doubt about what should, or not use, check the module hamsandwich. All the forwards that contain classes geared players, can be registered with the code that I taught you.

Well, that's all. Any suggestion, doubt or something, is welcome.
__________________









Last edited by CrazY.; 03-10-2017 at 17:16.
CrazY. is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-10-2017 , 02:28   Re: [TUT] Registering hams on bots.
Reply With Quote #2

If you use podbots you don't need any of this by the way. Best bots for testing in my opinion.
klippy is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-10-2017 , 05:12   Re: [TUT] Registering hams on bots.
Reply With Quote #3

Interesting, I didn't know this detail. But anyway, I prefer to use their own bots of contain-strike.
__________________








CrazY. is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-10-2017 , 12:01   Re: [TUT] Registering hams on bots.
Reply With Quote #4

PHP Code:
  // If the ID dont is bot
    
if (!is_user_bot(id))
        return;
        
    
// If the ham already registered
    
if (g_hambots)
        return;
        
    
// If dont have any bot in game
    
if (!get_pcvar_num(cvar_botquota))
        return; 
It's not needed inside fw_RegisterHamBots, the check is already done inside client_putinserver.
__________________
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 03-10-2017 , 12:29   Re: [TUT] Registering hams on bots.
Reply With Quote #5

Why are you setting a task in client_putinserver rather than just doing the stuff there?
__________________
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-10-2017 , 12:40   Re: [TUT] Registering hams on bots.
Reply With Quote #6

From my tests, this little task is needed. Looks like putinserver alone is a bit too early.
__________________
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 03-10-2017 , 13:20   Re: [TUT] Registering hams on bots.
Reply With Quote #7

Quote:
Originally Posted by HamletEagle View Post
From my tests, this little task is needed. Looks like putinserver alone is a bit too early.
0.1 seconds matter?
__________________
edon1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-10-2017 , 13:39   Re: [TUT] Registering hams on bots.
Reply With Quote #8

More like 1 frame matters probably.
klippy is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-10-2017 , 17:15   Re: [TUT] Registering hams on bots.
Reply With Quote #9

Quote:
Originally Posted by HamletEagle View Post
PHP Code:
  // If the ID dont is bot
    
if (!is_user_bot(id))
        return;
        
    
// If the ham already registered
    
if (g_hambots)
        return;
        
    
// If dont have any bot in game
    
if (!get_pcvar_num(cvar_botquota))
        return; 
It's not needed inside fw_RegisterHamBots, the check is already done inside client_putinserver.
Thank you for letting me know!
__________________








CrazY. is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 03-11-2017 , 02:14   Re: [TUT] Registering hams on bots.
Reply With Quote #10

You should hook PvAllocEntPrivateData call from gamedll, check the passed entity for bot and register ham on it. But you can't hook it with amxx, so then you should hook GetInfoKeyBuffer, it is first engine function called after PvAllocEntPrivateData on bot creating.

That is my old code for this:
PHP Code:
#include <amxmodx>
#include <fakemeta>

new g_iFakeClientByGameDll;

new 
g_fwdCreateFakeClient_Post;
new 
g_fwdGetInfoKeyBuffer;

public 
plugin_init() {
    
g_fwdCreateFakeClient_Post register_forward(FM_CreateFakeClient"CreateFakeClient_Post"true);
    
g_fwdGetInfoKeyBuffer register_forward(FM_GetInfoKeyBuffer"GetInfoKeyBuffer");
}

public 
CreateFakeClient_Post() {
    new 
iEntity get_orig_retval();
    
    if (!
pev_valid(iEntity)) {
        return;
    }
    
    
g_iFakeClientByGameDll iEntity;
}

public 
GetInfoKeyBuffer(const iEntity) {
    if (!
g_iFakeClientByGameDll) {
        return;
    }
    
    
g_iFakeClientByGameDll 0;
    
    
unregister_forward(FM_CreateFakeClientg_fwdCreateFakeClient_Posttrue);
    
unregister_forward(FM_GetInfoKeyBufferg_fwdGetInfoKeyBuffer);
    
    new 
iRet;
    new 
fwd CreateMultiForward("CSBot_Init"ET_IGNOREFP_CELL);
    
ExecuteForward(fwdiRetiEntity);
    
DestroyForward(fwd);

__________________

Last edited by PRoSToTeM@; 03-14-2017 at 21:05.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:45.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode