Raised This Month: $ Target: $400
 0% 

Why does this plugin makes the server crash?


Post New Thread Reply   
 
Thread Tools Display Modes
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
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-02-2022 , 16:09   Re: Why does this plugin makes the server crash?
Reply With Quote #2

Because there are some potential loopholes in your loops causing it to be stuck in an infinite loop.


And whats with your get_random_bot logerthem ? Same for get_alive_bots both of them are invalid!
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-02-2022 at 16:12.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-02-2022 , 16:14   Re: Why does this plugin makes the server crash?
Reply With Quote #3

Skip the other game modes too + what natsheh said above.

Code:
public zp_round_started(gamemode, id) {     for (new id = 1; id <= g_maxplayers; id++)         g_has_item[id] = false;     if (gamemode != MODE_PLAGUE && gamemode != MODE_SURVIVOR && gamemode != MODE_SNIPER ) // etc...         set_task(2.0, "give_item_task", TASK_STARTGIVE); }

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_bots, g_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(id, g_botname[id], charsmax(g_botname[])); } public zp_round_started(gamemode, id) {     for (new id = 1; id <= g_maxplayers; id++)         g_has_item[id] = false;     if (gamemode != MODE_PLAGUE && gamemode != MODE_SURVIVOR && gamemode != MODE_SNIPER)         set_task(2.0, "give_item_task", TASK_STARTGIVE); } public give_item_task(taskid) {     static id, iBots, iMaxBots;     iBots = 0;     iMaxBots = get_pcvar_num(cvar_max_bots);     /* Why do you loop here? You can create an infinite loop because not everytime botid will be different. */     for (new i; i <= iMaxBots; i++)     {         id = get_random_bot(i);         // We dont have any more bots, break the loop         if(id == -2)             break;         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 id, random, itemid;     id = ID_BOT;     random = random_num(0, sizeof 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(id, itemid, 1);     g_has_item[id] = true;     remove_task(id+TASK_GIVEITEM); } get_random_bot(index) {     new iPlayers[MAX_PLAYERS], iNum;     get_players(iPlayers, iNum, "ad");     if(iNum < index)         return -2;     return iNum > 0 ? iPlayers[index] : -1; }

Not tested.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 01-02-2022 at 16:32. Reason: lmfao, forgot to text
Shadows Adi is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-02-2022 , 16:16   Re: Why does this plugin makes the server crash?
Reply With Quote #4

Quote:
Originally Posted by Shadows Adi View Post
Skip the game modes if

Code:
public zp_round_started(gamemode, id) {     for (new id = 1; id <= g_maxplayers; id++)         g_has_item[id] = false;     if (gamemode != MODE_PLAGUE && gamemode != MODE_SURVIVOR && gamemode != MODE_SNIPER ) // etc...         set_task(2.0, "give_item_task", TASK_STARTGIVE); }

What?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-02-2022 , 16:33   Re: Why does this plugin makes the server crash?
Reply With Quote #5

Quote:
Originally Posted by Natsheh View Post
What?
My bad, forgot to text the message lmao
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 01-02-2022 , 18:02   Re: Why does this plugin makes the server crash?
Reply With Quote #6

Don't use that plugin, it's complete garbage and I know, I'm the author. Use this one, will work on any game mode.

Code:
#include <amxmodx>
#include <zombieplague>

new const EXTRA_ITEMS[][] = {
	"Balrog Ethereal"
}

new cvar_max_bots

new g_extraItems[sizeof EXTRA_ITEMS], g_extraItemCount

public plugin_init()
{
	register_plugin("Bots Buy Extra Items", "1.1", "Ainsley Harriott")
	cvar_max_bots = register_cvar("zp_force_buy_maxbots", "3")
}

public plugin_cfg()
{
	for (new i, itemid; i < sizeof EXTRA_ITEMS; i++)
	{
		itemid = zp_get_extra_item_id(EXTRA_ITEMS[i])

		if (itemid != -1)
		{
			g_extraItems[g_extraItemCount++] = itemid
		}
	}
}

public zp_round_started(gamemode, id)
{
	if (g_extraItemCount > 0)
	{
		GiveBotExtraItems()
	}
}

GiveBotExtraItems()
{
	new bots[32], botCount
	new humanBots[32], humanBotCount

	get_players(bots, botCount, "adh")

	for (new i, bot; i < botCount; i++)
	{
		bot = bots[i]

		if (!zp_get_user_zombie(bot))
		{
			humanBots[humanBotCount++] = bot
		}
	}

	SortIntegers(humanBots, humanBotCount, Sort_Random)

	for (new i, bot, itemid, max = min(humanBotCount, get_pcvar_num(cvar_max_bots)); i < max; i++)
	{
		bot = humanBots[i]
		itemid = g_extraItems[random(g_extraItemCount)]
		zp_force_buy_extra_item(bot, itemid, 1)
	}
}
__________________









Last edited by CrazY.; 01-02-2022 at 18:05.
CrazY. is offline
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 01-26-2022 , 11:56   Re: Why does this plugin makes the server crash?
Reply With Quote #7

Quote:
Originally Posted by CrazY. View Post
Don't use that plugin, it's complete garbage and I know, I'm the author. Use this one, will work on any game mode.

Code:
#include <amxmodx>
#include <zombieplague>

new const EXTRA_ITEMS[][] = {
	"Balrog Ethereal"
}

new cvar_max_bots

new g_extraItems[sizeof EXTRA_ITEMS], g_extraItemCount

public plugin_init()
{
	register_plugin("Bots Buy Extra Items", "1.1", "Ainsley Harriott")
	cvar_max_bots = register_cvar("zp_force_buy_maxbots", "3")
}

public plugin_cfg()
{
	for (new i, itemid; i < sizeof EXTRA_ITEMS; i++)
	{
		itemid = zp_get_extra_item_id(EXTRA_ITEMS[i])

		if (itemid != -1)
		{
			g_extraItems[g_extraItemCount++] = itemid
		}
	}
}

public zp_round_started(gamemode, id)
{
	if (g_extraItemCount > 0)
	{
		GiveBotExtraItems()
	}
}

GiveBotExtraItems()
{
	new bots[32], botCount
	new humanBots[32], humanBotCount

	get_players(bots, botCount, "adh")

	for (new i, bot; i < botCount; i++)
	{
		bot = bots[i]

		if (!zp_get_user_zombie(bot))
		{
			humanBots[humanBotCount++] = bot
		}
	}

	SortIntegers(humanBots, humanBotCount, Sort_Random)

	for (new i, bot, itemid, max = min(humanBotCount, get_pcvar_num(cvar_max_bots)); i < max; i++)
	{
		bot = humanBots[i]
		itemid = g_extraItems[random(g_extraItemCount)]
		zp_force_buy_extra_item(bot, itemid, 1)
	}
}
Hello. When i tried to compile the code you gave me, i got the following 2 errors:

//AMXXPC compile.exe
// by the AMX Mod X Dev Team


//// buy_extra_items.sma
// C:\Mod\cstrike\addons\amxmodx\scripting\bot_s upport_extra_items.sma(56) : error 017: undefined symbol "Sort_Random"
// C:\Mod\cstrike\addons\amxmodx\scripting\bot_s upport_extra_items.sma(56 -- 5 : error 088: number of arguments does not match definition


Here is the whole code that contains the lines that are the source of errors (the lines are marked in red):

Code:
GiveBotExtraItems()
{
	new bots[32], botCount
	new humanBots[32], humanBotCount

	get_players(bots, botCount, "adh")

	for (new i, bot; i < botCount; i++)
	{
		bot = bots[i]

		if (!zp_get_user_zombie(bot))
		{
			humanBots[humanBotCount++] = bot
		}
	}

	SortIntegers(humanBots, humanBotCount, Sort_Random)

	for (new i, bot, itemid, max = min(humanBotCount, get_pcvar_num(cvar_max_bots)); i < max; i++)
	{
		bot = humanBots[i]
		itemid = g_extraItems[random(g_extraItemCount)]
		zp_force_buy_extra_item(bot, itemid, 1)
	}
}
GlobalPlague is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-02-2022 , 18:16   Re: Why does this plugin makes the server crash?
Reply With Quote #8

Here a better + fixed function to get a random bot with no replication!!

I saw alot of coders struggle to create such function there you go, try understanding...

PHP Code:
get_random_bot(arrNoReplicate[MAX_PLAYERS]="", &ReplicateSize=0)
{
    static 
iPlayers[MAX_PLAYERS], iNum;

    
get_players(iPlayersiNum"adh");

    if( 
ReplicateSize )
    {
        for(new 
ijiNumj++)
       {
           for(
0ReplicateSizei++)
           {
                if(
iPlayers] == arrNoReplicate])
                     
iPlayersj-- ] = iPlayers [ --iNum ];
           }
       }
    }
    
    if(!
iNum// uncomment and remove return 0; in the following if you want the function to never fails until legitimately there are no alive bots exists.
    
{
        
//ReplicateSize = 0;
        //get_players(iPlayers, iNum, "adh");
        
return 0;
    }

    new 
iChosen 0;

    if( 
iNum )
    {
        
iChosen iPlayersrandom(iNum) ] ;
        if(
MAX_PLAYERS ReplicateSizearrNoReplicate ReplicateSize++ ] = iChosen;
    }
        
    return 
iChosen;


This how to use inside the following function...

PHP Code:
public give_item_task(taskid)
{
    static 
iMaxBots;
    
iMaxBots get_pcvar_num(cvar_max_bots);

    for (new 
iidoldbots[MAX_PLAYERS], oldbots_countiMaxBotsi++)
    {
        if(! (
id get_random_bot(oldbotsoldbots_count)) )
            break;

        if (
zp_get_user_zombie(id))
            continue;

        if (
g_has_item[id])
            continue;

        
set_task(1.0"give_item"id+TASK_GIVEITEM);
    }

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-03-2022 at 00:55.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 01-26-2022 , 11:49   Re: Why does this plugin makes the server crash?
Reply With Quote #9

Quote:
Originally Posted by Natsheh View Post
Here a better + fixed function to get a random bot with no replication!!

I saw alot of coders struggle to create such function there you go, try understanding...

PHP Code:
get_random_bot(arrNoReplicate[MAX_PLAYERS]="", &ReplicateSize=0)
{
    static 
iPlayers[MAX_PLAYERS], iNum;

    
get_players(iPlayersiNum"adh");

    if( 
ReplicateSize )
    {
        for(new 
ijiNumj++)
       {
           for(
0ReplicateSizei++)
           {
                if(
iPlayers] == arrNoReplicate])
                     
iPlayersj-- ] = iPlayers [ --iNum ];
           }
       }
    }
    
    if(!
iNum// uncomment and remove return 0; in the following if you want the function to never fails until legitimately there are no alive bots exists.
    
{
        
//ReplicateSize = 0;
        //get_players(iPlayers, iNum, "adh");
        
return 0;
    }

    new 
iChosen 0;

    if( 
iNum )
    {
        
iChosen iPlayersrandom(iNum) ] ;
        if(
MAX_PLAYERS ReplicateSizearrNoReplicate ReplicateSize++ ] = iChosen;
    }
        
    return 
iChosen;


This how to use inside the following function...

PHP Code:
public give_item_task(taskid)
{
    static 
iMaxBots;
    
iMaxBots get_pcvar_num(cvar_max_bots);

    for (new 
iidoldbots[MAX_PLAYERS], oldbots_countiMaxBotsi++)
    {
        if(! (
id get_random_bot(oldbotsoldbots_count)) )
            break;

        if (
zp_get_user_zombie(id))
            continue;

        if (
g_has_item[id])
            continue;

        
set_task(1.0"give_item"id+TASK_GIVEITEM);
    }

Is this code going to fix the crash, caused by the plugin i posted in my original post? If yes, would you explain me where to put the code you gave me?
GlobalPlague is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 01-02-2022 , 19:12   Re: Why does this plugin makes the server crash?
Reply With Quote #10

Your code is not right either, it is not even working.

Code:
	 0. random bot id -> 9
	 1. random bot id -> 2
	 2. random bot id -> 0
	 3. random bot id -> 0
	 4. random bot id -> 0
	 5. random bot id -> 0
	 6. random bot id -> 0
	 7. random bot id -> 0
	 8. random bot id -> 0
	 9. random bot id -> 0
	 10. random bot id -> 0
	 11. random bot id -> 0
	 12. random bot id -> 0
	 13. random bot id -> 0
	 14. random bot id -> 0
	 15. random bot id -> 0
	 16. random bot id -> 0
	 17. random bot id -> 0
	 18. random bot id -> 0
	 19. random bot id -> 0
	 20. random bot id -> 0
	 21. random bot id -> 0
	 22. random bot id -> 0
	 23. random bot id -> 0
	 24. random bot id -> 0
	 25. random bot id -> 0
	 26. random bot id -> 0
	 27. random bot id -> 0
	 28. random bot id -> 0
	 29. random bot id -> 0
And you're calling get_players inside a loop. If you need 30 random bots your code will call get_players 30 times, like what is this
__________________








CrazY. is offline
Reply



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