This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

CS_TerminateRound and Round_end problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
XHeadHunterX
Member
Join Date: Aug 2013
Old 08-25-2013 , 19:33   CS_TerminateRound and Round_end problem
Reply With Quote #1

Hi, I'm trying to make the ct team win if there is at least one player alive in the ct team when the round ends. I tried the following but it crashes the server.

PHP Code:
public Action:OnRoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    for (new 
1<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && GetClientTeam(i) == && IsPlayerAlive(i))
            
CS_TerminateRound(GetConVarFloat(FindConVar("mp_round_restart_delay")), CSRoundEnd_CTWin);
    }

I also tried to put mp_ignore_round_win_conditions 1 but it still crashes. I also tried to use plugin_handled but it doesn't stop the round_end event. Help!

EDIT : Is there an event right before the round_end?

Last edited by XHeadHunterX; 08-25-2013 at 19:34.
XHeadHunterX is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 08-25-2013 , 22:34   Re: CS_TerminateRound and Round_end problem
Reply With Quote #2

The round_end event is firing after the round has already ended. You're trying to end it twice. That's a no-no.

What you want is CS_OnTerminateRound.
__________________
thetwistedpanda is offline
dilalmon
AlliedModders Donor
Join Date: Apr 2013
Old 08-26-2013 , 12:26   Re: CS_TerminateRound and Round_end problem
Reply With Quote #3

OnRoundEnd (round_end) is a broadcasting event which is fired after the round has ended.
So your custom round ending condition check gets fired when the round actually ends (OnRoundEnd), and it tries to end the round again inside the OnRoundEnd through CS_TerminateRound which most likely causes the crash.

So if you want to, you can put your conditions in the player_death event so when a player dies (when there are changes in the number of players in the game), you can let the game check for the custom conditions you specified and end the round because the round won't end due to the cvar, mp_ignore_round_win_conditions being set to 1.
Also note that player_death event is not triggered when the person is disconnected from the game while being alive. So make sure to fire the condition check on client disconnect forwards as well.

Other way is to use a repeated timer that checks the condition at a certain interval, but I personally do not like timers so I try to avoid them as much as possible.

Last edited by dilalmon; 08-26-2013 at 12:31.
dilalmon is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 08-26-2013 , 13:47   Re: CS_TerminateRound and Round_end problem
Reply With Quote #4

Quote:
Originally Posted by dilalmon View Post
OnRoundEnd (round_end) is a broadcasting event which is fired after the round has ended.
So your custom round ending condition check gets fired when the round actually ends (OnRoundEnd), and it tries to end the round again inside the OnRoundEnd through CS_TerminateRound which most likely causes the crash.

So if you want to, you can put your conditions in the player_death event so when a player dies (when there are changes in the number of players in the game), you can let the game check for the custom conditions you specified and end the round because the round won't end due to the cvar, mp_ignore_round_win_conditions being set to 1.
Also note that player_death event is not triggered when the person is disconnected from the game while being alive. So make sure to fire the condition check on client disconnect forwards as well.

Other way is to use a repeated timer that checks the condition at a certain interval, but I personally do not like timers so I try to avoid them as much as possible.
The player may still be counted as being in game when OnClientDisconnect fires, so use OnClientDisconnect_Post instead.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
XHeadHunterX
Member
Join Date: Aug 2013
Old 08-26-2013 , 20:15   Re: CS_TerminateRound and Round_end problem
Reply With Quote #5

Yes I tought about the player death event, but in my case it won't work because I want to modify it when there is still a player alive in the ct team at the round end.

How can I use the CS_OnTerminateRound? does it work as an event? Do I have to hook it?
XHeadHunterX is offline
XHeadHunterX
Member
Join Date: Aug 2013
Old 08-26-2013 , 20:33   Re: CS_TerminateRound and Round_end problem
Reply With Quote #6

I tried this
PHP Code:
public Action:CS_OnTerminateRound(&Float:delay, &CSRoundEndReason:reason)
{
    for (new 
1<= MaxClientsi++)
    {    
        if(
IsClientInGame(i) && GetClientTeam(i) == && IsPlayerAlive(i))
            
CS_TerminateRound(GetConVarFloat(FindConVar("mp_round_restart_delay")), CSRoundEnd_CTWin);
    }

It still crashes, I guess it's probably because I need to use plugin_stop or plugin_handled to block the event?

EDIT : Meh, this crashes too
PHP Code:
public Action:CS_OnTerminateRound(&Float:delay, &CSRoundEndReason:reason)
{
    for (new 
1<= MaxClientsi++)
    {    
        if(
IsClientInGame(i) && GetClientTeam(i) == && IsPlayerAlive(i))
        {    
            
CS_TerminateRound(GetConVarFloat(FindConVar("mp_round_restart_delay")), CSRoundEnd_CTWin);
            return 
Plugin_Handled;
        }
    }
    return 
Plugin_Continue;


Last edited by XHeadHunterX; 08-26-2013 at 20:39.
XHeadHunterX is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 08-26-2013 , 20:48   Re: CS_TerminateRound and Round_end problem
Reply With Quote #7

No. No no no. Stop that. Bad. *grabs a newspaper*

CS_OnTerminateRound fires... wait for it... when you call CS_TerminateRound. What happens when you call CS_TerminateRound inside of CS_OnTerminateRound! Infinite loopage! What happens when you repeat that infinite loop inside of another loop? Infinite loopage! What event fires after CS_TerminateRound is called? round_end. Infinite loopage! As you can see, this is all bad.

Since you're having difficulties:
PHP Code:
public Action:CS_OnTerminateRound(&Float:delay, &CSRoundEndReason:reason)
{
    
//This has priority, it won't fire unless the round is starting or something bad happened and it has to restart the round.
    
if(reason == CSRoundEnd_GameStart)
        return 
Plugin_Continue;
    
    
//Was a reason other than CT win passed? If so, we gotta fix that shit.
    
if(reason != CSRoundEnd_CTWin)
    {
        new 
iLivingBlues;
        for(new 
1<= MaxClientsi++)
        {
            
//Not ingame? Don't care. Not on CT? Don't care. Dead? Don't care.
            
if(!IsClientInGame(i) || GetClientTeam(i) != CS_TEAM_CT || !IsPlayerAlive(i))
                continue;
                
            
iLivingBlues++;
        }
        
        
//If there are any living CTs, make them the winner
        
if(iLivingBlues)
        {
            
reason CSRoundEnd_CTWin;
            return 
Plugin_Changed;
        }
    }

    return 
Plugin_Continue;

Of course this assumes the round ends naturally. If it doesn't, you'll have to handle that elsewhere. And on a re-read, this sounds very condescending, I apologize as that wasn't intentional. Need to work on my humor...
__________________

Last edited by thetwistedpanda; 08-26-2013 at 21:05.
thetwistedpanda is offline
XHeadHunterX
Member
Join Date: Aug 2013
Old 08-26-2013 , 21:12   Re: CS_TerminateRound and Round_end problem
Reply With Quote #8

Thanks for the reply. I tried the code and it has mixed results. On the first round, if there is a CT alive and the timer ends, it still says terrorists win, the next round if the same thing happen it will say round draw, and the next round the round timer changes (maybe because it reloads the round time from the cfg file? I change it when I load my plugin).

Last edited by XHeadHunterX; 08-26-2013 at 21:14.
XHeadHunterX is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 08-26-2013 , 21:19   Re: CS_TerminateRound and Round_end problem
Reply With Quote #9

It's likely erroring somewhere, check the logs?
__________________
thetwistedpanda is offline
XHeadHunterX
Member
Join Date: Aug 2013
Old 08-26-2013 , 21:47   Re: CS_TerminateRound and Round_end problem
Reply With Quote #10

No, no errors given, argh
XHeadHunterX 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 18:15.


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