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

Solved Small problem in this plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AuricYoutube
Senior Member
Join Date: Aug 2016
Location: Here
Old 03-31-2019 , 03:32   Small problem in this plugin
Reply With Quote #1

I have a really small tiny problem with this plugin, whenever the last player alive joins spectator and comes back to ct/t, it causes the plugin not to recognize that all players are dead and not end the round.

Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <cstrike>

public OnPluginStart()
{
    HookEvent("player_death", Event_PlayerDeath);
}

public Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    
    if (!IsFakeClient(client) && AllHumansDead())
    {
        EndRound();
    }
}

bool:AllHumansDead()
{
    new bool:result = true;
    
    for (new i = 1; i <= MaxClients; i++)
    {
        if (IsClientInGame(i) && !IsFakeClient(i) && IsPlayerAlive(i)) // Thanks Black-Rabbit
        {
            result = false;
        }
    }
    
    return result;
}

EndRound()
{
	CS_TerminateRound(GetConVarFloat(FindConVar("mp_round_restart_delay")), CSRoundEnd_CTWin);
}
If you know how to add such a function please help me.

Last edited by AuricYoutube; 04-12-2019 at 10:36.
AuricYoutube is offline
adma
Senior Member
Join Date: Oct 2015
Old 03-31-2019 , 04:51   Re: Small problem in this plugin
Reply With Quote #2

I've had issues with counting dead players when someones dies. The way I got it to work was using RequestFrame to delay the check by a frame.
adma is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 03-31-2019 , 08:08   Re: Small problem in this plugin
Reply With Quote #3

Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <cstrike>

public void OnPluginStart()
{
    HookEvent("player_death", Event_PlayerDeath);
}

public void Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
    int client = GetClientOfUserId(GetEventInt(event, "userid"));
    
    if (IsFakeClient(client)) return;

    if (AllHumansDead(client))
    {
        EndRound();
    }
}

bool AllHumansDead(int client)
{
    for (int i = 1; i <= MaxClients; i++)
    {
        if (i == client) continue;

        if (IsClientInGame(i))
        {
                if (IsFakeClient(i)) continue;

                if (IsPlayerAlive(i))
                {
                        return false;
                }
        }
    }
    
    return true;
}

void EndRound()
{
	CS_TerminateRound(GetConVarFloat(FindConVar("mp_round_restart_delay")), CSRoundEnd_CTWin);
}
__________________
Ilusion9 is offline
AuricYoutube
Senior Member
Join Date: Aug 2016
Location: Here
Old 04-11-2019 , 08:00   Re: Small problem in this plugin
Reply With Quote #4

Quote:
Originally Posted by Ilusion9 View Post
Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <cstrike>

public void OnPluginStart()
{
    HookEvent("player_death", Event_PlayerDeath);
}

public void Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
    int client = GetClientOfUserId(GetEventInt(event, "userid"));
    
    if (IsFakeClient(client)) return;

    if (AllHumansDead(client))
    {
        EndRound();
    }
}

bool AllHumansDead(int client)
{
    for (int i = 1; i <= MaxClients; i++)
    {
        if (i == client) continue;

        if (IsClientInGame(i))
        {
                if (IsFakeClient(i)) continue;

                if (IsPlayerAlive(i))
                {
                        return false;
                }
        }
    }
    
    return true;
}

void EndRound()
{
	CS_TerminateRound(GetConVarFloat(FindConVar("mp_round_restart_delay")), CSRoundEnd_CTWin);
}
problem still occuring
AuricYoutube is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 04-11-2019 , 08:11   Re: Small problem in this plugin
Reply With Quote #5

If you have a custom command to join spec, you should check that.
__________________
Ilusion9 is offline
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 04-11-2019 , 15:56   Re: Small problem in this plugin
Reply With Quote #6

Try this


PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <cstrike>

public void OnPluginStart()
{
    
HookEvent("player_death"Event_CheckCondEventHookMode_PostNoCopy);
    
HookEvent("player_team"Event_CheckCondEventHookMode_PostNoCopy);
}

public 
void Event_CheckCond(Event event, const char[] namebool dontBroadcast)
{
    
RequestFrame(view_as<RequestFrameCallback>(DoRoundcheck));
}

public 
void DoRoundcheck()
{
    if (
AllHumansDead())
    {
        
EndRound();
    }
}

bool AllHumansDead()
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i) && IsPlayerAlive(i))
        {
            return 
false;
        }
    }
    return 
true;
}

void EndRound()
{
    
CS_TerminateRound(GetConVarFloat(FindConVar("mp_round_restart_delay")), CSRoundEnd_CTWin);

__________________

Last edited by impossible_cc; 04-11-2019 at 15:57.
impossible_cc 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 07:10.


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