AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   CSDM FFA enable/disable with certain amount of players (https://forums.alliedmods.net/showthread.php?t=338117)

Napoleon_be 06-08-2022 08:23

CSDM FFA enable/disable with certain amount of players
 
Hi all,

I've been trying to create a subplugin for CSDM to enable or disable the FFA mode when a certain amount of players are CT/TS. I've tried 2 different aproaches but the server still crashes without any errors.

Here are the 2 aproaches i've tried but with the same result, surely it has something to do with the checks, but i'm not sure what. FFA is enabled by default and should only be disabled when a certain amount of players have joined a team. But somehow, the second check passes no matter what, even though csdm_get_ffa() should return true and not false at that point. (The commented part is how i first tried it and makes the most sense as there should be no need for a bool here.)

Help is appreciated, thanks.

PHP Code:

/* Sublime AMXX Editor v2.2 */

#include <amxmodx>
#include <csdm>
#include <cromchat>
// #include <amxmisc>
// #include <cstrike>
// #include <engine>
// #include <fakemeta>
// #include <hamsandwich>
// #include <fun>
// #include <xs>
// #include <sqlx>

#pragma semicolon 1
#pragma library csdm_main

#define PLUGIN  "[SYS] FFA Changer"
#define VERSION "1.0.0"
#define AUTHOR  "LadderGoat"

#if AMXX_VERSION_NUM < 183
    
const MAX_PLAYERS 32;
    const 
MAX_NAME_LENGTH 32;
    const 
MAX_FMT_LENGTH 256;
#endif

new pPlayerLimit;

new 
g_iCurTeam[MAX_PLAYERS 1] = { 'U' , ... };

new 
bool:g_bEnabled;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);

    
//register_logevent("teamJoined", 3, "1=joined team");

    
register_event("TeamInfo""playerJoinedTeam""a");

    
pPlayerLimit register_cvar("ffa_playerlimit""16");
}

public 
playerJoinedTeam()
{
    static 
idid read_data(1);
    static 
szTeam[2]; read_data(2szTeam1);

    if(
g_iCurTeam[id] != szTeam[0])
    {
        
g_iCurTeam[id] = szTeam[0];

        switch(
szTeam[0])
        {
            case 
'T'getTotalPlayers();
            case 
'C'getTotalPlayers();
        }
    }
}

public 
getTotalPlayers()
{
    new 
iTerPlayers[MAX_PLAYERS], iTerNum;
    
get_players(iTerPlayersiTerNum"che""TERRORIST");

    new 
iCtPlayers[MAX_PLAYERS], iCtNum;
    
get_players(iCtPlayersiCtNum"che""CT");

    new 
iNum iTerNum iCtNum;

    if(
iNum >= get_pcvar_num(pPlayerLimit) && csdm_get_ffa() && csdm_active())
    {
        
csdm_set_ffa(0);

        for(new 
i3i++)
        {
            
ColorChat(0GREEN"[SYS]^1 FFA has been^4 DISABLED^1 because enough players joined the server!");
        }

        
g_bEnabled false;
    }

    else if(
iNum get_pcvar_num(pPlayerLimit) && !g_bEnabled && csdm_active())
    {
        
csdm_set_ffa(1);

        for(new 
i3i++)
        {
            
ColorChat(0GREEN"[SYS]^1 FFA has been^4 ENABLED^1 again!");
        }

        
g_bEnabled true;
    }
}

/*public teamJoined()
{
    new iTerPlayers[MAX_PLAYERS], iTerNum;
    get_players(iTerPlayers, iTerNum, "che", "TERRORIST");

    new iCtPlayers[MAX_PLAYERS], iCtNum;
    get_players(iCtPlayers, iCtNum, "che", "CT");

    new iNum = iTerNum + iCtNum;

    if(iNum >= get_pcvar_num(pPlayerLimit) && csdm_get_ffa() && csdm_active())
    {
        csdm_set_ffa(0);

        for(new i; i < 2; i++)
        {
            ColorChat(0, GREEN, "[SYS]^1 FFA has been^4 DISABLED^1 because enough players joined the server!");
        }
    }

    else if(iNum < get_pcvar_num(pPlayerLimit) && !csdm_get_ffa() && csdm_active())
    {
        csdm_set_ffa(1);

        for(new i; i < 2; i++)
        {
            ColorChat(0, GREEN, "[SYS]^1 FFA has been^4 ENABLED^1 again!");
        }
    }
}*/ 



All times are GMT -4. The time now is 21:18.

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