Mechanic /applyjob problem.
#1

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?
Reply
#2

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

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)