Raised This Month: $ Target: $400
 0% 

Why does this plugin makes the server crash?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 01-02-2022 , 14:26   Why does this plugin makes the server crash?
Reply With Quote #1

Hello. The following plugin makes it possible for bots to be forced to buy items from the humans' Extra Items menu:

PHP Code:
#include <amxmodx>
#include <zombie_plague_advance>


/*================================================================================
 [Plugin Customization]
=================================================================================*/

// Items name (note: add exact item name)

new const EXTRA_ITEMS[][] = {
    
"Plasma Gun",
    
"Golden Ak 47",
    
"Item3"
}

/*================================================================================
 Customization ends here! Yes, that's it. Editing anything beyond
 here is not officially supported. Proceed at your own risk...
=================================================================================*/

enum
{
    
TASK_STARTGIVE 298,
    
TASK_GIVEITEM
}

#define ID_BOT (taskid - TASK_GIVEITEM)

new cvar_max_botsg_botname[33][32], g_has_item[33], g_maxplayers;

public 
plugin_init()
{
    
/* Plugin register */
    
register_plugin("[ZP] Bot Addon: Force buy items""v0.2""Crazy");

    
/* Cvars */
    
cvar_max_bots register_cvar("zp_force_buy_maxbots""5");

    
/* Max players */
    
g_maxplayers get_maxplayers()
}

public 
client_putinserver(id)
{
    if (
is_user_bot(id))
        
get_user_name(idg_botname[id], charsmax(g_botname[]));
}

public 
zp_round_started(gamemodeid)
{
    for (new 
id 1id <= g_maxplayersid++)
        
g_has_item[id] = false;

    if (
gamemode != MODE_PLAGUE || MODE_SURVIVOR)
        
set_task(2.0"give_item_task"TASK_STARTGIVE);
}

public 
give_item_task(taskid)
{
    static 
idiBotsiMaxBots;
    
iBots 0;
    
iMaxBots get_pcvar_num(cvar_max_bots);

    while (
iBots <= iMaxBots)
    {
        
id get_random_bot(random_num(1get_alive_bots()));

        if (!
is_user_alive(id))
            continue;

        if (
zp_get_user_zombie(id))
            continue;

        if (
g_has_item[id])
            continue;

        
set_task(1.0"give_item"id+TASK_GIVEITEM);

        
iBots++;
    }

    
remove_task(TASK_STARTGIVE);
    
remove_task(TASK_GIVEITEM);
}

public 
give_item(taskid)
{
    static 
idrandomitemid;
    
id ID_BOT;
    
random random_num(0sizeof EXTRA_ITEMS 1);
    
itemid zp_get_extra_item_id(EXTRA_ITEMS[random]);

    if (
itemid == -1)
    {
        
set_task(0.5"give_item"id+TASK_GIVEITEM);
        return;
    }

    
zp_force_buy_extra_item(iditemid1);
    
g_has_item[id] = true;
    
remove_task(id+TASK_GIVEITEM);
}

get_alive_bots()
{
    static 
iBotid;
    
iBot 0;

    for (
id 1id <= g_maxplayersid++)
    {
        if (
is_user_alive(id) && is_user_bot(id))
            
iBot++;
    }

    return 
iBot;
}

get_random_bot(n)
{
    static 
iBotid;
    
iBot 0;

    for (
id 1id <= g_maxplayersid++)
    {
        if (
is_user_alive(id) && is_user_bot(id))
            
iBot++;

        if (
iBot == n)
            return 
id;
    }

    return -
1;

In the following code, you need to type the names of the extra items you want the bots to have access to:

Code:
// Items name (note: add exact item name)

new const EXTRA_ITEMS[][] = {
	"Plasma Gun",
	"Golden Ak 47",
	"Item3"
}
The problem is that the plugin works only during normal infection round, Nemesis mode, Assassin mode, Swarm mode, Multiple infection mode, Plague mode, Armageddon mode, but makes the server to crash during Survivor mode and Sniper mode. During Armageddon round and Plague round, there are survivors, too, but then the server doesn't crash. The server crash only when the game mode is mode where there is only one Sniper or only one Survivor, and all other players are zombies. Can someone fix this bug? I'm using ZPA 1.6.1.

If you are going to help me, don't forget to explain to me what code(s) exactly you edited, so i can learn for myself.

Thanks.

Last edited by GlobalPlague; 01-02-2022 at 14:28.
GlobalPlague 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 11:30.


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