Police only...
#1

Alright i made the system so only the police skins can enter the police cars, But it does not work,
The Enum
pawn Code:
enum TeamCars
{
    Police
}

new Cars[TeamCars];
new Skins[TeamCars];
Checks the skin and car models
pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(GetVehicleModel(GetPlayerVehicleID(playerid)) == Cars[Police])
    {
    if(GetPlayerSkin(playerid) == Skins[Police])
    {
    SendClientMessage(playerid, 0x33FF33AA,"You have entered a Police vehicle");
    }
    else
    {
    RemovePlayerFromVehicle(playerid);
    SendClientMessage(playerid, 0xFF0000AA,"Error: you do not have the keys for this vehicle!");
    return 1;
    }
    }
    return 1;
}
PD Skins
pawn Code:
Skins[Police] = AddPlayerClass(280,1544.4233,-1673.0183,13.5584,87.1245,0,0,0,0,0,0);
    Skins[Police] = AddPlayerClass(281,1544.4233,-1673.0183,13.5584,87.1245,0,0,0,0,0,0);
    Skins[Police] = AddPlayerClass(282,1544.4233,-1673.0183,13.5584,87.1245,0,0,0,0,0,0);
    Skins[Police] = AddPlayerClass(283,1544.4233,-1673.0183,13.5584,87.1245,0,0,0,0,0,0);
    Skins[Police] = AddPlayerClass(284,1544.4233,-1673.0183,13.5584,87.1245,0,0,0,0,0,0);
Some of the PD Cars
pawn Code:
Cars[Police] = CreateVehicle(596,1601.06665039,-1692.17382812,5.46062469,91.29089355,-1,-1,15); //Police Car (LSPD)
    Cars[Police] = CreateVehicle(596,1601.45349121,-1687.62915039,5.46062469,89.30590820,-1,-1,15); //Police Car (LSPD)
    Cars[Police] = CreateVehicle(596,1601.17285156,-1684.14086914,5.46062469,89.30236816,-1,-1,15); //Police Car (LSPD)
    Cars[Police] = CreateVehicle(427,1530.66174316,-1644.98913574,6.13862514,179.47515869,-1,1,15); //Enforcer
    Cars[Police] = CreateVehicle(427,1534.38708496,-1645.19458008,6.13862514,179.47265625,-1,-1,15); //Enforcer
    Cars[Police] = CreateVehicle(601,1526.62500000,-1646.62597656,5.82083368,0.00000000,-1,-1,15); //S.W.A.T. Van
    Cars[Police] = CreateVehicle(599,1538.96801758,-1646.31713867,6.27575159,0.00000000,-1,1,15); //Police Ranger
    Cars[Police] = CreateVehicle(490,1543.90966797,-1651.23962402,6.21075153,89.32434082,-1,-1,15); //FBI Rancher
    Cars[Police] = CreateVehicle(411,1544.61230469,-1655.26037598,5.69062471,89.32434082,1,1,15); //Infernus
    Cars[Police] = CreateVehicle(541,1544.73278809,-1659.18371582,5.59062481,89.33935547,1,1,15); //Bullet
    Cars[Police] = CreateVehicle(415,1544.80761719,-1663.22778320,5.69014645,89.74975586,1,1,15); //Cheetah
    Cars[Police] = CreateVehicle(490,1544.37280273,-1668.03149414,6.21075153,89.32434082,-1,-1,15); //FBI Rancher
Reply
#2

Why are you using a table (more space) if you got only 1 function in it?
Try
pawn Code:
new Cars[MAX_VEHICLES];
new Skins[MAX_PLAYERS];
new Job[MAX_PLAYERS];
Add someone in OnPlayerCommandText
pawn Code:
if(!strcmp(cmdtext, "/police", true))
{
  Job[playerid] = 1;
   return 1;
}

if(!strcmp(cmdtext, "/civilian", true))
{
  Job[playerid] = 0;
  return 1;
}
Remove the Cars[Police] =, and add also at your OnPlayerEnterVehicle

pawn Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
  if(GetVehicleModel(vehicleid))
 {
    switch(GetVehicleModel))
   {
      case 596, 598, 597:
      {
        if(Job[playerid] != 1) return RemovePlayerFromVehicle(vehicleid); // kicks them when they'r not job 1 == police
        return 1;
      }    
    }
 }
 return 1;
}
Reply
#3

The problem is that you're comparing the model of the vehicle to the ID of the vehicle.

pawn Code:
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == Cars[Police])
You could either change == Cars[Police] to be the model ID of the vehicle, or you could simply edit it to work with the way you have it set up

pawn Code:
if(GetPlayerVehicleID(playerid) == Cars[Police])
Also there's a problem, you only have one variable for the vehicles, so basically Cars[Police] only contains one of the vehicle ID's (the last one you set it to). The only solution to this is to make Cars[Police] an array, and store multiple vehicle ID's in the array, then use a loop to go through them. This is a bit too much for something that can be done a lot easier and more effectively, so I recommend the simple solution which is something like.

pawn Code:
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 596)
Add if you want to check more models, you'd need a loop or just a long list of checks on that line.

pawn Code:
new model = GetVehicleModel(GetPlayerVehicleID(playerid));
if(model == 596 || model == 427 || model == 601 || model == 599)
Edit: Someone else also showed you how you can do it with a simple switch statement, either way will work however the switch statement would be cleaner.
Reply
#4

Quote:
Originally Posted by JaTochNietDan
View Post
The problem is that you're comparing the model of the vehicle to the ID of the vehicle.

pawn Code:
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == Cars[Police])
You could either change == Cars[Police] to be the model ID of the vehicle, or you could simply edit it to work with the way you have it set up

pawn Code:
if(GetPlayerVehicleID(playerid) == Cars[Police])
Also there's a problem, you only have one variable for the vehicles, so basically Cars[Police] only contains one of the vehicle ID's (the last one you set it to). The only solution to this is to make Cars[Police] an array, and store multiple vehicle ID's in the array, then use a loop to go through them. This is a bit too much for something that can be done a lot easier and more effectively, so I recommend the simple solution which is something like.

pawn Code:
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 596)
Add if you want to check more models, you'd need a loop or just a long list of checks on that line.

pawn Code:
new model = GetVehicleModel(GetPlayerVehicleID(playerid));
if(model == 596 || model == 427 || model == 601 || model == 599)
Edit: Someone else also showed you how you can do it with a simple switch statement, either way will work however the switch statement would be cleaner.
Alright i did what you did but now it just kicked me out the car when i am using PD skin..
Reply
#5

pawn Code:
new model = GetVehicleModel(GetPlayerVehicleID(playerid));
if(model != 596 || model != 427 || model != 601 || model != 599)
!= means if The Skin iD Is Not 596 continue. add your other police skins to it
Reply
#6

pawn Code:
new Cars[Police]1;
new Cars[Police]2;
new Cars[Police]3;
new Cars[Police]4;
new Cars[Police]5;
new Cars[Police]6;
new Cars[Police]7;
new Cars[Police]8;
new Cars[Police]9;
new Cars[Police]10;
new Cars[Police]11;
new Cars[Police]12;
pawn Code:
Cars[Police]1 = CreateVehicle(596,1601.06665039,-1692.17382812,5.46062469,91.29089355,-1,-1,15); //Police Car (LSPD)
    Cars[Police]2 = CreateVehicle(596,1601.45349121,-1687.62915039,5.46062469,89.30590820,-1,-1,15); //Police Car (LSPD)
    Cars[Police]3 = CreateVehicle(596,1601.17285156,-1684.14086914,5.46062469,89.30236816,-1,-1,15); //Police Car (LSPD)
    Cars[Police]4 = CreateVehicle(427,1530.66174316,-1644.98913574,6.13862514,179.47515869,-1,1,15); //Enforcer
    Cars[Police]5 = CreateVehicle(427,1534.38708496,-1645.19458008,6.13862514,179.47265625,-1,-1,15); //Enforcer
    Cars[Police]6 = CreateVehicle(601,1526.62500000,-1646.62597656,5.82083368,0.00000000,-1,-1,15); //S.W.A.T. Van
    Cars[Police]7 = CreateVehicle(599,1538.96801758,-1646.31713867,6.27575159,0.00000000,-1,1,15); //Police Ranger
    Cars[Police]8 = CreateVehicle(490,1543.90966797,-1651.23962402,6.21075153,89.32434082,-1,-1,15); //FBI Rancher
    Cars[Police]9 = CreateVehicle(411,1544.61230469,-1655.26037598,5.69062471,89.32434082,1,1,15); //Infernus
    Cars[Police]10 = CreateVehicle(541,1544.73278809,-1659.18371582,5.59062481,89.33935547,1,1,15); //Bullet
    Cars[Police]11 = CreateVehicle(415,1544.80761719,-1663.22778320,5.69014645,89.74975586,1,1,15); //Cheetah
    Cars[Police]12 = CreateVehicle(490,1544.37280273,-1668.03149414,6.21075153,89.32434082,-1,-1,15); //FBI Rancher
And under OnPlayerStateChange add this.
pawn Code:
if (newstate == PLAYER_STATE_DRIVER) {
new getthecar = GetPlayerVehicleID(playerid);
if (getthecar == Car[Police]1 || Car[Police]2 || Car[Police]3 || Car[Police]4 || Car[Police]5 || Car[Police]6 || Car[Police]7 || Car[Police]8 || Car[Police]9 || Car[Police]10 || Car[Police]11 || Car[Police]12) {
if(GetPlayerSkin(playerid) != Skins[Police]) return SendClientMessage(playerid, COLOR,"You dont have the keys for this vehicle!), RemovePlayerFromVehicle(playerid);
SendClientMessage(playerid, 0x33FF33AA,"
You have entered a Police vehicle");
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)