SA-MP Forums Archive
I'm a noob with Arrays, help? :D - 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: I'm a noob with Arrays, help? :D (/showthread.php?tid=474586)



I'm a noob with Arrays, help? :D - Chrillzen - 08.11.2013

Alright, I want to check if he's one of these 5 cars. If he is then it sets the checkpoint. DMVCar 0 to 5.

pawn Код:
DMVcar[0] = AddStaticVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1);
    DMVcar[1] = AddStaticVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1);
    DMVcar[2] = AddStaticVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1);
    DMVcar[3] = AddStaticVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1);
    DMVcar[4] = AddStaticVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1);
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        if(IsPlayerInVehicle(playerid, DMVCar[0] ??))
        {
            if(TakingDriverLicense[playerid] == true)
            {
                SetPlayerCheckpoint(playerid, 1982.6150, -220.6680, -0.2432, 3.0);
            }
        }
    }



Re: I'm a noob with Arrays, help? :D - bensmart469 - 08.11.2013

Why not just do a loop, e.g.
for(new i=0; i<5; i++)
{
if(GetPlayerVehicleID(playerid) == DMVCar[i])
{
//Your code
}
}


Re: I'm a noob with Arrays, help? :D - Chrillzen - 08.11.2013

Thanks, seems logical.


Re: I'm a noob with Arrays, help? :D - AnonScripter - 08.11.2013

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
    {
        if(IsPlayerInVehicle(playerid, DMVCar[0] || IsPlayerInVehicle(playerid, DMVCar[1] || IsPlayerInVehicle(playerid, DMVCar[2] || IsPlayerInVehicle(playerid, DMVCar[3] || IsPlayerInVehicle(playerid, DMVCar[4]))
        {
            if(TakingDriverLicense[playerid] == true)
            {
                SetPlayerCheckpoint(playerid, 1982.6150, -220.6680, -0.2432, 3.0);
            }
        }
    }