SetPlayerTeamFromClass & SetPlayerToTeamColor - What Have I Done Wrong ?
#1

Hey guys i will just give you the code and you check if it has any errors or no
First The SetPlayerTeamFromClass function if it is not correct please tell me how to fix it
pawn Код:
SetPlayerTeamFromClass(playerid, classid)
{
    if(classid == 0)
    {
        gTeam[playerid] = TEAM_VAGOS;
    }
    else
    {
        gTeam[playerid] = TEAM_GROVE;
    }
    else
    {
        gTeam[playerid] = TEAM_BALLAS;
    }
    else
    {
        gTeam[playerid] = TEAM_ARMY;
    }
    else
    {
        gTeam[playerid] = TEAM_POLICE;
    }
    else
    {
        gTeam[playerid] = TEAM_MAFIA;
    }
    else
    {
        gTeam[playerid] = TEAM_ADMINS;
    }
}
And Now The SetPlayerToTeamColor
pawn Код:
SetPlayerToTeamColor(playerid)
{
    if (gTeam[playerid] == TEAM_VAGOS)
    {
        SetPlayerColor(playerid, TEAM_VAGOS_COLOR);
    }
    else if (gTeam[playerid] == TEAM_GROVE)
    {
        SetPlayerColor(playerid, TEAM_GROVE_COLOR);
    }
    else if (gTeam[playerid] == TEAM_BALLAS)
    {
        SetPlayerColor(playerid, TEAM_BALLAS_COLOR);
    }
    else if (gTeam[playerid] == TEAM_ARMY)
    {
        SetPlayerColor(playerid, TEAM_ARMY_COLOR);
    }
    else if (gTeam[playerid] == TEAM_POLICE)
    {
        SetPlayerColor(playerid, TEAM_POLICE_COLOR)
    }
    else if (gTeam[playerid] == TEAM_MAFIA)
    {
        SetPlayerColor(playerid, TEAM_MAFIA_COLOR);
    }
    else if(gTeam[playerid] == TEAM_ADMINS)
    {
        SetPlayerColor(playerid, TEAM_ADMINS_COLOR);
    }
}
Thanks in advance
Reply
#2

In First Script , you cant use else for each cases, this condition is used for only 1 or 2 . For multiple you should use
pawn Код:
if

else if

else
Format

pawn Код:
SetPlayerTeamFromClass(playerid, classid)
{
    if(classid == 0)
    {
        gTeam[playerid] = TEAM_VAGOS;
    }
    else if
    {
        gTeam[playerid] = TEAM_GROVE;
    }
    else if
    {
        gTeam[playerid] = TEAM_BALLAS;
    }
    else if
    {
        gTeam[playerid] = TEAM_ARMY;
    }
    else if
    {
        gTeam[playerid] = TEAM_POLICE;
    }
    else if
    {
        gTeam[playerid] = TEAM_MAFIA;
    }
    else
    {
        gTeam[playerid] = TEAM_ADMINS;
    }
}
Reply
#3

@Neo

Lol, you forgot again an "else if" statement, at "Mafia"!

@MrFames

I recommend you to use cases, which are better instead of the "else if" statement! The "cases" are here the skin-numbers, starting from 0! This, for example, is mine:

PHP код:
SetPlayerTeamFromClass(playeridclassid)
{
    switch(
classid)
    {
        case 
.. 2:
        {
            
gTeam[playerid] = BALLA;
        }
        case 
.. 7:
        {
            
gTeam[playerid] = GROVE;
        }
        case 
.. 10:
        {
            
gTeam[playerid] = VAGOS;
        }
        case 
11 .. 14:
        {
            
gTeam[playerid] = AZTECAS;
        }
        case 
15 .. 23:
        {
            
gTeam[playerid] = POLICE;
        }
        case 
24 .. 26:
        {
            
gTeam[playerid] = RIFAS;
        }
        case 
27 .. 31:
        {
            
gTeam[playerid] = LOCO;
        }
    }

Also, at the color-callback:

PHP код:
SetPlayerToTeamColor(playerid)
{
    switch(
gTeam[playerid])
    {
        case 
GROVE:
        {
            
SetPlayerColor(playeridTEAM_GROVE_COLOR);
        }
        case 
BALLA:
        {
            
SetPlayerColor(playeridTEAM_BALLA_COLOR);
        }
        case 
VAGOS:
        {
            
SetPlayerColor(playeridTEAM_VAGOS_COLOR);
        }
        case 
AZTECAS:
        {
            
SetPlayerColor(playeridTEAM_AZTECAS_COLOR);
        }
        case 
POLICE:
        {
            
SetPlayerColor(playeridTEAM_POLICE_COLOR);
        }
        case 
RIFAS:
        {
            
SetPlayerColor(playeridTEAM_RIFAS_COLOR);
        }
        case 
LOCO:
        {
            
SetPlayerColor(playeridTEAM_LOCO_COLOR);
        }
    }

Reply
#4

hmmm @Tisted_Insane
I didn't get u, what did u mean by skin numbers can u explain more please
Reply
#5

Yeah bro , I was editing throughout there and missed one,but i corrected it before your last reply , anyway thanks btw...

You re right Case Statement is the best conditional statement because , the script is more clear and easy to know.

For Each Case, for example input value is BALLA

then the script will proceed only

case BALLA:
{
SetPlayerColor(playerid, TEAM_BALLA_COLOR);
}

and break to outside the loop ({ })..
Reply
#6

Quote:
Originally Posted by Mr.Fames
Посмотреть сообщение
hmmm @Tisted_Insane
I didn't get u, what did u mean by skin numbers can u explain more please
I mean the skins at "OnPlayerRequestClass" and "OnGameModeInit", the skins, which you add there!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)