Raised This Month: $51 Target: $400
 12% 

Win Conditions Issue.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 09-07-2013 , 08:28   Win Conditions Issue.
Reply With Quote #1

Summary:
Hello, I am currently trying to make a custom plugin that gives each player more than 1 life each round, I have been pulling my hair out trying to get the win conditions to work, So I can't move any further into the plugin code until this is fixed.

Right now I am attempting to recode the default win conditions with cvar mp_ignore_round_win_conditions 1

You may ask why I'm doing this, but lets say only 1 player on a certain team is alive but has more than 1 life remaining and dies it will automatically end the round which is not what I want, he should get 1 more respawn (once plugin is complete).

Issue:
So the issue is with this code, is that the round is not ending at all regardless of which team dies first.

Code:

PHP Code:
#define cDefault 0x01
#define cLightGreen 0x03
#define cGreen 0x04
#define cDarkGreen 0x05

#include <sourcemod>
#include <cstrike>
#include <smlib>

new countAliveTerrorists;
new 
countAliveCounterTerrorists;

public 
Plugin:myinfo = {
    
    
name "Win Conditions Test",
    
author "xCoderx",
    
description "",
    
version "1.0",
    
url ""
}

public 
OnPluginStart(){
    
    
HookEvent("player_death"playerDeath);
}

public 
playerDeathHandle:event, const String:name[], bool:Death_Broadcast){
    
    
roundWinConditions();
}

roundWinConditions(){
    
Team_GetClientCounts(countAliveTerroristscountAliveCounterTerroristsCLIENTFILTER_ALIVE);
    
    for (new 
client=1client <= MaxClientsclient++) {
        
        if (
countAliveCounterTerrorists 1){ // Less than one alive CT
            
if(countAliveTerrorists 0// More than 0 Terrorists alive.
            
{
                
CS_TerminateRound(5.0CSRoundEnd_TerroristWintrue); // Then Terrorists win.
                
PrintToChat(client"%cTerrorists Win!"cLightGreen);
            }
        }
        
        else if((
countAliveCounterTerrorists 0)){ // Or More than 1 CT Alive
            
if((countAliveTerrorists 1)){ // And Less than 1 Terrorist Alive
                
                
CS_TerminateRound(5.0CSRoundEnd_CTWintrue); // CT Win
                
PrintToChat(client"%cCounter-Terrorists Win!"cLightGreen);
            }
        }
    }

I am using smlib to make life easier btw.

Any assistance with this code is extremely appreciated,
thanks a lot, I'm pretty new to this, so expect my code to have simple mistakes.

Last edited by SM9; 09-07-2013 at 08:30.
SM9 is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 09-07-2013 , 09:09   Re: Win Conditions Issue.
Reply With Quote #2

Your code is throwing errors, so that's why nothing is actually occurring.

PHP Code:
roundWinConditions()
{
    
//SMLIB isn't necessary
    
new iTotalRed;
    new 
iTotalBlue;
    
    for(new 
client 1client <= MaxClientsclient++)
    {
        
//Ensure the client is in-game and living
        
if(!IsClientInGame(client) || !IsPlayerAlive(client))
            continue;

        switch(
GetClientTeam(client))
        {
            case 
CS_TEAM_T:
                
iTotalRed++;
            case 
CS_TEAM_CT:
                
iTotalBlue++;
        }
    }
    
    if(
iTotalRed iTotalBlue)
    {
        
CS_TerminateRound(5.0CSRoundEnd_TerroristWintrue);
        
PrintToChat(client"%cTerrorists Win!"cLightGreen);
    }
    else if(
iTotalBlue iTotalRed)
    {                
        
CS_TerminateRound(5.0CSRoundEnd_CTWintrue);
        
PrintToChat(client"%cCounter-Terrorists Win!"cLightGreen);
    }
    else
    {
        
CS_TerminateRound(5.0CSRoundEnd_Drawtrue);
        
PrintToChat(client"%cDraw!"cLightGreen);
    }

__________________
thetwistedpanda is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 09-07-2013 , 09:33   Re: Win Conditions Issue.
Reply With Quote #3

With some modifications to your code it worked perfectly. BIG THANKS!

PHP Code:
roundWinConditions()
{
    
//SMLIB isn't necessary
    
new iTotalRed;
    new 
iTotalBlue;
    
    for(new 
client 1client <= MaxClientsclient++)
    {
        
//Ensure the client is in-game and living
        
if(!IsClientInGame(client) || !IsPlayerAlive(client))
            continue;
        
        switch(
GetClientTeam(client))
        {
            case 
CS_TEAM_T:
            
iTotalRed++;
            case 
CS_TEAM_CT:
            
iTotalBlue++;
        }
    }
    
    if(
iTotalRed == 0)
    {
        if(
iTotalBlue 0)
        {
            
CS_TerminateRound(5.0CSRoundEnd_CTWintrue);
        }
    }
    if(
iTotalBlue == 0)
    {          
        if(
iTotalRed 0)
        {
            
CS_TerminateRound(5.0CSRoundEnd_TerroristWintrue);
        }
    }

SM9 is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 09-07-2013 , 11:22   Re: Win Conditions Issue.
Reply With Quote #4

Sorry to be a nuisance but I realised I need to get the player count in other functions also, but I don't wanna copy all the code to each function. Could somebody make it into a stock so I can easily check alive counts.

Example: if(AliveCount[Terrorist] == 1){} and if(AliveCount[CT] == 1){}

many thanks
SM9 is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 09-07-2013 , 11:31   Re: Win Conditions Issue.
Reply With Quote #5

Should give you a better idea. Stocks are no mystery in SP xD. If you're going to be using both teams, may as well get them at the same time; saves a second iteration.
PHP Code:
stock GetLivingTeamCount(&iRed, &iBlue)
{
    new 
iTotalRed;
    new 
iTotalBlue;
    for(new 
client 1client <= MaxClientsclient++)
    {
        if(!
IsClientInGame(client) || !IsPlayerAlive(client))
            continue;
        
        switch(
GetClientTeam(client))
        {
            case 
CS_TEAM_T:
                
iTotalRed++;
            case 
CS_TEAM_CT:
                
iTotalBlue++;
        }
    }
    
    
iRed iTotalRed;
    
iBlue iTotalBlue;
}

new 
HOWMANYREDSNOTINABOXHOWMANYBLUESNOTINABOX;
GetLivingTeamCount(HOWMANYREDSNOTINABOXHOWMANYBLUESNOTINABOX);
PrintToChatAll("THERES %d MANY REDS LIVING AND %d MANY BLUES LIVING"HOWMANYREDSNOTINABOXHOWMANYBLUESNOTINABOX);

stock GetLivingTeamCount2()
{
    new 
iArray[2];
    for(new 
client 1client <= MaxClientsclient++)
    {
        if(!
IsClientInGame(client) || !IsPlayerAlive(client))
            continue;
        
        switch(
GetClientTeam(client))
        {
            case 
CS_TEAM_T:
                
iArray[0]++;
            case 
CS_TEAM_CT:
                
iArray[1]++;
        }
    }
    
    return 
iArray;
}

new 
HOWMANYNOTINABOX[2];
HOWMANYNOTINABOX GetLivingTeamCount2();
PrintToChatAll("THERES %d MANY REDS LIVING AND %d MANY BLUES LIVING"HOWMANYNOTINABOX[0], HOWMANYNOTINABOX[1]); 
__________________

Last edited by thetwistedpanda; 09-07-2013 at 11:37.
thetwistedpanda is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 09-08-2013 , 10:30   Re: Win Conditions Issue.
Reply With Quote #6

Thats great, Thanks again!
SM9 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 05:24.


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