Raised This Month: $32 Target: $400
 8% 

Solved Crash problem and another small one.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 10-18-2017 , 09:52   Crash problem and another small one.
Reply With Quote #1

So the crash:

PHP Code:
case MenuAction_Cancel:
        {
            
ReturnPlayerInGame(client);
            
delete menu;
        } 
PHP Code:
public void ReturnPlayerInGame(int client)
{
    
int TeamCountT GetTeamClientCount(2);
    
int TeamCountCT GetTeamClientCount(3);
            
    if (
TeamCountT == TeamCountCT)
    {
        
int chooserandomteam GetRandomInt(12); 
        switch(
chooserandomteam
        {
            case 
1:
            {
                
CS_SwitchTeam(clientCS_TEAM_T);
            }
            case 
2:
            {
                
CS_SwitchTeam(clientCS_TEAM_CT);
            }
        }
    }
    else
    {
        if (
TeamCountCT TeamCountT)
        {
            
CS_SwitchTeam(clientCS_TEAM_T);
        }
        else if (
TeamCountT TeamCountCT)
        {
            
CS_SwitchTeam(clientCS_TEAM_CT);
        }
    }

And the server instantly crashesh.

The small problem:

PHP Code:
    if (Team == || Team == && PlayerIsSpec[client])
    {
        
PlayerIsSpec[client] = false;
        
        if (
KickTimer[client] != null)
        {
            
KillTimer(KickTimer[client]);
            
KickTimer[client] = null;
        }
        
        return 
Plugin_Continue;
    } 
And the player still can't join CT or T, when SPEC when changing team is blocked:

PHP Code:
    if (ClientInGame[client])
    {
        if (
IsChangeAllowed)
        {
            if (
Team == && !PlayerIsSpec[client])
            {
                
PlayerIsSpec[client] = true;
                
SpectatorMenu(clientargs);
            }
            else
            {
                return 
Plugin_Continue;
            }
        }
        else if (!
IsChangeAllowed)
        {
            if (
Team == 1)
            {
                
CPrintToChat(client"[{red}Teamlock: {green}Active{default}] You can {red}only{default} go to spectators when a round is {green}finished{default}!");
                return 
Plugin_Handled;
            }
            else if (
Team == || Team == 3)
            {
                
CPrintToChat(client"[{red}Teamlock: {green}Active{default}] You {red}cannot{default} change your team now. You can change it only when the round is {green}finished{default}!");
                return 
Plugin_Handled;  
            }
        }
    } 
Shouldn't that
PHP Code:
return Plugin_Continue
just pass the
PHP Code:
IsChangeAllowed / !IsChangeAllowed 
check?

Maybe if I do it that way:

PHP Code:
    if (ClientInGame[client])
    {
        if (
IsChangeAllowed)
        {
            if (
Team == && !PlayerIsSpec[client])
            {
                
PlayerIsSpec[client] = true;
                
SpectatorMenu(clientargs);
            }
            else
            {
                return 
Plugin_Continue;
            }
        }
        else if (!
IsChangeAllowed)
        {
            if (
Team == 1)
            {
                
CPrintToChat(client"[{red}Teamlock: {green}Active{default}] You can {red}only{default} go to spectators when a round is {green}finished{default}!");
                return 
Plugin_Handled;
            }
            else if (
Team == || Team == 3)
            {
                
CPrintToChat(client"[{red}Teamlock: {green}Active{default}] You {red}cannot{default} change your team now. You can change it only when the round is {green}finished{default}!");
                return 
Plugin_Handled;  
            }
        }
        else if (
Team && PlayerIsSpec[client])
        {
            
PlayerIsSpec[client] = false;
        
            if (
KickTimer[client] != null)
            {
                
KillTimer(KickTimer[client]);
                
KickTimer[client] = null;
            }
        
            return 
Plugin_Continue;
        }
    } 
You'll be able to return to CT or T while SPEC with block.
__________________

Last edited by PinHeaDi; 10-19-2017 at 17:30.
PinHeaDi is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 10-18-2017 , 11:19   Re: Crash problem and another small one.
Reply With Quote #2

So addressing the crash issue, what are you trying to achive with that code? Because to me it seems like an endless cycle of changing teams. No matter the team count.

If the count is even you're changed to a random team. If there are more terrorist then you're changed to CT, and if there are more CT's you're changed to T. Are you trying to keep balanced teams?

As for your second question, if you're asking how to return the bool.
Code:
return IsChangeAlloed;
Depending on what is returned "true" or "false" will determine if the player can change teams.

Edit and that first block kind of bothers me lol not that it matters but here is this

PHP Code:
public void ReturnPlayerInGame(int client

    
int TeamCountT GetTeamClientCount(2); 
    
int TeamCountCT GetTeamClientCount(3); 
             
    if (
TeamCountT == TeamCountCT
    { 
        
int chooserandomteam GetRandomInt(12);  //No need for this
        
switch(chooserandomteam)  //Change to this switch(GetRandomInt(1, 2))
        

            case 
1
            { 
                
CS_SwitchTeam(clientCS_TEAM_T); 
            } 
            case 
2
            { 
                
CS_SwitchTeam(clientCS_TEAM_CT); 
            } 
        } 
    } 
    else 
//Else statment
    

        if (
TeamCountCT TeamCountT
        { 
            
CS_SwitchTeam(clientCS_TEAM_T); 
        } 
        else if (
TeamCountT TeamCountCT//Else if? Not consistant
        

            
CS_SwitchTeam(clientCS_TEAM_CT); 
        } 
    } 


Last edited by Halt; 10-18-2017 at 11:31.
Halt is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 10-18-2017 , 11:58   Re: Crash problem and another small one.
Reply With Quote #3

I didn't get the:

return IsChangeAllowed;

What is I'm trying to achive is - when players go to spec a menu is shown to him:
PHP Code:
public int Spec_Menu(Menu menuMenuAction actionint clientint param2)
{
    switch(
action)
    {
        case 
MenuAction_Cancel:
        {
            
ReturnPlayerInGame(client);
            
delete menu;
        }

        case 
MenuAction_Select:
        {
            
char info[32];
            
menu.GetItem(param2infosizeof(info));
            
            
int timer g_MaxSpecTime.IntValue;
            
int afktimer g_MaxAfkTime.IntValue;
 
            if (
StrEqual(info"HACKER"))
            {
                
CPrintToChat(client"[{blue}Spectator MODE{default}] You've entered in {red}SPECTATOR{default} mode. You have {green}%i{default} minutes to watch your hacker and return or you'll be kicked!"timer);
                
KickTimer[client] = CreateTimer(g_MaxSpecTime.IntValue 60.0TimerToKickPlayerGetClientSerial(client));
            }
            else if (
StrEqual(info"AFK"))
            {
                
CPrintToChat(client"[{blue}Afk MODE{default}] You've entered in {red}AFK{default} mode. You have {green}%i{default} minutes to do whatever you're doing and return or you'll be kicked!"afktimer);
                
KickTimer[client] = CreateTimer(g_MaxAfkTime.IntValue 60.0TimerToKickPlayerGetClientSerial(client));
            }
        }
    }
        
    return 
0;

PHP Code:
public void SpectatorMenu(int clientint args)
{
    
Menu menu = new Menu(Spec_Menu);
    
menu.SetTitle("What do you wanna do as a spectator?");
    
menu.AddItem("HACKER""I want to watch a hacker.");
    
menu.AddItem("AFK""I want to go AFK for a while.");
    
menu.AddItem(""""ITEMDRAW_RAWLINE);
    
menu.AddItem("Info""This menu will be closed after 10 seconds."ITEMDRAW_DISABLED);
    
menu.AddItem("Info1""If you don't choose you'll be put back in-game.."ITEMDRAW_DISABLED);
    
menu.ExitButton false;
    
menu.Display(client10);

PHP Code:
// ================ RETURNPLAYERINGAME ===================== //
public void ReturnPlayerInGame(int client)
{
    
int TeamCountT GetTeamClientCount(CS_TEAM_T);
    
int TeamCountCT GetTeamClientCount(CS_TEAM_CT);
            
    if (
TeamCountT == TeamCountCT)
    {
        switch(
GetRandomInt(12))
        {
            case 
1:
            {
                
CS_SwitchTeam(clientCS_TEAM_T);
            }
            case 
2:
            {
                
CS_SwitchTeam(clientCS_TEAM_CT);
            }
        }
    }
    else
    {
        if (
TeamCountCT TeamCountT)
        {
            
CS_SwitchTeam(clientCS_TEAM_T);
        }
        else if (
TeamCountT TeamCountCT)
        {
            
CS_SwitchTeam(clientCS_TEAM_CT);
        }
    }
}
// =========================================================== // 
If he doesn't choose in 10 seconds the menu closes and the plugin will return him to the game. The swich is to keep the game balance so that he won't be put in team with more players.
__________________

Last edited by PinHeaDi; 10-18-2017 at 12:00.
PinHeaDi is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 10-18-2017 , 16:43   Re: Crash problem and another small one.
Reply With Quote #4

So, team changing from spec is fixed.. The crash still persists on MenuAction_Cancel:

PHP Code:
// ====================== MENU ========================== //
public int Spec_Menu(Menu menuMenuAction actionint clientint param2)
{
    switch(
action)
    {
        case 
MenuAction_Cancel:
        {
            if (
PlayerIsSpec[client])
            {
                
ReturnPlayerInGame(client);
            }

            
delete menu;
        }

        case 
MenuAction_Select:
        {
            
char info[32];
            
menu.GetItem(param2infosizeof(info));
            
            
int timer g_MaxSpecTime.IntValue;
            
int afktimer g_MaxAfkTime.IntValue;
 
            if (
StrEqual(info"HACKER"))
            {
                if (
PlayerIsSpec[client])
                {
                    
CPrintToChat(client"[{blue}Spectator MODE{default}] You've entered in {red}SPECTATOR{default} mode. You have {green}%i{default} minutes to watch your hacker and return or you'll be kicked!"timer);
                    
KickTimer[client] = CreateTimer(g_MaxSpecTime.IntValue 60.0TimerToKickPlayerGetClientSerial(client));
                }
            }
            else if (
StrEqual(info"AFK"))
            {
                if (
PlayerIsSpec[client])
                {
                    
CPrintToChat(client"[{blue}Afk MODE{default}] You've entered in {red}AFK{default} mode. You have {green}%i{default} minutes to do whatever you're doing and return or you'll be kicked!"afktimer);
                    
KickTimer[client] = CreateTimer(g_MaxAfkTime.IntValue 60.0TimerToKickPlayerGetClientSerial(client));
                }
            }
        }
    }
        
    return 
0;
}


public 
void SpectatorMenu(int clientint args)
{
    
Menu menu = new Menu(Spec_Menu);
    
menu.SetTitle("What do you wanna do as a spectator?");
    
menu.AddItem("HACKER""I want to watch a hacker.");
    
menu.AddItem("AFK""I want to go AFK for a while.");
    
menu.AddItem(""""ITEMDRAW_RAWLINE);
    
menu.AddItem("Info""This menu will be closed after 10 seconds."ITEMDRAW_DISABLED);
    
menu.AddItem("Info1""If you don't choose you'll be put back in-game.."ITEMDRAW_DISABLED);
    
menu.ExitButton false;
    
menu.Display(client10);
}
// =========================================================== // 
PHP Code:
// ================ RETURNPLAYERINGAME ===================== //
public void ReturnPlayerInGame(int client)
{
    
int TeamCountT GetTeamClientCount(CS_TEAM_T);
    
int TeamCountCT GetTeamClientCount(CS_TEAM_CT);
    
    if (
TeamCountT == TeamCountCT)
    {
        switch(
GetRandomInt(12))
        {
            case 
1:
            {
                
ChangeClientTeam(clientCS_TEAM_T);
            }
            case 
2:
            {
                
ChangeClientTeam(clientCS_TEAM_CT);
            }
        }
    }
    else
    {
        if (
TeamCountCT TeamCountT)
        {
            
ChangeClientTeam(clientCS_TEAM_T);
        }
        else
        {
            
ChangeClientTeam(clientCS_TEAM_CT);
        }
    }
}
// =========================================================== // 
ChangeClientTeam & CS_SwitchTeam - with both it crashesh.
__________________

Last edited by PinHeaDi; 10-18-2017 at 19:11.
PinHeaDi is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 10-19-2017 , 00:35   Re: Crash problem and another small one.
Reply With Quote #5

Don't delete/close the menu handle until MenuAction_End.
Fyren is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 10-19-2017 , 04:35   Re: Crash problem and another small one.
Reply With Quote #6

PHP Code:
        case MenuAction_Cancel:
        {
            if (
PlayerIsSpec[client])
            {
                
ReturnPlayerInGame(client);
            }
        } 
>>

PHP Code:
        case MenuAction_Cancel:
        {
            if (
PlayerIsSpec[client])
            {
                
ReturnPlayerInGame(client);
            }
        }
        case 
MenuAction_End:
        {
            
delete menu;
        } 
?
I don't get the whole menu thing with _End and _Cancel
__________________

Last edited by PinHeaDi; 10-19-2017 at 04:35.
PinHeaDi is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-19-2017 , 16:16   Re: Crash problem and another small one.
Reply With Quote #7

_Cancel is fired when a user closes a menu without selecting anything or the menu times out.

_End is called when users are done with a menu/vote and it's ready to be cleaned up.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 10-19-2017 , 17:23   Re: Crash problem and another small one.
Reply With Quote #8

Quote:
Originally Posted by Powerlord View Post
_Cancel is fired when a user closes a menu without selecting anything or the menu times out.

_End is called when users are done with a menu/vote and it's ready to be cleaned up.
So I don't need to use "delete menu;" in "MenuAction_Cancel:", since it's going to be closed after the defined time?

PHP Code:
        case MenuAction_Cancel:
        {
            if (
PlayerIsSpec[client])
            {
                
ReturnPlayerInGame(client);
            }
        } 
instead of:

PHP Code:
        case MenuAction_Cancel:
        {
            if (
PlayerIsSpec[client])
            {
                
ReturnPlayerInGame(client);
            }

            
delete menu;
        } 
P.S.: Yes, the plugin now runs flawlessly, thank you guys.
__________________

Last edited by PinHeaDi; 10-19-2017 at 17:29.
PinHeaDi is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-19-2017 , 17:35   Re: Crash problem and another small one.
Reply With Quote #9

Quote:
Originally Posted by PinHeaDi View Post
So I don't need to use "delete menu;" in "MenuAction_Cancel:", since it's going to be closed after the defined time?
Correct. _End is always called after either _Select or _Cancel for menus.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-19-2017 at 17:35. Reason: Shortening quoted section
Powerlord is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 10-19-2017 , 18:49   Re: Crash problem and another small one.
Reply With Quote #10

The handle isn't ever going to close itself, but you should not delete it before MenuAction_End because SM itself is going to still be using it.

Though, we could probably detect this and throw an error instead of just assuming users aren't doing the wrong thing.

Edit: PinHeaDi, can you provide the output of "sm version" from your server that was crashing?

Last edited by Fyren; 10-19-2017 at 18:59.
Fyren is offline
Reply


Thread Tools
Display Modes

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 01:30.


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