Help With OnPlayerStateChange
#1

I'm trying to create a piece of script that stops anyone who isn't swat from entering swat cars. I have tried many different things but all of them didn't work. Please could somebody help!

Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if(IsPlayerConnected(playerid))
	{
		if(gTeam[playerid] != TEAM_SWAT)
		IsPlayerInVehicle(playerid,SwatCar);
		RemovePlayerFromVehicle(playerid);
		SendClientMessage(playerid, COLOR_RED,"You have been ejected from the vehicle - You Are Not S.W.A.T");
 	}
	return 1;
}
Thanks
Reply
#2

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(IsPlayerConnected(playerid))
    {
        if(gTeam[playerid] != TEAM_SWAT && IsPlayerInVehicle(playerid,SwatCar)
        {
              RemovePlayerFromVehicle(playerid);
              SendClientMessage(playerid, COLOR_RED,"You have been ejected from the vehicle - You Are Not S.W.A.T");
        }
    }
    return 1;
}
have you definded the SwatCar anywhere in your script ?
Reply
#3

Yes, I've got SwatCar here:

Код:
new SwatCar;

SwatCar = AddStaticVehicle(415,2574.4297,2791.9282,10.5926,0.6702,0,0); // SWAT - Cheetah

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(IsPlayerConnected(playerid))
    {
        if(gTeam[playerid] != TEAM_SWAT && IsPlayerInVehicle(playerid,SwatCar)
        {
              RemovePlayerFromVehicle(playerid);
              SendClientMessage(playerid, COLOR_RED,"You have been ejected from the vehicle - You Are Not S.W.A.T");
        }
    }
    return 1;
}
Note: You needed to put an extra ) on this statement.

if(gTeam[playerid] != TEAM_SWAT && IsPlayerInVehicle(playerid,SwatCar)

to make it

if(gTeam[playerid] != TEAM_SWAT && IsPlayerInVehicle(playerid,SwatCar))

AND

THE SCRIPT YOU GAVE DOESN'T WORK
Reply
#4

You havent added a key to detect..
Reply
#5

I don't understand onplayerkeychangestate.
Reply
#6

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(IsPlayerConnected(playerid))
    {
        if(gTeam[playerid] != TEAM_SWAT && GetPlayerVehicleID(playerid) == SwatCar)
        {
              RemovePlayerFromVehicle(playerid);
              SendClientMessage(playerid, COLOR_RED,"You have been ejected from the vehicle - You Are Not S.W.A.T");
        }
    }
    return 1;
}
Try this one, tho I wiould suggest Setting player position instead RemovePlayerFromVehicle as Removing is slower.
Reply
#7

This only works for one car.. I have lots of cars.

Код:
SwatCar = AddStaticVehicle(415,2574.4297,2791.9282,10.5926,0.6702,0,0); // SWAT - Cheetah
	SwatCar = AddStaticVehicle(415,2570.5615,2792.0767,10.5914,0.9299,0,0); // SWAT - Cheetah
	SwatCar = AddStaticVehicle(415,2566.3796,2792.0466,10.5913,359.4993,0,0); // SWAT - Cheetah
	SwatCar = AddStaticVehicle(415,2562.2039,2792.0452,10.5929,0.9964,0,0); // SWAT - Cheetah
	SwatCar = AddStaticVehicle(415,2558.0940,2792.1858,10.5915,358.5075,0,0); // SWAT - Cheetah
	SwatCar = AddStaticVehicle(415,2553.7168,2792.3120,10.5927,359.7787,0,0); // SWAT - Cheetah
	SwatCar = AddStaticVehicle(415,2549.4983,2792.1211,10.5922,0.2932,0,0); // SWAT - Cheetah
	SwatCar = AddStaticVehicle(415,2545.5750,2792.1936,10.5926,359.6158,0,0); // SWAT - Cheetah
	SwatCar = AddStaticVehicle(415,2541.4482,2792.3184,10.5928,358.8225,0,0); // SWAT - Cheetah
	SwatCar = AddStaticVehicle(587,2574.5945,2768.5872,10.5460,178.7814,0,0); // SWAT - Euros
	SwatCar = AddStaticVehicle(587,2570.3674,2768.3809,10.5474,179.9563,0,0); // SWAT - Euros
	SwatCar = AddStaticVehicle(587,2566.2615,2768.7295,10.5483,179.5582,0,0); // SWAT - Euros
	SwatCar = AddStaticVehicle(587,2561.9038,2768.7612,10.5462,178.3078,0,0); // SWAT - Euros
	SwatCar = AddStaticVehicle(587,2557.8052,2768.6194,10.5476,179.7739,0,0); // SWAT - Euros
	SwatCar = AddStaticVehicle(587,2553.8728,2768.4998,10.5468,179.1818,0,0); // SWAT - Euros
	SwatCar = AddStaticVehicle(587,2549.7273,2768.7395,10.5461,180.9640,0,0); // SWAT - Euros
	SwatCar = AddStaticVehicle(480,2541.4121,2768.5486,10.5944,359.6268,0,0); // SWAT - Comet
	SwatCar = AddStaticVehicle(480,2537.1936,2768.3057,10.5934,358.3396,0,0); // SWAT - Comet
	SwatCar = AddStaticVehicle(480,2533.1843,2768.4578,10.5949,359.3449,0,0); // SWAT - Comet
	SwatCar = AddStaticVehicle(480,2528.8801,2768.5027,10.5938,359.6940,0,0); // SWAT - Comet
	SwatCar = AddStaticVehicle(480,2524.6924,2768.2234,10.5938,359.2802,0,0); // SWAT - Comet
	SwatCar = AddStaticVehicle(480,2520.7043,2768.3669,10.5924,3.6111,0,0); // SWAT - Comet
Reply
#8

Try
pawn Код:
//At Top
new SwatCar[23];
pawn Код:
//OnGameModeInit
    SwatCar[1] = AddStaticVehicle(415,2574.4297,2791.9282,10.5926,0.6702,0,0); // SWAT - Cheetah
    SwatCar[2] = AddStaticVehicle(415,2570.5615,2792.0767,10.5914,0.9299,0,0); // SWAT - Cheetah
    SwatCar[3] = AddStaticVehicle(415,2566.3796,2792.0466,10.5913,359.4993,0,0); // SWAT - Cheetah
    SwatCar[4] = AddStaticVehicle(415,2562.2039,2792.0452,10.5929,0.9964,0,0); // SWAT - Cheetah
    SwatCar[5] = AddStaticVehicle(415,2558.0940,2792.1858,10.5915,358.5075,0,0); // SWAT - Cheetah
    SwatCar[6] = AddStaticVehicle(415,2553.7168,2792.3120,10.5927,359.7787,0,0); // SWAT - Cheetah
    SwatCar[7] = AddStaticVehicle(415,2549.4983,2792.1211,10.5922,0.2932,0,0); // SWAT - Cheetah
    SwatCar[8] = AddStaticVehicle(415,2545.5750,2792.1936,10.5926,359.6158,0,0); // SWAT - Cheetah
    SwatCar[9] = AddStaticVehicle(415,2541.4482,2792.3184,10.5928,358.8225,0,0); // SWAT - Cheetah
    SwatCar[10] = AddStaticVehicle(587,2574.5945,2768.5872,10.5460,178.7814,0,0); // SWAT - Euros
    SwatCar[11] = AddStaticVehicle(587,2570.3674,2768.3809,10.5474,179.9563,0,0); // SWAT - Euros
    SwatCar[12] = AddStaticVehicle(587,2566.2615,2768.7295,10.5483,179.5582,0,0); // SWAT - Euros
    SwatCar[13] = AddStaticVehicle(587,2561.9038,2768.7612,10.5462,178.3078,0,0); // SWAT - Euros
    SwatCar[14] = AddStaticVehicle(587,2557.8052,2768.6194,10.5476,179.7739,0,0); // SWAT - Euros
    SwatCar[15] = AddStaticVehicle(587,2553.8728,2768.4998,10.5468,179.1818,0,0); // SWAT - Euros
    SwatCar[16] = AddStaticVehicle(587,2549.7273,2768.7395,10.5461,180.9640,0,0); // SWAT - Euros
    SwatCar[17] = AddStaticVehicle(480,2541.4121,2768.5486,10.5944,359.6268,0,0); // SWAT - Comet
    SwatCar[18] = AddStaticVehicle(480,2537.1936,2768.3057,10.5934,358.3396,0,0); // SWAT - Comet
    SwatCar[19] = AddStaticVehicle(480,2533.1843,2768.4578,10.5949,359.3449,0,0); // SWAT - Comet
    SwatCar[20] = AddStaticVehicle(480,2528.8801,2768.5027,10.5938,359.6940,0,0); // SWAT - Comet
    SwatCar[21] = AddStaticVehicle(480,2524.6924,2768.2234,10.5938,359.2802,0,0); // SWAT - Comet
    SwatCar[22] = AddStaticVehicle(480,2520.7043,2768.3669,10.5924,3.6111,0,0); // SWAT - Comet
pawn Код:
//...
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(IsPlayerConnected(playerid))
    {
        if(gTeam[playerid] != TEAM_SWAT && SwatCar[23])
        {
              RemovePlayerFromVehicle(playerid);
              SendClientMessage(playerid, COLOR_RED,"You have been ejected from the vehicle - You Are Not S.W.A.T");
        }
    }
    return 1;
}
Reply
#9

(837) : error 032: array index out of bounds (variable "SwatCar")
Код:
if(gTeam[playerid] != TEAM_SWAT && SwatCar[23])
This line.
Reply
#10

Quote:
Originally Posted by Tessar
Посмотреть сообщение
(837) : error 032: array index out of bounds (variable "SwatCar")
Код:
if(gTeam[playerid] != TEAM_SWAT && SwatCar[23])
This line.
pawn Код:
if(gTeam[playerid] != TEAM_SWAT && SwatCar[22])
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)