View Single Post
Author Message
yagami
Senior Member
Join Date: Jan 2021
Old 08-23-2023 , 10:19   Testing AI with AMXX
Reply With Quote #1

I don't know if I'm in the right area, sorry to the admins if I'm not

Good morning, I was playing with some AI's and asked them if they understood AMXX so I did some tests

some were good, others didn't even make sense, I don't know if anyone has already done this test but I found it interesting
I took the plugin "Advanced Bullet Damage" and asked him to optimize the code so what do you think?


New Code
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta_util>

#define PLUGIN "Advanced Bullet Damage"
#define VERSION "1.0"
#define AUTHOR "Sn!ff3r"

new g_typeg_enabledg_recievedbool:g_showrecievedg_hudmsg1g_hudmsg2

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_event("Damage""on_damage""b""2!0""3=0""4!0")
    
register_event("HLTV""on_new_round""a""1=0""2=0")

    
g_type register_cvar("amx_bulletdamage""1")
    
g_recieved register_cvar("amx_bulletdamage_recieved""1")

    
g_hudmsg1 CreateHudSyncObj()
    
g_hudmsg2 CreateHudSyncObj()
}

public 
on_new_round()
{
    
g_enabled get_pcvar_num(g_type)
    
g_showrecieved get_pcvar_num(g_recieved)
}

public 
on_damage(id)
{
    if (!
g_enabled)
        return

    static 
attackerdamage
    attacker 
get_user_attacker(id)
    
damage read_data(2)

    if (
g_showrecieved)
    {
        
set_hudmessage(255000.450.5020.14.00.10.1, -1)
        
ShowSyncHudMsg(idg_hudmsg2"%i^n"damage)
    }

    if (
is_user_connected(attacker))
    {
        if (
g_enabled == || (g_enabled == && fm_is_ent_visible(attackerid)))
        {
            
set_hudmessage(0100200, -1.00.5520.14.00.020.02, -1)
            
ShowSyncHudMsg(attackerg_hudmsg1"%i^n"damage)
        }
    }


That's the change AI made
Code:
In this optimized version, the following improvements have been made: 
 
- Removed unnecessary static declarations within the loop. 
- The g_showrecieved variable is set directly by the value of the g_recieved cvar. 
- Simplified the logic for checking the value of g_enabled using an if . 
- Removed the unnecessary switch and replaced it with an if to check the value of g_enabled . 
- Removed the is_user_connected(attacker) condition from the switch, as it is already checked in the outer if. 
 
Be sure to test the optimized code and adjust it as necessary. If you have any more questions, feel free to ask!
yagami is offline