SA-MP Forums Archive
If Player Is In Vechile - 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: If Player Is In Vechile (/showthread.php?tid=445228)



If Player Is In Vechile - Donvalley - 20.06.2013

How To Set This To If Player Is In ComTruck it doesnt do the else return

pawn Code:
if(GetPlayerVehicleID(playerid) <= ComTruck[0] && GetPlayerVehicleID(playerid) >= ComTruck[12])
{
 else return SendClientMessage(playerid, GREY, "    You can only deliver in a truck.");
                    }



Re: If Player Is In Vechile - MP2 - 20.06.2013

That is not the correct way to do this at all. You need to loop through each truck ID and check if they are in it. You can't just assume the IDs are consecutive (i.e. 4, 5, 6, 7 and . Your if/else structure is also wrong.

pawn Code:
new vehicleid = GetPlayerVehicleID(playerid);

for(new i=0; i < sizeof(ComTruck); i++)
{
    if(vehicleid == ComTruck[i])
    {
        // They are in truck 'i', code here
        break;
    }
}
// Not in a truck