"else if" or "if"
#1

Hello,i have a proleb the the if functions are not working in the script below,i want help

PHP код:
public OnPlayerSpawn(playerid)
{
    
IsJumping[playerid] = 0;
    
PlayerPlaySound(playerid,1063,0.0,0.0,0.0);
    
TextDrawShowForPlayer(playeridInfoTextdraw);
    if(
PlayerInfo[playerid][pSkin] >= 1) return SetPlayerSkin(playeridPlayerInfo[playerid][pSkin]);
    
SetPlayerWeatherEx(playerid,PlayerInfo[playerid][pWeather]);
    if(
God[playerid] == 1) return SetPlayerHealth(playerid99999);
       else if(
PlayerInfo[playerid][Jail] == 1)
    {
        new 
rand random(sizeof(JailRandomSpawn));
        
SetPlayerPos(playeridJailRandomSpawn[rand][0], JailRandomSpawn[rand][1], JailRandomSpawn[rand][2]);
        
SetPlayerFacingAngle(playeridJailRandomSpawn[rand][3]);
        
ResetPlayerWeapons(playerid);
        
SetPlayerInterior(playerid3);
    }
    else if(
fr[playerid] == 1)
    {
        
SetPlayerVirtualWorld(playerid0);
        
SetPlayerInterior(playerid0);
        
SetPlayerPos(playerid, -1680.1483,706.0532,30.6016);
        
SetPlayerFacingAngle(playerid90.9011);
    }
    else if(
indm[playerid] == 1)
    {
        new 
rand random(sizeof(DDMRandomSpawn));
        
SetPlayerTeam(playerid, -1);
        
SetPlayerPos(playeridDDMRandomSpawn[rand][0], DDMRandomSpawn[rand][1],DDMRandomSpawn[rand][2]);
        
SetPlayerFacingAngle(playeridDDMRandomSpawn[rand][3]);
        
SetPlayerInterior(playerid18);
        
SetPlayerVirtualWorld(playerid2);
        
ResetPlayerWeapons(playerid);
        
GivePlayerWeapon(playerid24999999);
    }
    else if(
indm[playerid] == 2)
    {
        
SetPlayerTeam(playerid, -1);
        new 
rand random(sizeof(SDMRandomSpawn));
        
SetPlayerPos(playeridSDMRandomSpawn[rand][0], SDMRandomSpawn[rand][1],SDMRandomSpawn[rand][2]);
        
SetPlayerFacingAngle(playeridSDMRandomSpawn[rand][3]);
        
SetPlayerInterior(playerid15);
        
SetPlayerVirtualWorld(playerid1);
        
ResetPlayerWeapons(playerid);
        
GivePlayerWeapon(playerid34999999);
    }
    else if(
indm[playerid] == 3)
    {
        
DeathmatchObjects(playerid);
        
SetPlayerTeam(playerid, -1);
        new 
rand random(sizeof(MDRandomSpawn));
        
SetPlayerPos(playeridMDRandomSpawn[rand][0], MDRandomSpawn[rand][1],MDRandomSpawn[rand][2]);
        
SetPlayerFacingAngle(playeridMDRandomSpawn[rand][3]);
        
SetPlayerHealth(playerid100);
        
SetPlayerInterior(playerid0);
        
SetPlayerVirtualWorld(playerid3);
        
ResetPlayerWeapons(playerid);
        
GivePlayerWeapon(playerid38999999);
    }
    else if(
PlayerInfo[playerid][pMuted] == 1)
    {
        
MuteTimer[playerid] = SetTimerEx("OnPlayerUnmute"PlayerInfo[playerid][MuteTime], false"d"playerid);
    }
    else if(
PlayerInfo[playerid][pVip] == 1)
    {
        
SetPlayerArmour(playerid100);
    }
    return 
1;

Reply
#2

You have some returns above your else ifs, maybe that's what is stopping it.
Also, make a switch.
Reply
#3

Quote:
Originally Posted by Sime30
Посмотреть сообщение
You have some returns above your else ifs, maybe that's what is stopping it.
Also, make a switch.
I tested it by removing returns but...
Reply
#4

pawn Код:
if(PlayerInfo[playerid][pSkin] >= 1) return SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
Did you remove this one? As far as I know, once this is called and the condition is true, it ends the code right there, not accounting for anything below it.
Reply
#5

Get rid of "else if" wherever possible. You should never need to use that construct. If you keep the rule in mind that "else should alway be on its own" then you will have far less problems.
PHP код:
if
{
    
// 1
}
else if
{
    
// 2
}
else
{
    
// 3

Can and should be restructured like:
PHP код:
if
{
    
// 1
}
else
{
    if
    {
        
// 2
    
}
    else
    {
        
// 3
    
}

And then you'll notice what a horrible mess the code really is.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)