Return + continue
#7

Return is final keyword in function, nothing can happen after it. But, you can make it conditional, so it only returns in certain situations. Also, simply moving chunks of code can make your code clearer:

pawn Код:
#define ActiveMemberOnDuty(%0,%1) (PlayerInfo[%0][pDuty] && (PlayerInfo[%0][pMember] == %1 || PlayerInfo[%0][pLeader] == %1))

public ReleaseFromHospital(playerid)
{
    KillTimer(stopactimer[playerid]);
    Dead[playerid] = 1;
    SCM(playerid, COLOR_LIGHT_BLUE, "You were released from hospital.");
    TogglePlayerControllable(playerid, 1);
    SetCameraBehindPlayer(playerid);
    SafeSetPlayerHealth(playerid, 50.0);
   
    if(PlayerInfo[playerid][pPocketbookexpire] < 1)
    {
        PlayerInfo[playerid][pPocketbook] = 0;
        PlayerInfo[playerid][pPocketbookexpire] = 0;
        SCM(playerid, COLOR_WHITE, "Your Pocketbook expire buy new!");
    }

    if(!PlayerInfo[playerid][pPocketbook]) {
        SCM(playerid, COLOR_WHITE, "You don't have pocketbook");
        SafeGivePlayerMoney(playerid, -500);
    }
    else {
        SCM(playerid, COLOR_WHITE, "You are insured.");
    }

    KillTimer(stopactimer[playerid]);
    stopactimer[playerid] = SetTimerEx("resumeanticheat", 4000, false, "i", playerid);

    if(ActiveMemberOnDuty(playerid, 1) || ActiveMemberOnDuty(playerid, 2) || ActiveMemberOnDuty(playerid, 3))
    {
        SCM(playerid, COLOR_WHITE, "Country pay insured for you.");
    }

    if(ActiveMemberOnDuty(playerid, 1))//L.S.P.D spawn
    {
        SetPlayerToTeamColor(playerid);
        SafeSetPlayerInterior(playerid,6);
        SafeSetPlayerPos(playerid, 216.9725,79.1339,1005.0391);
        SetPlayerFacingAngle(playerid, 270.0);
        SafeSetPlayerArmor(playerid, 50.0);
        return 1;
    }

    if(ActiveMemberOnDuty(playerid, 2)) //FBI spawn
    {
        SetPlayerToTeamColor(playerid);
        SafeSetPlayerInterior(playerid,3);
        SafeSetPlayerPos(playerid, 299.7097,183.1322,1007.1719);
        SetPlayerFacingAngle(playerid, 90);
        SafeSetPlayerHealth(playerid, 75.0);
        SafeSetPlayerArmor(playerid, 75.0);
        return 1;
    }
   
    if(ActiveMemberOnDuty(playerid, 3))
    {
        SetPlayerToTeamColor(playerid);
        SafeSetPlayerInterior(playerid, 0);
        SafeSetPlayerPos(playerid, 2731.5229,-2451.3643,17.5937);
        SafeSetPlayerHealth(playerid, 100.0);
        SafeSetPlayerArmor(playerid, 99.0);
        return 1;
    }
     
    new decidehosp = random(2);

    switch(decidehosp)
    {
        case 0: SafeSetPlayerPos(playerid, 1177.4866,-1323.9749,14.0731);
        case 1: SafeSetPlayerPos(playerid, 2025.1497,-1402.8643,17.2089);
    }

    SetPlayerFacingAngle(playerid, 270.0);
    SafeSetPlayerInterior(playerid, 0);
    SafeResetPlayerWeapons(playerid);
   
    return 1;
}
I added one macro, it's cleaner that way - it check if player is a member or leader of a fraction, and if he's on duty.
Reply


Messages In This Thread
Return + continue - by bigboy81 - 03.05.2015, 13:28
Re: Return + continue - by giorgosdim12 - 03.05.2015, 13:34
Re: Return + continue - by bigboy81 - 03.05.2015, 13:49
Re: Return + continue - by Misiur - 03.05.2015, 13:50
Re: Return + continue - by giorgosdim12 - 03.05.2015, 13:52
Re: Return + continue - by bigboy81 - 03.05.2015, 14:05
Re: Return + continue - by Misiur - 03.05.2015, 14:50
Re: Return + continue - by bigboy81 - 03.05.2015, 15:08
Re: Return + continue - by Threshold - 03.05.2015, 15:58
Re: Return + continue - by bigboy81 - 03.05.2015, 16:11

Forum Jump:


Users browsing this thread: 2 Guest(s)