Raised This Month: $ Target: $400
 0% 

TeamLock 5v5? Errors 3 and 4 help


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Hectik17
AlliedModders Donor
Join Date: Oct 2005
Old 04-09-2017 , 18:12   TeamLock 5v5? Errors 3 and 4 help
Reply With Quote #1

There was a stack error with check_teams check_ratio and get_players_in_teams

Also when a player subed in to spec when dead the player who replaced him on the round end, the match will restart an set score back to 0 during the first half.

Could anyone take a look and see if any thing Is out of place. Mainly around round_end task_match_ended is ment to be disabled for now because I want the teams to manually swapteams, if there is a way to enable vgui menu that be cool. It's using old style at because b4 when it was vgui menu players with old style could still join the teams when they were locked. So old menu had to be used. Thanks.

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>

#define PLUGIN "::Fair-Match:."
#define VERSION "rev2.0"
#define AUTHOR "Natsheh"

#define MAX_TEAMS         4
#define MAX_PLAYERS        32
#define OFFSET_TEAM        114
#define PLAYER_LINUXDIFF    5
#define VGUI_JOIN_TEAM_NUM    2

// teams variables...
new bool:team_avaialble[MAX_TEAMS];

// user booleans
new g_isConnected[MAX_PLAYERS+1];            //need bool ?? 

enum
{
    
TEAM_UNASSIGNED 0,
    
TEAM_TERRORIST,
    
TEAM_CT,
    
TEAM_SPECTATOR,
    
TEAM_AUTO_ASSIGN
}

// variables..
new g_iMaxplayersg_iMsgTeamInfo;
new 
g_roundsg_ctwing_terwin;

// cvars variables
new g_cvar_enableg_cvar_ratiog_match_rounds;

#define NEWMENUID    get_user_msgid("VGUIMenu")
#define OLDMENUID    get_user_msgid("ShowMenu")

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_cvar_enable register_cvar("fmatch_enable""1"ADMIN_BAN)
    
g_cvar_ratio register_cvar("fmatch_ratio""5"ADMIN_BAN)
    
g_match_rounds register_cvar("fmatch_match_rounds""15"ADMIN_BAN)
    
    
//register_logevent("freezetime_end", 2, "1=Round_Start"); // after freezetime        //causes issues disabled
    
register_event("HLTV""round_start""a""1=0""2=0"); // before freezetime
    
    
register_message(NEWMENUID"MessageVGUIMenu")
    
register_message(OLDMENUID"MessageShowMenu")
    
register_menucmd(register_menuid("Team_Select"true), (MENU_KEY_1|MENU_KEY_2|MENU_KEY_6|MENU_KEY_0), "old_jointeam_menu")
    
    
register_clcmd("jointeam""clcmd_join")
    
register_clcmd("chooseteam""clcmd_join")
    
    
register_event("TeamInfo""event_TeamInfo""a")
    
    
register_event("SendAudio""event_terwin""a""2&%!MRAD_terwin");
    
register_event("SendAudio""event_ctwin""a""2&%!MRAD_ctwin");
    
register_logevent("round_end"2"0=World triggered""1=Round_End");
    
//register_logevent("match_started", 2, "0=World triggered", "1&Restart_Round")        //these were effecting the roundcount
    //register_logevent("match_started", 2, "0=World triggered", "1=Game_Commencing")    //at the moment wahts registerd works perfect
    
register_event("TextMsg","match_started","a","2&#Game_C","2&#Game_w")
    
    
g_iMaxplayers get_maxplayers();
    
g_iMsgTeamInfo get_user_msgid("TeamInfo");
    
    for(new 
iTeam 0iTeam MAX_TEAMSiTeam++)
    {
        
team_avaialble[iTeam] = true;
    }
}

public 
event_terwin()
{
    if(!
get_pcvar_num(g_cvar_enable))
        return;
    
    
g_terwin++;
}

public 
event_ctwin()
{
    if(!
get_pcvar_num(g_cvar_enable))
        return;
    
    
g_ctwin++;
}

public 
match_started()
{
    if(!
get_pcvar_num(g_cvar_enable))
        return;
    
    
g_rounds 0;
    new 
g_match_rounds get_pcvar_num(g_match_rounds);
}

public 
event_TeamInfo()
{
    if(!
get_pcvar_num(g_cvar_enable))
        return;
    
    
//new id = read_data(1);
    
new sTeam[32];
    
read_data(2sTeamcharsmax(sTeam));
    
    if(
equal(sTeam"SPECTATOR"))
    {
        
check_teams();
    }
}

public 
client_disconnect(id)
{
    if(!
get_pcvar_num(g_cvar_enable))
        return;

    
g_isConnected[id] = false;    //added to try and fix a issue with player DC's or retrys then cant getback intoteam at all

    
check_teams();

}

public 
round_end()
{
    if(
g_rounds >= get_pcvar_num(g_match_rounds))
    {
        
set_cvar_num("fmatch_ratio"10)    //this is the way i made it able to change team manualy.
        
server_cmd("sv_restart");
    }
    {
        
check_teams();
    }
}

/**public task_match_ended()        //might be a old way of sending to spec i kno there is siplerway to do
{                    //"for(new id = 1; id <= g_iMaxplayers; id++)" maybey this notsure.
    // get players into teams..
    static TPlayers[MAX_TEAMS][MAX_PLAYERS], ctsnum, tsnum, unassigned, specsnum, i;
    get_players_inteams(TPlayers, ctsnum, tsnum, specsnum, unassigned)
    static id;
    for(i = 0; i < ctsnum; i++)
    {
        id = TPlayers[TEAM_CT][i]
        fm_set_user_team(id, TEAM_SPECTATOR)
    }

    for(i = 0; i < tsnum; i++)
    {
        id = TPlayers[TEAM_TERRORIST][i]
        fm_set_user_team(id, TEAM_SPECTATOR)
    }
    check_teams();
    set_cvar_num( "fmatch_ratio 10" );        //need to test might fix over flow whne auto swawp was enabled, but i dont want it to
    g_rounds = 0;                    //if you want autoswap uncomment and test, this add //set_task(3.0, "task_match_ended"); to line 133 above the }
    
    team_avaialble[TEAM_CT] = true;
    team_avaialble[TEAM_TERRORIST] = true;
    team_avaialble[TEAM_SPECTATOR] = true;
    // join team
    {
        set_task(0.1, "oldstyle_newmenu", i)    //added this from menucode line 321. was only working for T until "i" was added
        return;                    //not sure if needed this or a plugin_continue??
    }

}**/

public round_start()
{
    if(!
get_pcvar_num(g_cvar_enable))
        return;
    
    new 
ratio clamp(get_pcvar_num(g_cvar_ratio), 1floatround(Float:(g_iMaxplayers/2.0), floatround_floor))
    new 
cnumtnumplayers[32];
    
get_players(playerscnum"he""CT")
    
get_players(playerstnum"he""TERRORIST")
    if((
ratio*2) > (cnum+tnum))
    {
        
check_teams();
        return;
    }
    else if(!((
ratio == cnum) && (ratio == tnum)))
    {
        
//server_cmd("sv_restart 3")        //this stoped a sub making match RS during game but also stops balancing whne lo3 and more tahtn 5v5
    
}
    
    
check_ratio()
    
    
// counting rounds..
    
g_rounds++;
    
}

public 
client_putinserver(id)
{
    if(!
get_pcvar_num(g_cvar_enable))
        return;
        
    
g_isConnected[id] = true;        //was trying to fix issue cant retry and join team if clined dc or drops, did nothing with bots
    
    
check_teams();
}

public 
MessageShowMenu(msgidmsgdestid)
{
    if(!
get_pcvar_num(g_cvar_enable))
        return 
PLUGIN_CONTINUE;
    
    if(!
is_user_connected(id))
        return 
PLUGIN_CONTINUE;
    
    if(
get_msg_argtype(4) != ARG_STRING)
        return 
PLUGIN_CONTINUE;
    
    new 
StrMessage[24]
    
get_msg_arg_string(4StrMessagecharsmax(StrMessage))
    
    
// join team
    
if(equal(StrMessage"#Team_Select"strlen("#Team_Select")) || equal(StrMessage"#IG_Team_Select"strlen("#IG_Team_Select")))
    {
        
set_task(0.1"oldstyle_newmenu"id)
        return 
PLUGIN_HANDLED;
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
oldstyle_newmenu(id)
{
    if(!
is_user_connected(id))
        return;
    
    
// check teams..
    
check_teams();
    
    static 
sText[256], leniKeys;
    
    
len formatex(sTextcharsmax(sText), "Choose your team...^n^n")
    
    
len += formatex(sText[len], charsmax(sText)-len"\r1. %sTeam Terrorist^n"team_avaialble[TEAM_TERRORIST] ? "\w":"\d")
    
iKeys |= team_avaialble[TEAM_TERRORIST] ? MENU_KEY_1:~MENU_KEY_1
    len 
+= formatex(sText[len], charsmax(sText)-len"\r2. %sTeam Counter-terrorist^n^n^n"team_avaialble[TEAM_CT] ? "\w":"\d")
    
iKeys |= team_avaialble[TEAM_CT] ? MENU_KEY_2:~MENU_KEY_2
    
    len 
+= formatex(sText[len], charsmax(sText)-len"\r6. %sSpectator^n^n^n"is_user_alive(id) ? "\d":"\w")
    
iKeys |= is_user_alive(id) ? ~MENU_KEY_6:MENU_KEY_6
    
    len 
+= formatex(sText[len], charsmax(sText)-len"\r0. \yExit")
    
iKeys |= MENU_KEY_0
    
    show_menu
(idiKeyssText_"Team_Select")
}

public 
old_jointeam_menu(idikey)
{
    switch(
ikey)
    {
        case 
0:
        {
            if(
team_avaialble[TEAM_TERRORIST])
            {
                
fm_set_user_team(idTEAM_TERRORIST)
                
check_teams();
            }
            else
            {
                
client_print(idprint_center"The Terrorist team is not available right now!")
                return 
PLUGIN_HANDLED;
            }
        }
        case 
1:
        {
            if(
team_avaialble[TEAM_CT])
            {
                
fm_set_user_team(idTEAM_CT)
                
check_teams();
            }
            else
            {
                
client_print(idprint_center"The Counter terrorist team is not available right now!")
                return 
PLUGIN_HANDLED;
            }
        }
        case 
5:
        {
            if(
team_avaialble[TEAM_SPECTATOR] && !is_user_alive(id))
            {
                
fm_set_user_team(idTEAM_SPECTATOR)
                
check_teams();
            }
            else
            {
                return 
PLUGIN_HANDLED;
            }
        }
        case 
9:
        {
            return 
PLUGIN_CONTINUE;
        }
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
MessageVGUIMenu(msgidmsgdestid)
{
    if(!
get_pcvar_num(g_cvar_enable) || !is_user_connected(id))
        return 
PLUGIN_CONTINUE;
    
    if(
get_msg_arg_int(1) == VGUI_JOIN_TEAM_NUM// user joined a team (NewMenu)
    
{
        
// user joined a team. (NewMenu)
        
set_task(0.1"oldstyle_newmenu"id)
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;
}

public 
task_joinclass(id)
{
    
engclient_cmd(id"joinclass""5")
}

public 
clcmd_join(id)
{
    if(!
get_pcvar_num(g_cvar_enable))
        return 
PLUGIN_CONTINUE;
    
    new 
sArg[5]
    
read_argv(1sArg4)
    switch( 
str_to_num(sArg) )
    {
        case 
1: if(!team_avaialble[TEAM_TERRORIST]) return PLUGIN_HANDLED;
        case 
2: if(!team_avaialble[TEAM_CT]) return PLUGIN_HANDLED;
        case 
5: return PLUGIN_HANDLED;
        default : return 
PLUGIN_CONTINUE;
    }
    
    return 
PLUGIN_CONTINUE;
}

get_players_inteams(Players[MAX_TEAMS][MAX_PLAYERS], &ctnum, &tsnum, &specnum, &unassigned)
{
    
get_players(Players[TEAM_CT], ctnum"eh""CT")
    
get_players(Players[TEAM_TERRORIST], tsnum"eh""TERRORIST")
    
    static 
players[32], pnumspecuna;
    
get_players(playerspnum"h")
    for(new 
0pnumi++)
    {
        switch( 
fm_get_user_team(players[i]) )
        {
            case 
TEAM_SPECTATORspec++;
            case 
TEAM_UNASSIGNEDuna++;
        }
    }
    
    
specnum spec;
    
unassigned una;
}

check_teams()
{
    new 
ratio clamp(get_pcvar_num(g_cvar_ratio), 1floatround(Float:(g_iMaxplayers/2.0), floatround_floor))
    
    
// get players into teams..
    
static TPlayers[MAX_TEAMS][MAX_PLAYERS], ctsnumtsnumunassignedspecsnum;
    
get_players_inteams(TPlayersctsnumtsnumspecsnumunassigned)
    
    
// no players..
    
if((ratio*2) > (ctsnum+tsnum))
    {
        
team_avaialble[TEAM_CT] = true;
        
team_avaialble[TEAM_TERRORIST] = true;
        return;
    }
    
    
// check teams if they are available..
    
team_avaialble[TEAM_CT] = (ctsnum ratio) ? true:false
    team_avaialble
[TEAM_TERRORIST] = (tsnum ratio) ? true:false
}

check_ratio()
{
    new 
ratio clamp(get_pcvar_num(g_cvar_ratio), 1floatround(Float:(g_iMaxplayers/2.0), floatround_floor))
    
    
// get players into teams..
    
static TPlayers[MAX_TEAMS][MAX_PLAYERS], ctsnumtsnumunassignedspecsnum;
    
get_players_inteams(TPlayersctsnumtsnumspecsnumunassigned)
    
    if((
ratio*2) > (ctsnum+tsnum))
        return;
    
    
// check if teams are available!
    
check_teams();
    
    
// few variables..
    
static sName[32], loopchosenplayer;
    
    if(
ratio != ctsnum)
    {
        
loop = (ratio ctsnum);
        
        if(
loop 0)
        {
            while(
loop)
            {
                if(
tsnum ratio)
                {
                    --
tsnum;
                    
chosen random(tsnum)
                    
player TPlayers[TEAM_TERRORIST][chosen]
                    
TPlayers[TEAM_TERRORIST][chosen] = TPlayers[TEAM_TERRORIST][tsnum]
                }   
                else break;
                
                
TPlayers[TEAM_CT][ctsnum] = player;
                ++
ctsnum;
                
fm_set_user_team(playerTEAM_CT)
                
get_user_name(playersName31)
                
client_print(0print_chat"%s has been transfered to counter-terrorist!"sName)
                
loop--;
            }
        }
        else 
//extra cts
        
{
            while(
loop 0)
            {
                --
ctsnum;
                
chosen random(ctsnum);
                
player TPlayers[TEAM_CT][chosen];
                
TPlayers[TEAM_CT][chosen] = TPlayers[TEAM_CT][ctsnum];
                
get_user_name(playersName31)
                
                if(
tsnum ratio// move them to terorist
                
{
                    
TPlayers[TEAM_TERRORIST][tsnum] = player;
                    ++
tsnum;
                    
fm_set_user_team(playerTEAM_TERRORIST)
                    
client_print(0print_chat"%s has been transfered to terrorist!"sName)
                }
                else 
// move them to spectators
                
{
                    
TPlayers[TEAM_SPECTATOR][specsnum] = player;
                    ++
specsnum;
                    
client_print(0print_chat"%s has been transfered to spectator!"sName)
                    
fm_set_user_team(playerTEAM_SPECTATOR)
                }
                
                
loop++;
            }
        }
    }
    
    if(
ratio != tsnum)
    {
        
loop = (ratio tsnum);
        
        if(
loop 0)
        {
            while(
loop--)
            {
                if(
ctsnum ratio)
                {
                    --
ctsnum;
                    
chosen random(ctsnum)
                    
player TPlayers[TEAM_CT][chosen]
                    
TPlayers[TEAM_CT][chosen] = TPlayers[TEAM_CT][ctsnum]
                }   
                else break;
                
                
TPlayers[TEAM_TERRORIST][tsnum] = player;
                ++
tsnum;
                
fm_set_user_team(playerTEAM_TERRORIST)
                
get_user_name(playersName31)
                
client_print(0print_chat"%s has been transfered to terrorist!"sName)
            }
        }
        else 
//extra ts
        
{
            while(
loop 0)
            {
                --
tsnum;
                
chosen random(tsnum);
                
player TPlayers[TEAM_TERRORIST][chosen];
                
TPlayers[TEAM_TERRORIST][chosen] = TPlayers[TEAM_TERRORIST][tsnum];
                
get_user_name(playersName31)
                
                if(
ctsnum ratio// move them to counter-terorist
                
{
                    
TPlayers[TEAM_CT][ctsnum] = player;
                    ++
ctsnum;
                    
fm_set_user_team(playerTEAM_CT)
                    
client_print(0print_chat"%s has been transfered to counter-terrorist!"sName)
                }
                else 
// move them to spectators
                
{
                    
TPlayers[TEAM_SPECTATOR][specsnum] = player;
                    ++
specsnum;
                    
client_print(0print_chat"%s has been transfered to spectator!"sName)
                    
fm_set_user_team(playerTEAM_SPECTATOR)
                }
                
                
loop++;
            }
        }
    }
    
    if(
ctsnum == ratioteam_avaialble[TEAM_CT] = false;
    if(
tsnum == ratioteam_avaialble[TEAM_TERRORIST] = false;
}

stock fm_get_user_team(index)
{
    new 
iteam get_user_team(index);
    
    switch( 
iteam )
    {
        case 
1: return TEAM_TERRORIST;
        case 
2: return TEAM_CT;
        case -
13: return TEAM_SPECTATOR;
        case 
0: return TEAM_UNASSIGNED
    
}
    
    return -
2;
}


stock fm_set_user_team(idteam)
{
    switch( 
team )
    {
        case 
TEAM_CTengclient_cmd(id"jointeam""2")
        case 
TEAM_TERRORISTengclient_cmd(id"jointeam""1")
        case 
TEAM_SPECTATORengclient_cmd(id"jointeam""6")
        case 
TEAM_AUTO_ASSIGN:
        {
            new 
sString[2]
            
team random_num(TEAM_TERRORISTTEAM_CT)
            
num_to_str(teamsStringcharsmax(sString))
            
engclient_cmd(id"jointeam"sString)
        }
        default: { 
            
log_error(AMX_ERR_NOTFOUND"Team with this id #%d is not found!"team)
            return
        }
    }
    
    
// set user team...
    
set_pdata_int(idOFFSET_TEAMteamPLAYER_LINUXDIFF)
    
set_pev(idpev_teamteam)
    
    static const 
TeamInfo[MAX_TEAMS][] = 
    { 
        
"UNASSIGNED",
        
"TERRORIST",
        
"CT",
        
"SPECTATOR" 
    
};
    
    
message_begin(MSG_ALLg_iMsgTeamInfo);
    
write_byte(id); 
    
write_string(TeamInfo[team]); 
    
message_end(); 
    
    if(
is_user_alive(id))
    {
        
user_kill(id)
    }
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang3081\\ f0\\ fs16 \n\\ par }
*/
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang3081\\ f0\\ fs16 \n\\ par }
*/ 
Rliable channel overflowed on 15th round when we all started to swap m1 m2

Atm it's set up to fmatch_ratio 20 after the 15th round is called. Changing ratio from 5 to 20 and I'm getting the overflowed.

I've also true to in include fmatch_enable 0 turning off the plugging but this only ables half the team to swap sides and theere are a few players who can't even bring up the teamchoose menu even after restart round.
That one causes a stack overflow 3.]

Whould these set_tasks() be a acceptable time? Would this stop it from overflowing.

Last edited by Hectik17; 05-17-2017 at 16:58. Reason: Updated might work?
Hectik17 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 17:47.


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