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

[TUT] Registering hams on bots.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 00:46.


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