SA-MP Forums Archive
Mechanic /applyjob problem. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Mechanic /applyjob problem. (/showthread.php?tid=387779)



Mechanic /applyjob problem. - printer - 26.10.2012

I've got this code:
pawn Код:
CMD:applymod(playerid, params[])
{
    if(PlayerInfo[playerid][pJob] !=7)
        return 1;
    new
        id,
        mod[128],
        modid,
        hascomp
    ;
    if(sscanf(params,"is[128]i",id,mod,modid))
        return SendClientMessage(playerid,C_NICE,"[Usage] {FFFFFF}/applymod [playerid/PON] [rims/hydraulics/radio/nos/addons] [modid]");
    if(equal(mod,"rims",true))
    {
        ForLoop(i,12)
        {
            if(PlayerInfo[playerid][pRSet][i] !=modid || PlayerInfo[playerid][pRSetA][i] < 1)
            {
                hascomp = 0;
                break;
            }
            else
            {
                PlayerInfo[playerid][pRSetA][i]--;
                AddVehicleComponent(GetPlayerVehicleID(id),modid);
                SendClientMessage(id,C_NICE,"[Mechanic] {FFFFFF}New wheels were installed for your vehicle.");
                break;
            }
        }
    }
    if(!hascomp)
        return SendClientMessage(playerid,C_RED,"You do not have these components.");
    return 1;
}
You get 3 sets of virtual wheels once you take the job, but the thing is, it works, but it executed "New will has been installed" and then "You do not have these components".

How can I fix that?


Re: Mechanic /applyjob problem. - Finn - 26.10.2012

Return the function instead of just breaking the loop: return will break the loop automatically.


Re: Mechanic /applyjob problem. - printer - 26.10.2012

Like this
pawn Код:
CMD:applymod(playerid, params[])
{
    if(PlayerInfo[playerid][pJob] !=7)
        return 1;
    new
        id,
        mod[128],
        modid,
        hascomp
    ;
    if(sscanf(params,"is[128]i",id,mod,modid))
        return SendClientMessage(playerid,C_NICE,"[Usage] {FFFFFF}/applymod [playerid/PON] [rims/hydraulics/radio/nos/addons] [modid]");
    if(equal(mod,"rims",true))
    {
        ForLoop(i,12)
        {
            if(PlayerInfo[playerid][pRSet][i] !=modid || PlayerInfo[playerid][pRSetA][i] < 1)
            {
                hascomp = 0;
                break;
            }
            else
            {
                PlayerInfo[playerid][pRSetA][i]--;
                AddVehicleComponent(GetPlayerVehicleID(id),modid);
                SendClientMessage(id,C_NICE,"[Mechanic] {FFFFFF}New wheels were installed for your vehicle.");
                return 1;
            }
        }
    }
    if(!hascomp)
        return SendClientMessage(playerid,C_RED,"You do not have these components.");
    return 1;
}