SA-MP Forums Archive
Fast array question - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Fast array question (/showthread.php?tid=255844)



Fast array question - sim_sima - 17.05.2011

Hey guys.
Just a fast question on arrays.
I added 4 vehicles, that only some people can use (People who has mechanic job).
I added the vehicles like this:
pawn Код:
new mechanicvehicles[4]; // Because there are 4 vehicles
and in OnPlayerEnterVehicle:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    if(PlayerInfo[playerid][pJob] != 1)
    {
        if(vehicleid == mechanicvehicles[playerid])
        {
            SetPlayerPos(playerid, x, y, z);
            SendClientMessage(playerid, COLOR_NORMALRED, "( ! ) Only Mechanics can use This Vehicle");
        }
    }
    return 1;
}
But this only ejects the player from one of the vehicles. I want it to happend on all 4 vehicles.
The problem is in this line:
pawn Код:
if(vehicleid == mechanicvehicles[playerid])
But i dont know what else to write.

Thank you.


Re: Fast array question - sim_sima - 17.05.2011

And by the way i also did this in OnGameModeInit:
pawn Код:
mechanicvehicles[0] = AddStaticVehicle(525,2080.1189,-2006.5361,13.4202,270.0635,22,30); // mechaniccar1
mechanicvehicles[1] = AddStaticVehicle(552,2080.4067,-2019.9713,13.2515,268.8202,56,56); // mechaniccar2
mechanicvehicles[2] = AddStaticVehicle(525,2080.2844,-2033.1355,13.4281,271.6693,44,51); // mechaniccar3
mechanicvehicles[3] = AddStaticVehicle(552,2080.0762,-2046.6104,13.2434,269.6772,26,124); // mechaniccar4



Re: Fast array question - Wesley221 - 17.05.2011

pawn Код:
if(vehicleid == mechanicvehicles[MAX_PLAYERS])
I guess this will do it


Re: Fast array question - sim_sima - 17.05.2011

Quote:
Originally Posted by Wesley221
Посмотреть сообщение
pawn Код:
if(vehicleid == mechanicvehicles[MAX_PLAYERS])
I guess this will do it
Thank you. Ill try.


Re: Fast array question - Dreftas - 17.05.2011

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    if(PlayerInfo[playerid][pJob] != 1)
    {
        for(new i=0; i<sizeof(mechanicvehicles); i++)
        {
            if(vehicleid == mechanicvehicles[i])
            {
                SetPlayerPos(playerid, x, y, z);
                SendClientMessage(playerid, COLOR_NORMALRED, "( ! ) Only Mechanics can use This Vehicle");
                break;
            }
        }  
    }
    return 1;
}



Re: Fast array question - Vince - 17.05.2011

*sigh* Dumb_answers_of_the_day++;
Edit: I'm slow again. That was directed at Wesley221

pawn Код:
if(PlayerInfo[playerid][pJob] != 1)
    {
        for(new i; i < sizeof(mechanicvehicles); i++)
        {
            if(mechanicvehicles[i] == vehicleid)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_NORMALRED, "( ! ) Only Mechanics can use This Vehicle");
                break;
            }
        }
    }



Re: Fast array question - sim_sima - 17.05.2011

Quote:
Originally Posted by Dreftas
Посмотреть сообщение
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    if(PlayerInfo[playerid][pJob] != 1)
    {
        for(new i=0; i<sizeof(mechanicvehicles); i++)
        {
            if(vehicleid == mechanicvehicles[i])
            {
                SetPlayerPos(playerid, x, y, z);
                SendClientMessage(playerid, COLOR_NORMALRED, "( ! ) Only Mechanics can use This Vehicle");
                break;
            }
        }  
    }
    return 1;
}
Thank you. Ill try