Orpheu: Control CZ Bots

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

Orpheu: Control CZ Bots

Post by Archive-Poster »

Many people asked me how to control CZ Bots. I decided to collect a pack with virtual functions + a bonus of 3 non virtual functions. You can use this as introduction and then search for more functions yourself.

I put together some base code to use those functions. On it, a hook to the bot creation is made so virtual functions can be get. The rest should be easy to understand. Non virtual functions ship with signature so you can use them on a plugin release. I used plugin_precache and plugin_init but that distintion is not really needed it was just for clarity.

Code: Select all

#include <amxmodx>
#include <orpheu>

/* Code for non-virtual functions */

new OrpheuFunction:Follow
new OrpheuFunction:Attack
new OrpheuFunction:Panic

public plugin_precache()
{
    Follow = OrpheuGetFunction("Follow","CCSBot")
    Attack = OrpheuGetFunction("Attack","CCSBot")
    Panic = OrpheuGetFunction("Panic","CCSBot")
}

/* Code for virtual functions */

new OrpheuHook:CCSBotHook

public plugin_init()
{
    CCSBotHook = OrpheuRegisterHook(OrpheuGetFunction("CCSBot","CCSBot"),"OnCCSBot",OrpheuHookPost)    
}

new OrpheuFunction:SetModel
new OrpheuFunction:SpawnBot
new OrpheuFunction:Jump
new OrpheuFunction:MoveBackward
new OrpheuFunction:MoveForward
new OrpheuFunction:StrafeRight
new OrpheuFunction:StrafeLeft
new OrpheuFunction:Initialize
new OrpheuFunction:Reload
new OrpheuFunction:PrimaryAttack
new OrpheuFunction:IsPlayerFacingMe
new OrpheuFunction:IsPlayerLookingAtMe
new OrpheuFunction:ExecuteCommand
new OrpheuFunction:IsEnemyPartVisible

public OnCCSBot(id)
{
    new botReference = OrpheuGetReturn()
    
    SetModel = OrpheuGetFunctionFromObject(botReference,"SetModel","CCSBot")
    SpawnBot = OrpheuGetFunctionFromObject(botReference,"SpawnBot","CCSBot")
    Jump = OrpheuGetFunctionFromObject(botReference,"Jump","CCSBot")
    MoveBackward = OrpheuGetFunctionFromObject(botReference,"MoveBackward","CCSBot")
    MoveForward = OrpheuGetFunctionFromObject(botReference,"MoveForward","CCSBot")
    StrafeLeft = OrpheuGetFunctionFromObject(botReference,"StrafeLeft","CCSBot")
    StrafeRight = OrpheuGetFunctionFromObject(botReference,"StrafeRight","CCSBot")
    Initialize = OrpheuGetFunctionFromObject(botReference,"Initialize","CCSBot")
    Reload = OrpheuGetFunctionFromObject(botReference,"Reload","CCSBot")
    PrimaryAttack = OrpheuGetFunctionFromObject(botReference,"PrimaryAttack","CCSBot")

    OrpheuRegisterHook(SpawnBot,"OnSpawnBot")

    OrpheuRegisterHook(Jump,"OnMovement")
    OrpheuRegisterHook(MoveBackward,"OnMovement")
    OrpheuRegisterHook(MoveForward,"OnMovement")
    OrpheuRegisterHook(StrafeLeft,"OnMovement")
    OrpheuRegisterHook(StrafeRight,"OnMovement")
        
    OrpheuUnregisterHook(CCSBotHook)
}

public OrpheuHookReturn:OnMovement(id)
{
    //return OrpheuSupercede
}

public OnSpawnBot(id)
{
    server_print("Spawned bot %d",id)
}

public plugin_cfg()
{
    register_clcmd("bots_follow","follow")
    register_clcmd("bots_jump","jump")
}

public follow(id)
{
    for(new i=1;i<=32;i++)
    {
        if(is_user_alive(i) && is_user_bot(i))
        {            
            OrpheuCall(Follow,i,id)
        }
    }
    
    return PLUGIN_HANDLED
}

public jump(id)
{    
    for(new i=1;i<=32;i++)
    {
        if(is_user_alive(i) && is_user_bot(i))
        {            
            OrpheuCall(Jump,i,1)
        }
    }
    
    return PLUGIN_HANDLED
} 
Ok, there weren't many. Just two.
Attachments
czbots.zip
(11.29 KiB) Downloaded 4 times

Who is online

Users browsing this forum: No registered users and 1 guest