[TUT] Registering hams on bots

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1229
Gender:
United States of America

[TUT] Registering hams on bots

Post by Archive-Poster »

[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.

Code: Select all

#include <amxmodx>
#include <hamsandwich> 
Now, let's create some variables.

Code: Select all

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.

Code: Select all

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.

Code: Select all

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.

Code: Select all

public fw_RegisterHamBots(id)
{
    // Ham Forwards
    RegisterHamFromEntity(Ham_TakeDamage, id, "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.

Code: Select all

public fw_TakeDamage(victim, inflictor, attacker, Float: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:

Code: Select all

#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_TakeDamage, id, "fw_TakeDamage"); // In this case, Ham_TakeDamage

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

public fw_TakeDamage(victim, inflictor, attacker, Float: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.

Who is online

Users browsing this forum: No registered users and 0 guests