AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   else if problem (https://forums.alliedmods.net/showthread.php?t=240635)

proffs 05-19-2014 06:50

else if problem
 
PHP Code:

public Fwd_PlayerKilled()
{
    if(
getPlayers(CS_TEAM_T) == 1// we have a winner
    
{
        
StopGame()
        
ColorChat(0GREY"Death Match")
    }
    
//but you have the game to NOT stop in the following cases. But instead of elses, we use switch between games
    
else
    {
        switch(
g_iCurrentGame)
        {
            case 
GAME_NO: return
            case 
GAME_SPARTA: return
            case 
GAME_SHARK: return
        }
        
    }



This doesn't work .

As you see when there is 1 T left Stopgame should run.
But if it's GAME_... those you can see, it shouldn't run Stopgame..
It doesn't work for me

ironskillz1 05-19-2014 07:31

Re: else if problem
 
Quote:

Originally Posted by proffs (Post 2139834)
PHP Code:

public Fwd_PlayerKilled()
{
    if(
getPlayers(CS_TEAM_T) == 1// we have a winner
    
{
        
StopGame()
        
ColorChat(0GREY"Death Match")
    }
    
//but you have the game to NOT stop in the following cases. But instead of elses, we use switch between games
    
else
    {
        switch(
g_iCurrentGame)
        {
            case 
GAME_NO: return
            case 
GAME_SPARTA: return
            case 
GAME_SHARK: return
        }
        
    }



This doesn't work .

As you see when there is 1 T left Stopgame should run.
But if it's GAME_... those you can see, it shouldn't run Stopgame..
It doesn't work for me

You are right now checking if its 1 player left. If its 0 players or more than 1 player left it will return and not stop the game.
You need to first check this
Code:

                switch(g_iCurrentGame)
                {
                        case GAME_NO: return
                        case GAME_SPARTA: return
                        case GAME_SHARK: return
                }

Then else if its 1 player left

proffs 05-19-2014 07:43

Re: else if problem
 
Quote:

Originally Posted by ironskillz1 (Post 2139849)
You are right now checking if its 1 player left. If its 0 players or more than 1 player left it will return and not stop the game.
You need to first check this
Code:

                switch(g_iCurrentGame)
                {
                        case GAME_NO: return
                        case GAME_SPARTA: return
                        case GAME_SHARK: return
                }

Then else if its 1 player left

PHP Code:

if
    {
        switch(
g_iCurrentGame)
        {
            case 
GAME_NO: return
            case 
GAME_SPARTA: return
            case 
GAME_SHARK: return
        }
        
    }
    else if(
getPlayers(CS_TEAM_T) == 1// we have a winner
    
{
        
StopGame()
        
ColorChat(0GREY"^."prefix)
    } 

Like this?
I get error on this line:

PHP Code:

if
    { 


ironskillz1 05-19-2014 07:49

Re: else if problem
 
Im in school right now. Can show later when i come home

Kia 05-19-2014 07:49

Re: else if problem
 
You have no condition for your if-statement, you are missing something.
The compiler is like : If what?

ironskillz1 05-19-2014 10:07

Re: else if problem
 
Code:

public Fwd_PlayerKilled()
{
        if( g_iCurrentGame == GAME_NO || g_iCurrentGame == GAME_SPARTA || g_iCurrentGame == GAME_SHARK) //Check if a game is on
                return PLUGIN_HANLED; //Stop the function if a game is on
       
        else(getPlayers(CS_TEAM_T) == 1) //Else check if 1 player is alive? i guess
        {
                StopGame() //Stop game
                ColorChat(0, GREY, "Death Match") //Print message
        }
}


GinNNy 05-19-2014 10:44

Re: else if problem
 
Quote:

Originally Posted by ironskillz1 (Post 2139913)
Code:

public fwd_playerkilled()
{
        if( g_icurrentgame == game_no || g_icurrentgame == game_sparta || g_icurrentgame == game_shark) //check if a game is on
                return plugin_hanled; //stop the function if a game is on
       
        else(getplayers(cs_team_t) == 1) //else check if 1 player is alive? I guess
        {
                stopgame() //stop game
                colorchat(0, grey, "death match") //print message
        }
}


plugin_hanled
=>
plugin_handled
^.^

ironskillz1 05-19-2014 13:35

Re: else if problem
 
Quote:

Originally Posted by GinNNy (Post 2139919)
plugin_hanled
=>
plugin_handled
^.^

Yeah my mistake :)

^SmileY 05-19-2014 17:24

Re: else if problem
 
Show to us the
PHP Code:

GAME_NO
GAME_SPARTA
GAME_SHARK 

enum, #define etc, I'm sure there is a better solution for this


All times are GMT -4. The time now is 09:41.

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