#1

Alright, I have my vehicle check script to check if a players allowed in that vehicle ( faction vehicle )

but I have to create a SWAT base which as 30 vehicles and I don't want to create a massive if() line which checks the vehicles ids

I'm wondering if I can stock() the GetPlayerVehicleID ?

pawn Код:
public OnPlayerUpdate(playerid)
{
    if(GetPlayerVehicleID(playerid) == 45 || GetPlayerVehicleID(playerid) == 46 || GetPlayerVehicleID(playerid) == 47 || GetPlayerVehicleID(playerid) == 48 && Taxijob[playerid] == 0)
    {
        RemovePlayerFromVehicle(playerid);
        ShowPlayerDialog(playerid, 3702, DIALOG_STYLE_MSGBOX, "No Keys", "You do not have the keys to this vehicle\nThis means you either don't have the Job/Faction .", "Ok", "");
        return 1;
    }
    if(GetPlayerVehicleID(playerid) == 49 || GetPlayerVehicleID(playerid) == 50 || GetPlayerVehicleID(playerid) == 51 || GetPlayerVehicleID(playerid) == 52)
    {
        if(ispolice[playerid] == 0)
        {
            RemovePlayerFromVehicle(playerid);
            ShowPlayerDialog(playerid, 3702, DIALOG_STYLE_MSGBOX, "No Keys", "You do not have the keys to this vehicle\nSimply because you are not in the {FF0000}BCSD.", "Ok", "");
            return 1;
        }
    }
    return 1;
}
see what I mean about the
pawn Код:
GetPlayerVehicleID(playerid) == 49 || GetPlayerVehicleID(playerid) == 50 || GetPlayerVehicleID(playerid) == 51 || GetPlayerVehicleID(playerid) == 52
So basicly all I'm saying is how can I get it all in 1 function?
Reply
#2

make a huge array for all created vehicles (only using max 2000 cells, so who the fuck cares), and set it to 1 at each created vehicle, in your case at vehicle ids 45 to 48, and 49 to 51:
pawn Код:
new VehicleAllowed[MAX_VEHICLES];

new TempID;
TempID=AddStaticVehcile(blablabla);
VehicleAllowed[TempID]=1;

public OnPlayerUpdate(playerid)
{
    if(VehicleAllowed[GetPlayerVehicleID(playerid)] == 1 && Taxijob[playerid] == 0)
i dont know about your faction system or how you set the jobs, but this could give you the idea on how to trade memory for runtime
edit:
its a good idea to move that stuff from OnPlayerUpdate() to OnPlayerStateChange() or OnPlayerEnterVehicle
Reply
#3

I have a password faction system, which is basicly /dsafjasdf signs you into the faction.

pawn Код:
public isfd[MAX_PLAYERS]; public ispolice[MAX_PLAYERS]; public istau[MAX_PLAYERS];
And I don't really understand your post.
Reply
#4

imagine you create 4 cars
pawn Код:
Car[45]=Create(cheetah);
Car[46]=Create(sultan);
Car[47]=Create(ingernus);
Car[48]=Create(nrg);
and you got an array with the same size as the amount of created vehicles, then each one should be set to a special allowed faction, or none at all:
pawn Код:
VehicleAllowed[45]=1;//only faction 1 is allowed to drive, all other factions gets kicked out
VehicleAllowed[46]=2;//only faction 2
VehicleAllowed[47]=2;
VehicleAllowed[48]=0;//no faction here, all players may drive, no need to add that line btw, any cell is 0 at start
.. you are using different faction variables for each player, so a isfd[playerid] can be true, while ispolice[playerid] also can be true. thats not the case i bet, since a player is supposed to work in 1 job at a time only.
checking for a player (being in a certain faction, ergo allowed/forbidden to drive), is best done with a pre-buffered array, the "vehicles allowances". who (faction) may drive it? or may ALL players drive? thats defined by setting a faction to either 1(isfd), 2(ispolice) or 3(istau) at each created vehicle, using its VehicleAllowed[vehicleid].
look at this line. isfd[playerid] is 1 as fireman. vehicle allowance of VehicleAllowed[45]=1 (the cheetah), so they match...
pawn Код:
if(isfd[playerid]==VehicleAllowed[GetPlayerVehicleID(playerid)] && Taxijob[playerid]==0)
    {
by using th SAME variable (like Faction[playerid]), you could set it to any value, so only one single check for any vehicle would be required. it also restricts a player to be in one single faction only. if you can sacrifice that, you will gain an elegant solution
if you want players to be in more than just 1 faction, then you need to add 1 or 2 more checks. slightly modified:
pawn Код:
if(ispolice[playerid]==VehicleAllowed[GetPlayerVehicleID(playerid)] && Taxijob[playerid]==0)
    {
Reply
#5

THANKS!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)