Faction Vehicles
#1

I got 6 ZR-350 with a siren as cop vehicle.
I used the next code to prevent civillians to enter the ZR-350

Код:
		if(vehicleid >= CopVehicle[0] && vehicleid <= CopVehicle[6])
	{
		if(PlayerInfo[playerid][pMember] != 1)
	    {
	    	SendClientMessage(playerid, COLOR_WHITE,"You don't have the keys of this vehicle( Faction-vehicle)");
	    	ClearAnimations(playerid);
		}
	}
And here the vehicles and siren..
Код:
	CopVehicle[0] = AddStaticVehicle(477,1566.2892,-1615.8591,13.1186,270.1325,1,1); // cop car 1
	CopVehicle[1] = AddStaticVehicle(477,1557.3464,-1615.8545,13.1397,270.2108,1,1); // cop car 2
	CopVehicle[2] = AddStaticVehicle(477,1591.6287,-1606.2499,13.1367,180.9415,1,1); // cop car 3
	CopVehicle[3] = AddStaticVehicle(477,1597.4304,-1606.0475,13.1902,181.4439,1,1); // cop car 4
	CopVehicle[4] = AddStaticVehicle(477,1601.6312,-1630.6210,13.2421,91.8427,1,1); // cop car 5
	CopVehicle[5] = AddStaticVehicle(477,1564.4960,-1631.6226,13.1129,88.9426,1,1); // cop car 6

	new SirenC;
	for(new i=0; i<sizeof(CopVehicle); i++)
	{
    SirenC = CreateObject(19419, 10.0, 10.0, 10.0, 0, 0, 0);
    AttachObjectToVehicle(SirenC, CopVehicle[i], -0.039999, -0.469999, 0.669999, 0.000000, 0.000000, 0.000000);
But civillians can still enter the car? Whats wrong?
Reply
#2

read this it will help you out

http://forum.sa-mp.com/showthread.ph...ht=faction+car
Reply
#3

Instead of ClearAnimations, try GetPlayerPos, then SetPlayerPos to the same point.
Reply
#4

Quote:
Originally Posted by MattyG
Посмотреть сообщение
Instead of ClearAnimations, try GetPlayerPos, then SetPlayerPos to the same point.
Nope doesn't work.
Btw. The players don't even get the msg: You don't have the keys of this vehicle( Faction-vehicle)
Reply
#5

Make sure that civilians don't accidentally get their pMember set to 1 somewhere. Just search for "PlayerInfo[playerid][pMember] = 1" (without quotation marks) and find out where this gets set. Also make sure that it gets set to 0 when they connect, before you load your data.
Reply
#6

pawn Код:
new CopVehicle[10]
new SirenC
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(vehicleid >= CopVehicle[0] && vehicleid <= CopVehicle[6])
    {
        if(PlayerInfo[playerid][pMember] != 1)
        {
            new Float:x, Float:y, Float:y;
            GetPlayerPos(playerid, x, y, z);
            SetPlayerPos(playerid, x, y, z)
            SendClientMessage(playerid, COLOR_WHITE, "You dont have the keys to this vehicle! (Faction Restricted)");
        }
    }
    return 1;
}

pawn Код:
public OnGameModeInit()
{
    CopVehicle[0] = AddStaticVehicle(477,1566.2892,-1615.8591,13.1186,270.1325,1,1); // cop car 1
    CopVehicle[1] = AddStaticVehicle(477,1557.3464,-1615.8545,13.1397,270.2108,1,1); // cop car 2
    CopVehicle[2] = AddStaticVehicle(477,1591.6287,-1606.2499,13.1367,180.9415,1,1); // cop car 3
    CopVehicle[3] = AddStaticVehicle(477,1597.4304,-1606.0475,13.1902,181.4439,1,1); // cop car 4
    CopVehicle[4] = AddStaticVehicle(477,1601.6312,-1630.6210,13.2421,91.8427,1,1); // cop car 5
    CopVehicle[5] = AddStaticVehicle(477,1564.4960,-1631.6226,13.1129,88.9426,1,1); // cop car 6

    for(new i=0; i<sizeof(CopVehicle); i++)
    {
        SirenC = CreateObject(19419, 10.0, 10.0, 10.0, 0, 0, 0);
        AttachObjectToVehicle(SirenC, CopVehicle[i], -0.039999, -0.469999, 0.669999, 0.000000, 0.000000, 0.000000);
    }
    return 1;
}
Reply
#7

Quote:
Originally Posted by J4mmyHD
Посмотреть сообщение
pawn Код:
new CopVehicle[10]
new SirenC
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(vehicleid >= CopVehicle[0] && vehicleid <= CopVehicle[6])
    {
        if(PlayerInfo[playerid][pMember] != 1)
        {
            new Float:x, Float:y, Float:y;
            GetPlayerPos(playerid, x, y, z);
            SetPlayerPos(playerid, x, y, z)
            SendClientMessage(playerid, COLOR_WHITE, "You dont have the keys to this vehicle! (Faction Restricted)");
        }
    }
    return 1;
}
Код:
new Float:x, Float:y, Float:y;
? I think you mean
Код:
 new Float:x, Float:y, Float:z;
?

EDIT: Doesn't work? Like i said before.

Quote:
Originally Posted by MattyG
Посмотреть сообщение
Make sure that civilians don't accidentally get their pMember set to 1 somewhere. Just search for "PlayerInfo[playerid][pMember] = 1" (without quotation marks) and find out where this gets set. Also make sure that it gets set to 0 when they connect, before you load your data.
I can't find were the civillians get their pMember also to reset the pMember i have set this under OnPlayerConnect
Код:
PlayerInfo[playerid][pMember] = 0;
But still normal players can enter
Reply
#8

Try this:

pawn Код:
IsACopVehicle(carid)
{
    for(new v = 0; v < sizeof(CopVehicle); v++)
    {
        if(carid == CopVehicle[v]) return 1;
    }
    return 0;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        if(IsACopVehicle(vehicleid))
        {
            if(PlayerInfo[playerid][pMember] != 1)
            {
                RemovePlayerFromVehicle(playerid);
                new Float:x, Float:y, Float:z;
                GetPlayerPos(playerid, x, y, z);
                SetPlayerPos(playerid, x, y, z);
                SendClientMessage(playerid, COLOR_WHITE, "You dont have the keys to this vehicle! (Faction Restricted)");
            }
        }
    }
    return 1;
}
I have not tested the code, but it should work.
Reply
#9

Quote:
Originally Posted by JJB562
Посмотреть сообщение
Try this:

pawn Код:
IsACopVehicle(carid)
{
    for(new v = 0; v < sizeof(CopVehicle); v++)
    {
        if(carid == CopVehicle[v]) return 1;
    }
    return 0;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        if(IsACopVehicle(vehicleid))
        {
            if(PlayerInfo[playerid][pMember] != 1)
            {
                RemovePlayerFromVehicle(playerid);
                new Float:x, Float:y, Float:z;
                GetPlayerPos(playerid, x, y, z);
                SetPlayerPos(playerid, x, y, z);
                SendClientMessage(playerid, COLOR_WHITE, "You dont have the keys to this vehicle! (Faction Restricted)");
            }
        }
    }
    return 1;
}
I have not tested the code, but it should work.
With this one?
Код:
    CopVehicle[0] = AddStaticVehicle(477,1566.2892,-1615.8591,13.1186,270.1325,1,1); // cop car 1
    CopVehicle[1] = AddStaticVehicle(477,1557.3464,-1615.8545,13.1397,270.2108,1,1); // cop car 2
    CopVehicle[2] = AddStaticVehicle(477,1591.6287,-1606.2499,13.1367,180.9415,1,1); // cop car 3
    CopVehicle[3] = AddStaticVehicle(477,1597.4304,-1606.0475,13.1902,181.4439,1,1); // cop car 4
    CopVehicle[4] = AddStaticVehicle(477,1601.6312,-1630.6210,13.2421,91.8427,1,1); // cop car 5
    CopVehicle[5] = AddStaticVehicle(477,1564.4960,-1631.6226,13.1129,88.9426,1,1); // cop car 6
Because from what im reading i need to add this:
Код:
stock IsACopVehicle(vehicleid)
{
    switch(GetVehicleModel(vehicleid))
    {
        case 477: return 1;
    }
    return 0;
}
But than all ZR-350's (Veh ID 477) would be blocked for normal players?
Please correct me if im wrong, Still a beginner
Reply
#10

No, the code I gave you should have worked. Let me try to explain the code as best I can:

pawn Код:
IsACopVehicle(carid)
{
    for(new v = 0; v < sizeof(CopVehicle); v++) // This will loop through all your CopVehicles.
    {
        if(carid == CopVehicle[v]) return 1; // If the vehicleid is defined by CopVehicle, it will return 1.
    }
    return 0; // If it is not, it will return 0.
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)