SA-MP Forums Archive
Faction vehicles - 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: Faction vehicles (/showthread.php?tid=379799)



Faction vehicles - davelord - 23.09.2012

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.


Re: Faction vehicles - ReneG - 23.09.2012

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;
}



Re: Faction vehicles - davelord - 23.09.2012

How would that restrict the faction for that specific ID?


Re: Faction vehicles - ReneG - 23.09.2012

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


Re: Faction vehicles - davelord - 23.09.2012

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


Re: Faction vehicles - JhnzRep - 23.09.2012

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.