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

Orpheu: Control CZ Bots


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-10-2010 , 05:05   Orpheu: Control CZ Bots
Reply With Quote #1

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.

PHP Code:

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

If you have any doubts, have no problem to ask me for stuff.
Attached Files
File Type: zip czbots.zip (11.3 KB, 407 views)
__________________
joaquimandrade 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 19:17.


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