SA-MP Forums Archive
LSPD Cars Problem - 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: LSPD Cars Problem (/showthread.php?tid=456742)



LSPD Cars Problem - XStormiest - 07.08.2013

Hey i want some help with something.
I was trying to put protect on Factions Cars , i was trying in this way:
Right now i have protection only on Police, but it doesn't work cause everyone can enter in the LSPD cars
pawn Код:
new LSPD[28];
Under :
pawn Код:
public OnGameModeInit()
{
    //LSPD
    LSPD[0] = AddStaticVehicle(596,1528.7373,-1687.9275,5.6120,89.6197,1,0); // Policecar
    LSPD[1] = AddStaticVehicle(596,1529.0087,-1683.6345,5.6107,90.3719,1,0); // Policecar
    LSPD[2] = AddStaticVehicle(596,1526.7955,-1644.7029,5.6101,359.5225,1,0); // Policecar
    LSPD[3] = AddStaticVehicle(596,1530.4741,-1644.5486,5.6083,358.2887,1,0); // Policecar
    LSPD[4] = AddStaticVehicle(596,1534.8539,-1645.9208,5.6082,0.0238,1,0); // Policecar
    LSPD[5] = AddStaticVehicle(596,1538.7765,-1645.2241,5.6076,0.8801,1,0); // Policecar
    LSPD[6] = AddStaticVehicle(596,1545.2113,-1650.8497,5.6123,267.5586,1,0); // Policecar
    LSPD[7] = AddStaticVehicle(596,1545.3855,-1655.3594,5.6074,264.3560,1,0); // Policecar
    LSPD[8] = AddStaticVehicle(596,1544.4871,-1659.3488,5.6120,271.0551,1,0); // Policecar
    LSPD[9] = AddStaticVehicle(596,1545.3839,-1662.9076,5.6103,271.0779,1,0); // Policecar
    LSPD[10] = AddStaticVehicle(596,1544.6493,-1667.6846,5.6130,267.3245,1,0); // Policecar
    LSPD[11] = AddStaticVehicle(596,1544.3698,-1671.6233,5.6130,266.2461,1,0); // Policecar
    LSPD[12] = AddStaticVehicle(596,1544.6852,-1676.1718,5.6071,270.4680,1,0); // Policecar
    LSPD[13] = AddStaticVehicle(596,1544.6268,-1679.9368,5.6121,265.9038,1,0); // Policecar
    LSPD[14] = AddStaticVehicle(596,1545.4022,-1684.0714,5.6073,269.2596,1,0); // Policecar
    LSPD[15] = AddStaticVehicle(427,1559.1028,-1708.9164,6.0223,183.4390,0,1); // Policecar
    LSPD[16] = AddStaticVehicle(427,1565.5569,-1709.2582,6.0223,178.4198,0,1); // Policecar
    LSPD[17] = AddStaticVehicle(427,1570.6371,-1711.7288,6.0227,180.2581,0,1); // Policecar
    LSPD[18] = AddStaticVehicle(427,1575.2072,-1710.1499,6.0225,180.0766,0,1); // Policecar
    LSPD[19] = AddStaticVehicle(451,1578.9642,-1710.1852,5.5977,180.5287,0,0); // Policecar
    LSPD[20] = AddStaticVehicle(451,1583.8252,-1710.2747,5.5979,180.5677,0,0); // Policecar
    LSPD[21] = AddStaticVehicle(451,1587.6625,-1709.0377,5.5985,178.9323,0,0); // Policecar
    LSPD[22] = AddStaticVehicle(451,1591.7848,-1710.7012,5.5966,179.2430,0,0); // Policecar
    LSPD[23] = AddStaticVehicle(451,1595.3241,-1711.8500,5.5974,182.0077,0,0); // Policecar
    LSPD[24] = AddStaticVehicle(522,1584.8099,-1680.4534,5.4704,91.7415,0,1); // Policecar
    LSPD[25] = AddStaticVehicle(522,1585.4646,-1676.3069,5.4705,84.0498,0,1); // Policecar
    LSPD[26] = AddStaticVehicle(522,1585.2666,-1671.6919,5.4674,92.5899,0,1); // Policecar
    LSPD[27] = AddStaticVehicle(522,1584.2675,-1667.6511,5.4655,94.9324,0,1); // Policecar
   return 1;
}

Under:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
      new carid = GetPlayerVehicleID(playerid);
      if(carid == LSPD[0] && PlayerInfo[playerid][Faction] != 1)
      {
         RemovePlayerFromVehicle(playerid);
        SendErrorMessage(playerid, "You can't enter in the police cars");
      }
    }
    return 1;
}
If you can help me with the protections and it work i will do the rest for the others factions, but i need an example that work so i can work it , thanks for reading


Re: LSPD Cars Problem - Skribblez - 07.08.2013

Just a question. Why are you adding static vehicles when the game mode exits?

Quote:
Originally Posted by XStormiest
Посмотреть сообщение
pawn Код:
public OnGameModeExit()
{
    //LSPD
    LSPD[0] = AddStaticVehicle(596,1528.7373,-1687.9275,5.6120,89.6197,1,0); // Policecar
    LSPD[1] = AddStaticVehicle(596,1529.0087,-1683.6345,5.6107,90.3719,1,0); // Policecar
    LSPD[2] = AddStaticVehicle(596,1526.7955,-1644.7029,5.6101,359.5225,1,0); // Policecar
    LSPD[3] = AddStaticVehicle(596,1530.4741,-1644.5486,5.6083,358.2887,1,0); // Policecar
    LSPD[4] = AddStaticVehicle(596,1534.8539,-1645.9208,5.6082,0.0238,1,0); // Policecar
    LSPD[5] = AddStaticVehicle(596,1538.7765,-1645.2241,5.6076,0.8801,1,0); // Policecar
    LSPD[6] = AddStaticVehicle(596,1545.2113,-1650.8497,5.6123,267.5586,1,0); // Policecar
    LSPD[7] = AddStaticVehicle(596,1545.3855,-1655.3594,5.6074,264.3560,1,0); // Policecar
    LSPD[8] = AddStaticVehicle(596,1544.4871,-1659.3488,5.6120,271.0551,1,0); // Policecar
    LSPD[9] = AddStaticVehicle(596,1545.3839,-1662.9076,5.6103,271.0779,1,0); // Policecar
    LSPD[10] = AddStaticVehicle(596,1544.6493,-1667.6846,5.6130,267.3245,1,0); // Policecar
    LSPD[11] = AddStaticVehicle(596,1544.3698,-1671.6233,5.6130,266.2461,1,0); // Policecar
    LSPD[12] = AddStaticVehicle(596,1544.6852,-1676.1718,5.6071,270.4680,1,0); // Policecar
    LSPD[13] = AddStaticVehicle(596,1544.6268,-1679.9368,5.6121,265.9038,1,0); // Policecar
    LSPD[14] = AddStaticVehicle(596,1545.4022,-1684.0714,5.6073,269.2596,1,0); // Policecar
    LSPD[15] = AddStaticVehicle(427,1559.1028,-1708.9164,6.0223,183.4390,0,1); // Policecar
    LSPD[16] = AddStaticVehicle(427,1565.5569,-1709.2582,6.0223,178.4198,0,1); // Policecar
    LSPD[17] = AddStaticVehicle(427,1570.6371,-1711.7288,6.0227,180.2581,0,1); // Policecar
    LSPD[18] = AddStaticVehicle(427,1575.2072,-1710.1499,6.0225,180.0766,0,1); // Policecar
    LSPD[19] = AddStaticVehicle(451,1578.9642,-1710.1852,5.5977,180.5287,0,0); // Policecar
    LSPD[20] = AddStaticVehicle(451,1583.8252,-1710.2747,5.5979,180.5677,0,0); // Policecar
    LSPD[21] = AddStaticVehicle(451,1587.6625,-1709.0377,5.5985,178.9323,0,0); // Policecar
    LSPD[22] = AddStaticVehicle(451,1591.7848,-1710.7012,5.5966,179.2430,0,0); // Policecar
    LSPD[23] = AddStaticVehicle(451,1595.3241,-1711.8500,5.5974,182.0077,0,0); // Policecar
    LSPD[24] = AddStaticVehicle(522,1584.8099,-1680.4534,5.4704,91.7415,0,1); // Policecar
    LSPD[25] = AddStaticVehicle(522,1585.4646,-1676.3069,5.4705,84.0498,0,1); // Policecar
    LSPD[26] = AddStaticVehicle(522,1585.2666,-1671.6919,5.4674,92.5899,0,1); // Policecar
    LSPD[27] = AddStaticVehicle(522,1584.2675,-1667.6511,5.4655,94.9324,0,1); // Policecar
   return 1;
}



Re: LSPD Cars Problem - XStormiest - 07.08.2013

is OnGameModeInit , sorry..., i writed wrong in this post


Re: LSPD Cars Problem - Misiur - 07.08.2013

pawn Код:
if(carid == LSPD[0] && PlayerInfo[playerid][Faction] != 1)
Only first spawned LSPD car is protected.
Let's try a little diffrent approach:
pawn Код:
new LSPD[28];
//change to
#define LSPD_CARS (28)
new LSPD[LSPD_CARS];
new ptrLSPD = 0;
pawn Код:
LSPD[0] = AddStaticVehicle(596,1528.7373,-1687.9275,5.6120,89.6197,1,0);
//Change to
ptrLSPD = AddStaticVehicle(596,1528.7373,-1687.9275,5.6120,89.6197,1,0);
LSPD[0] = ptrLSPD;
Then

pawn Код:
//Change
if(carid == LSPD[0] && PlayerInfo[playerid][Faction] != 1)
//to
if(ptrLSPD <= carid <= ptrLSPD + LSPD_CARS && PlayerInfo[playerid][Faction] != 1)
#e: Of course you can simply loop through all vehicles, but it's standard memory/CPU dilemma


Re: LSPD Cars Problem - XStormiest - 07.08.2013

so i have to make something like:

pawn Код:
ptrLSPD = AddStaticVehicle(596,1528.7373,-1687.9275,5.6120,89.6197,1,0);
    ptrLSPD = AddStaticVehicle(596,1529.0087,-1683.6345,5.6107,90.3719,1,0);
    LSPD[0] = ptrLSPD;
    LSPD[1] = ptrLSPD;
right? cause i don't understand this part


Re: LSPD Cars Problem - Skribblez - 07.08.2013

Basing it on the vehicles that you're spawning, I've noticed that you're using 4 vehicle models. So you can do something like this:

pawn Код:
stock IsLSPDCar(vehicleid)
{
    if(GetVehicleModel(vehicleid) == 596 || GetVehicleModel(vehicleid) == 427 || GetVehicleModel(vehicleid) == 451 || GetVehicleModel(vehicleid) == 522) return true;
    else return false;
}
The code above checks if the vehicle a player is entering is an LSPD car. Returns true if yes, otherwise false.

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(IsPlayerConnected(playerid))
    {
        if(IsLSPDCar(vehicleid))
        {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid, -1, "You can't enter in police cars.");
        }
    }
    return 1;
}
When a player enters the vehicle it checks if it's an LSPD car or not and removes the player if it returns true.

EDIT: On second thought, replace "RemovePlayerFromVehicle(playerid);" with:

pawn Код:
TogglePlayerControllable(playerid, false);
TogglePlayerControllable(playerid, true);
Since OnPlayerEnterVehicle - called when a player starts to enter a vehicle, meaning the player is not in vehicle yet at the time this callback is called.


Re: LSPD Cars Problem - Misiur - 07.08.2013

No

pawn Код:
ptrLSPD = AddStaticVehicle(596,1528.7373,-1687.9275,5.6120,89.6197,1,0);
LSPD[0] = ptrLSPD;
//Nothing changes after this line
LSPD[1] = AddStaticVehicle(596,1529.0087,-1683.6345,5.6107,90.3719,1,0);
LSPD[2] = AddStaticVehicle(596,1526.7955,-1644.7029,5.6101,359.5225,1,0);



Re: LSPD Cars Problem - XStormiest - 07.08.2013

i was also thinking this way,
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(IsPlayerConnected(playerid))
    {
        if(IsLSPDCar(vehicleid))
        {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid, -1, "You can't enter in police cars.");
        }
    }
    return 1;
}
but what if also other factions have nrg/turismo etc...
So this is why i didn't want to try this way, i will try the first way that you told me, and i will come back with an edit so you can know if it worked
pawn Код:
 



Re: LSPD Cars Problem - -Prodigy- - 07.08.2013

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new carid = GetPlayerVehicleID(playerid);

        for(new i = 0; i < sizeof(LSPD); i++)
        {
            if(carid == LSPD[i] && PlayerInfo[playerid][Faction] != 1)
            {
                RemovePlayerFromVehicle(playerid);
                SendErrorMessage(playerid, "You can't enter in the police cars");
            }
        }
    }
    return 1;
}



Re: LSPD Cars Problem - Misiur - 07.08.2013

If you choose to use @-Prodigy- way, change it to

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new carid = GetPlayerVehicleID(playerid);
        if(PlayerInfo[playerid][Faction] == 1) {
            for(new i = 0; i < sizeof(LSPD); i++)
            {
                if(carid == LSPD[i])
                {
                    RemovePlayerFromVehicle(playerid);
                    SendErrorMessage(playerid, "You can't enter in the police cars");
                    break;
                }
            }
        }
    }
    return 1;
}