Raised This Month: $ Target: $400
 0% 

Why does this plugin makes the server crash?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
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 #1

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

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