Faction vehicles
#1

Hi there, I was wondering how I could make faction vehicles? The idea I had in mind was - if the player enters a faction vehicle, (specific vehicle MODEL ID, not the vehicle ID, but the model ID - the system checks their faction. My code is: (PlayerInfo[playerid][Faction]), as the system should check for that. If the ID is one, for example, the player gets access to the vehicle - if not, it returns a message and kicks the player from the vehicle.
Reply
#2

It's better to do it by vehicle ID, not model, because that'll restrict one model for one faction.

If your factions are static, then you could use this method.

pawn Код:
new gPoliceCars[10];

public OnGameModeInit()
{
    // in a loop if you were doing a lot of the SAME vehicle models
    for(new i=0; i<10; i++) {
        gPoliceCars[i] = CreateVehicle(...);
    }
   
    //OR one by one with different models
    gPoliceCars[0] = CreateVehicle(...);
    gPoliceCars[1] = CreateVehicle(...);
    gPoliceCars[2] = CreateVehicle(...);
    gPoliceCars[3] = CreateVehicle(...);
    gPoliceCars[4] = CreateVehicle(...);
    gPoliceCars[5] = CreateVehicle(...);
    gPoliceCars[6] = CreateVehicle(...);
    gPoliceCars[7] = CreateVehicle(...);
    gPoliceCars[8] = CreateVehicle(...);
    gPoliceCars[9] = CreateVehicle(...);
    return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(!ispassenger) {
        for(new i=0; i<10; i++) {
            if(vehicleid == gPoliceCars[i]) {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, -1, "You are not a cop!");
            }
        }
    }
    return 1;
}
Reply
#3

How would that restrict the faction for that specific ID?
Reply
#4

For example you could want two police factions, using the same car model, with different colors. Your method will prevent that.
Reply
#5

Doubt I'll be using multipe police factions any time soon, which is why I was planning to use my method.
Reply
#6

pawn Код:
stock IsACopC(vehicleid) { switch(GetVehicleModel(vehicleid)) { case 596,597: return 1; } return 0;} // Add anymore vehicles you want.
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(newstate == PLAYER_STATE_DRIVER)
    {
        if(IsCopCar(vehicleid) && PlayerInfo[playerid][Faction] != 1 )
        {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid, COLOR_GREY, "This is a Police vehicle.");
        }
    }
    return 1;
}

This should work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)