Vlock.
#1

Could someone tell me why this specific vehicle door isn't locking? it's my first time locking vehicle doors though.

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	new veh = GetPlayerVehicleID(playerid);
	if(veh == Car[TEAM_COP] && gTeam[playerid] != TEAM_COP)
	{
		SetVehicleParamsForPlayer(veh, playerid, 0, 1);
		SendClientMessage(playerid, -1, "Cops Only!.");
	}
	return 1;
}
Reply
#2

OnPlayerEnterVehicle is called when a player starts to enter the vehicle but the player is not in the vehicle yet. GetPlayerVehicleID will return 0 by the way and the whole statement will fail, use vehicleid parameter.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
OnPlayerEnterVehicle is called when a player starts to enter the vehicle but the player is not in the vehicle yet. GetPlayerVehicleID will return 0 by the way and the whole statement will fail, use vehicleid parameter.
Ik,i read the wiki,i've tried the vehicleid it still doesn't work.
Reply
#4

The issue here is that you're using GetPlayerVehicleID instead of the vehicleid parameter provided in the callback header.

It helps to clear the player's animations as they attempt entry. With the code you provided it's still possible for anyone to enter the vehicle. If you're looking to lock the vehicle when a player in the wrong team approaches it, use OnVehicleStreamIn:

pawn Код:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
    if(vehicleid == Car[TEAM_COP] && gTeam[playerid] != TEAM_COP)
    {
        SetVehicleParamsForPlayer(vehicleid, forplayerid, 0, 1);
    }
}
Also what is Car[TEAM_COP] being assigned to? You may be attempting to assign multiple vehicle IDs to it, e.g:

pawn Код:
Car[TEAM_COP] = CreateVehicle(...);
Car[TEAM_COP] = CreateVehicle(...);
Car[TEAM_COP] = CreateVehicle(...);
In this instance only the last created vehicle ID is assigned to that variable. Therefore this means only one vehicle is designated for TEAM_COP. Two dimensional arrays exist for this purpose:

pawn Код:
Car[TEAM_COP][0] = CreateVehicle(...);
Car[TEAM_COP][1] = CreateVehicle(...);
Car[TEAM_COP][2] = CreateVehicle(...);
Reply
#5

Quote:
Originally Posted by Chump
Посмотреть сообщение
The issue here is that you're using GetPlayerVehicleID instead of the vehicleid parameter provided in the callback header.

It helps to clear the player's animations as they attempt entry. With the code you provided it's still possible for anyone to enter the vehicle. If you're looking to lock the vehicle when a player in the wrong team approaches it, use OnVehicleStreamIn:

pawn Код:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
    if(vehicleid == Car[TEAM_COP] && gTeam[playerid] != TEAM_COP)
    {
        SetVehicleParamsForPlayer(vehicleid, forplayerid, 0, 1);
    }
}
Also what is Car[TEAM_COP] being assigned to? You may be attempting to assign multiple vehicle IDs to it, e.g:

pawn Код:
Car[TEAM_COP] = CreateVehicle(...);
Car[TEAM_COP] = CreateVehicle(...);
Car[TEAM_COP] = CreateVehicle(...);
In this instance only the last created vehicle ID is assigned to that variable. Therefore this means only one vehicle is designated for TEAM_COP. Two dimensional arrays exist for this purpose:

pawn Код:
Car[TEAM_COP][0] = CreateVehicle(...);
Car[TEAM_COP][1] = CreateVehicle(...);
Car[TEAM_COP][2] = CreateVehicle(...);
My teams are now defined in an enum. so i've
Код:
new Car[Team];
to make the team cars,should i change it to the second time you said?
Reply
#6

Errrm this won't work
Код:
new Car[Team];
It needs to be able to hold all the vehicles so it have different values for each individual vehicle
Код:
new Car[MAX_VEHICLES];
now to set it to a team do
Код:
Car[ vehicleid ] = TEAM_COP; // or what ever you have defined for that team
then in OnVehicleStreamIn you could do this:
Код:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
    if(Car[ vehicleid ] == TEAM_COP && gTeam[playerid] != TEAM_COP)
    {
        SetVehicleParamsForPlayer(vehicleid, forplayerid, 0, 1);
    }
}
Hopefully you understand this?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)