AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   BOT Random Cut The Right Wire (https://forums.alliedmods.net/showthread.php?t=332065)

731 04-21-2021 03:22

BOT Random Cut The Right Wire
 
how to make the bot random cut the right wire,instead of directly dismantling the bomb

Code:

/*        Copyright ?2008, ConnorMcLeod

        Cut The Right Wire is free software;
        you can redistribute it and/or modify it under the terms of the
        GNU General Public License as published by the Free Software Foundation.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with Cut The Right Wire; if not, write to the
        Free Software Foundation, Inc., 59 Temple Place - Suite 330,
        Boston, MA 02111-1307, USA.
*/

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "Cut The Right Wire"
#define AUTHOR "ConnorMcLeod"
#define VERSION "0.0.2"

#define MAX_PLAYERS        32

#define TEAM_CT        2

#define PEV_PDATA_SAFE        2

#define EXTRAOFFSET                                        5
#define ACTUAL_EXTRA_OFFSET                        20

#define OFFSET_TEAM                114
#define OFFSET_MENUID        205

#define OFFSET_C4_EXPLODE_TIME                100
#define OFFSET_C4_DEFUSING                        0x181

#define KEYS        ((1<<0)|(1<<1)|(1<<9))

new const g_szWrongWireMsgs[][] = {
        "CTRW_FAILED1",
        "CTRW_FAILED2"
}

new g_iMaxPlayers
new g_iWire
new g_iC4 = FM_NULLENT
new bool:g_bCanDefuse[MAX_PLAYERS+1]
new g_iPlayerInMenu
new bool:g_bBot[MAX_PLAYERS+1]
new g_iChooseMenu

public plugin_init()
{
        register_plugin(PLUGIN, VERSION, AUTHOR)

        if( !engfunc( EngFunc_FindEntityByString , FM_NULLENT , "classname" , "func_bomb_target" )
        &&  !engfunc( EngFunc_FindEntityByString , FM_NULLENT , "classname" , "info_bomb_target" )  )
        {
                pause("ad")
                return
        }

        register_dictionary("right_wire.txt")

        register_event("HLTV", "Event_HLTV_New_Round", "a", "1=0", "2=0")
        register_logevent("Logevent_Round_End", 2, "1=Round_End")

        register_menucmd((g_iChooseMenu = register_menuid("WireMenu")), KEYS ,"actionChooseWire");

        RegisterHam(Ham_Use, "grenade", "C4_Use")

        g_iMaxPlayers = get_maxplayers()
}

public client_putinserver(id)
{
        if( (g_bBot[id] = bool:is_user_bot(id)) )
        {
                g_bCanDefuse[id] = true
        }
}

public client_disconnect(id)
{
        g_bBot[id] = false
}

public Event_HLTV_New_Round()
{
        g_iC4 = FM_NULLENT
        g_iPlayerInMenu = 0
        g_iWire = random_num(0,1)
        for( new id = 1 ; id <= g_iMaxPlayers ; id++ )
        {
                g_bCanDefuse[id] = g_bBot[id] ? true : false
        }
}

public Logevent_Round_End()
{
        g_iC4 = FM_NULLENT
}

ShowMenu(id)
{
        new szMenu[192]
        formatex(szMenu, charsmax(szMenu), "%L", id, "CTRW_CHOOSE")
        show_menu(id, KEYS, szMenu, _, "WireMenu")
}

public actionChooseWire(id, iKey)
{
        if( iKey == g_iWire )
        {
                g_bCanDefuse[id] = true
        }
        else
        {
                Explode_c4()
                Failed_Msg(id)
        }
        return PLUGIN_HANDLED
}

public C4_Use(iC4, id, idactivator, use_type, Float:value)
{
        if( use_type != 2 || value != 1.0 )
        {
                UTIL_ServerConsole_Printf("usetype: %d , val:%f", use_type, value)
                return HAM_IGNORED
        }

        if( get_pdata_int(id, OFFSET_TEAM, EXTRAOFFSET) != TEAM_CT )
        {
                return HAM_IGNORED
        }

        if( g_iC4 != iC4 )
        {
                g_iC4 = iC4
        }

        if( !g_bCanDefuse[id] )
        {
                if( !g_iPlayerInMenu
                ||  !is_user_alive( g_iPlayerInMenu )
                ||  get_pdata_int(g_iPlayerInMenu, OFFSET_MENUID, EXTRAOFFSET) != g_iChooseMenu )
                {
                        g_iPlayerInMenu = id
                        ShowMenu(id)
                }
                return HAM_SUPERCEDE
        }

        return HAM_IGNORED
}

Explode_c4()
{
        if( pev_valid(g_iC4) == PEV_PDATA_SAFE )
        {
                set_pdata_float(g_iC4, OFFSET_C4_EXPLODE_TIME, 0.0, EXTRAOFFSET)
        }
}

Failed_Msg(id)
{
        new szName[32]
        get_user_name(id, szName, charsmax(szName))
        client_print(0, print_chat, "%L", LANG_PLAYER, g_szWrongWireMsgs[random_num(0,charsmax(g_szWrongWireMsgs))], szName)
}

stock UTIL_ServerConsole_Printf(const fmt[], any:...) // from shptools
{
        static string[512]
        vformat(string, charsmax(string), fmt, 2)
        server_print(string)

        static basedir[64], date[16], time[16], fp
        get_localinfo("amxx_basedir",basedir,63)
        get_time("%H:%M:%S", time, 15)

        static logfile[192]
        if(logfile[0] == 0)
        {
                get_time("%m%d", date, 15)
                formatex(logfile, 127, "%s/logs/CTRW_%s.log", basedir, date)
        }

        get_time("%m/%d/%Y", date, 15)
        fp = fopen(logfile, "a")
        fprintf(fp, "L %s - %s: %s^n", date, time, string)
        fclose(fp)
}


731 06-19-2021 11:10

Re: BOT Random Cut The Right Wire
 
DJEarthQuake I do not understand what you are saying

+ARUKARI- 06-20-2021 20:15

Re: BOT Random Cut The Right Wire
 
Not tested.

Code:
/*  Copyright ?2008, ConnorMcLeod     Cut The Right Wire is free software;     you can redistribute it and/or modify it under the terms of the     GNU General Public License as published by the Free Software Foundation.     This program is distributed in the hope that it will be useful,     but WITHOUT ANY WARRANTY; without even the implied warranty of     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     GNU General Public License for more details.     You should have received a copy of the GNU General Public License     along with Cut The Right Wire; if not, write to the     Free Software Foundation, Inc., 59 Temple Place - Suite 330,     Boston, MA 02111-1307, USA. */ #include <amxmodx> #include <fakemeta> #include <hamsandwich> #define PLUGIN "Cut The Right Wire" #define AUTHOR "ConnorMcLeod" #define VERSION "0.0.2" #define MAX_PLAYERS 32 #define TEAM_CT 2 #define PEV_PDATA_SAFE  2 #define EXTRAOFFSET                 5 #define ACTUAL_EXTRA_OFFSET         20 #define OFFSET_TEAM     114 #define OFFSET_MENUID   205 #define OFFSET_C4_EXPLODE_TIME      100 #define OFFSET_C4_DEFUSING          0x181 #define KEYS    ((1<<0)|(1<<1)|(1<<9)) new const g_szWrongWireMsgs[][] = {     "CTRW_FAILED1",     "CTRW_FAILED2" } new g_iMaxPlayers new g_iWire new g_iC4 = FM_NULLENT new bool:g_bCanDefuse[MAX_PLAYERS+1] new g_iPlayerInMenu new bool:g_bBot[MAX_PLAYERS+1] new g_iChooseMenu public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     if( !engfunc( EngFunc_FindEntityByString , FM_NULLENT , "classname" , "func_bomb_target" )     &&  !engfunc( EngFunc_FindEntityByString , FM_NULLENT , "classname" , "info_bomb_target" )  )     {         pause("ad")         return     }     register_dictionary("right_wire.txt")     register_event("HLTV", "Event_HLTV_New_Round", "a", "1=0", "2=0")     register_logevent("Logevent_Round_End", 2, "1=Round_End")     register_menucmd((g_iChooseMenu = register_menuid("WireMenu")), KEYS ,"actionChooseWire");     RegisterHam(Ham_Use, "grenade", "C4_Use")     g_iMaxPlayers = get_maxplayers() } public client_putinserver(id) {     // if( (g_bBot[id] = bool:is_user_bot(id)) )     // {     //  g_bCanDefuse[id] = true     // } } public client_disconnect(id) {     g_bBot[id] = false } public Event_HLTV_New_Round() {     g_iC4 = FM_NULLENT     g_iPlayerInMenu = 0     g_iWire = random_num(0,1)     for( new id = 1 ; id <= g_iMaxPlayers ; id++ )     {         g_bCanDefuse[id] = g_bBot[id] ? true : false     } } public Logevent_Round_End() {     g_iC4 = FM_NULLENT } ShowMenu(id) {     new szMenu[192]     formatex(szMenu, charsmax(szMenu), "%L", id, "CTRW_CHOOSE")     show_menu(id, KEYS, szMenu, _, "WireMenu") } public actionChooseWire(id, iKey) {     if( iKey == g_iWire )     {         g_bCanDefuse[id] = true     }     else     {         Explode_c4()         Failed_Msg(id)     }     return PLUGIN_HANDLED } public C4_Use(iC4, id, idactivator, use_type, Float:value) {     if( use_type != 2 || value != 1.0 )     {         UTIL_ServerConsole_Printf("usetype: %d , val:%f", use_type, value)         return HAM_IGNORED     }     if( get_pdata_int(id, OFFSET_TEAM, EXTRAOFFSET) != TEAM_CT )     {         return HAM_IGNORED     }     if( g_iC4 != iC4 )     {         g_iC4 = iC4     }     if( !g_bCanDefuse[id] )     {         if( !g_iPlayerInMenu         ||  !is_user_alive( g_iPlayerInMenu )         ||  get_pdata_int(g_iPlayerInMenu, OFFSET_MENUID, EXTRAOFFSET) != g_iChooseMenu )         {             g_iPlayerInMenu = id            if (is_user_bot(id))                 actionChooseWire(id, random_num(0, 1))             else                 ShowMenu(id)         }         return HAM_SUPERCEDE     }     return HAM_IGNORED } Explode_c4() {     if( pev_valid(g_iC4) == PEV_PDATA_SAFE )     {         set_pdata_float(g_iC4, OFFSET_C4_EXPLODE_TIME, 0.0, EXTRAOFFSET)     } } Failed_Msg(id) {     new szName[32]     get_user_name(id, szName, charsmax(szName))     client_print(0, print_chat, "%L", LANG_PLAYER, g_szWrongWireMsgs[random_num(0,charsmax(g_szWrongWireMsgs))], szName) } stock UTIL_ServerConsole_Printf(const fmt[], any:...) // from shptools {     static string[512]     vformat(string, charsmax(string), fmt, 2)     server_print(string)     static basedir[64], date[16], time[16], fp     get_localinfo("amxx_basedir",basedir,63)     get_time("%H:%M:%S", time, 15)     static logfile[192]     if(logfile[0] == 0)     {         get_time("%m%d", date, 15)         formatex(logfile, 127, "%s/logs/CTRW_%s.log", basedir, date)     }     get_time("%m/%d/%Y", date, 15)     fp = fopen(logfile, "a")     fprintf(fp, "L %s - %s: %s^n", date, time, string)     fclose(fp) }

731 06-21-2021 03:01

Re: BOT Random Cut The Right Wire
 
thank you very much, after testing, the bot can randomly select wires

do you need to delete the code here?

Code:

new bool:g_bBot[MAX_PLAYERS+1]
Code:

public client_putinserver(id)
{
    // if( (g_bBot[id] = bool:is_user_bot(id)) )
    // {
    //  g_bCanDefuse[id] = true
    // }
}

public client_disconnect(id)
{
    g_bBot[id] = false
}

Code:

public Event_HLTV_New_Round()
{
    g_iC4 = FM_NULLENT
    g_iPlayerInMenu = 0
    g_iWire = random_num(0,1)
    for( new id = 1 ; id <= g_iMaxPlayers ; id++ )
    {
        g_bCanDefuse[id] = g_bBot[id] ? true : false
    }
}


+ARUKARI- 06-21-2021 19:57

Re: BOT Random Cut The Right Wire
 
Yes, I just made it work quickly, so if you want to make clean changes, you should remove unnecessary code.

731 06-22-2021 04:14

Re: BOT Random Cut The Right Wire
 
this code
Code:

g_bCanDefuse[id] = g_bBot[id] ? true : false
need to be changed to false?
Code:

g_bCanDefuse[id] = false


All times are GMT -4. The time now is 19:53.

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