SA-MP Forums Archive
How to fix this warning ? - 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: How to fix this warning ? (/showthread.php?tid=505409)



How to fix this warning ? - AnonScripter - 08.04.2014

pawn Код:
stock IsPlayerInCopVehicle(playerid)
{
    if(IsPlayerInVehicle(playerid, 427) || IsPlayerInVehicle(playerid, 490) ||
    IsPlayerInVehicle(playerid, 497) || IsPlayerInVehicle(playerid, 523) ||
    IsPlayerInVehicle(playerid, 596) || IsPlayerInVehicle(playerid, 597) ||
    IsPlayerInVehicle(playerid, 598) || IsPlayerInVehicle(playerid, 599))
    return 1; //Line 1125
}

Код:
(1125) : warning 209: function "IsPlayerInCopVehicle" should return a value



Re: How to fix this warning ? - CutX - 08.04.2014

that function only returns a value (1) when that control structure equals true.
But what if that's not the case?
pawn doesen't know what to do.

do it like this:

pawn Код:
stock IsPlayerInCopVehicle(playerid)
{
    if(IsPlayerInVehicle(playerid, 427) || IsPlayerInVehicle(playerid, 490) ||
    IsPlayerInVehicle(playerid, 497) || IsPlayerInVehicle(playerid, 523) ||
    IsPlayerInVehicle(playerid, 596) || IsPlayerInVehicle(playerid, 597) ||
    IsPlayerInVehicle(playerid, 598) || IsPlayerInVehicle(playerid, 599))
        return 1;
    else return 0;
}
btw. relying on assumptions is the worst thing you could ever do.
it could easily mess up stuff. use an array to store the id's

like, when you create the vehicle:
pawn Код:
//globally
new copCar[8];//space for 8 id's (idx from 0 - 7)

//then when creating the cars:
    copCar[0] = CreateVeh....
    copCar[1] = CreateVeh....
    //and so on



Re: How to fix this warning ? - xVIP3Rx - 08.04.2014

I think that will be a bit faster and better..
pawn Код:
stock IsPlayerInCopVehicle(playerid)
{
    switch(GetPlayerVehicleID(playerid))
    {
        case 427, 490, 497, 523, 596, 597, 598, 599: return 1;
        default: return 0;
    }
}



Re: How to fix this warning ? - AnonScripter - 08.04.2014

fixed thank you all