OnPlayerEnterVehicle bug -
AlexGheorghe - 05.06.2017
Hi, i have a problem with OnPlayerEnterVehicle callback. I want to do this: when a player enter into a police car / paramedic car and he isn't from this faction, to get him out of the car. The code works with this vehicles (police and paramedic) but for example when i spawn a car with /spawncar, if i want to enter vehicle, the code works as if entering a police or paramedic car. Here is my code:
https://pastebin.com/y7HrFxFw
Thank you!
Re: OnPlayerEnterVehicle bug -
DeeadPool - 05.06.2017
There is no need of a Timer to remove the player from the vehicle, instead use ClearAnimations and the player won't be able to enter it. The code should work.
PHP код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(vehicleid == PoliceVehicle[1] || PoliceVehicle[2] || PoliceVehicle[3] || PoliceVehicle[4] || PoliceVehicle[5] || PoliceVehicle[6] || PoliceVehicle[7] || PoliceVehicle[8] || PoliceVehicle[9])
{
if(PlayerInfo[playerid][pFaction] != 1)
{
ClearAnimations(playerid);
GameTextForPlayer(playerid, "~r~Nu esti autorizat sa conduci aceasta masina!", 1000, 3);
}
else return InCopCar[playerid] = 1;
}
else return InCopCar[playerid] = 0;
else if(vehicleid == ParamedicVehicle[1] || ParamedicVehicle[1] || ParamedicVehicle[1] || ParamedicVehicle[1] || ParamedicVehicle[1] || ParamedicVehicle[1] || ParamedicVehicle[1] || ParamedicVehicle[1] || ParamedicVehicle[1])
{
if(PlayerInfo[playerid][pFaction] != 2)
{
ClearAnimations(playerid);
GameTextForPlayer(playerid, "~r~Nu esti autorizat sa conduci aceasta masina!", 1000, 3);
}
else return InParamedicCar[playerid] = 1;
}
else return InParamedicCar[playerid] = 0;
return 1;
}
Re: OnPlayerEnterVehicle bug -
AlexGheorghe - 05.06.2017
You are right with ClearAnimations instead of Timers, but not this is my problem. I can't enter in any other car, like spawned car if i'm not in the group 1 (police). Some photos here if they help:
http://imgur.com/a/A2nOr
I hope you understand my problem now.
Thanks again for your time.
Re: OnPlayerEnterVehicle bug -
DeeadPool - 05.06.2017
Can you send me your variable of PoliceVehicle & Parademic Vehicle? Then maybe I can help you out.
Re: OnPlayerEnterVehicle bug -
AlexGheorghe - 05.06.2017
It's ok?
https://pastebin.com/ecmR7WKR
Re: OnPlayerEnterVehicle bug -
DeeadPool - 05.06.2017
Ah.. Maybe try use these 2 stock(s), would be much better.
PHP код:
stock IsAPoliceVehicle(vehicleid)
{
switch(GetVehicleModel(vehicleid))
{
case 598, 599, 523: return 1; // You can add more vehicles id if u add more cop vehicles.
}
return 0;
}
PHP код:
stock IsAParademicVehicle(vehicleid)
{
switch(GetVehicleModel(vehicleid))
{
case 416: return 1; // same applies here.
}
return 0;
}
Your final code should be this and should be working. (Haven't tested it but looks fine for me.)
PHP код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(IsAPoliceVehicle(vehicleid))
{
if(PlayerInfo[playerid][pFaction] != 1)
{
ClearAnimations(playerid);
GameTextForPlayer(playerid, "~r~Nu esti autorizat sa conduci aceasta masina!", 1000, 3);
}
else return InCopCar[playerid] = 1;
}
else return InCopCar[playerid] = 0;
else if(IsAParademicVehicle(vehicleid))
{
if(PlayerInfo[playerid][pFaction] != 2)
{
ClearAnimations(playerid);
GameTextForPlayer(playerid, "~r~Nu esti autorizat sa conduci aceasta masina!", 1000, 3);
}
else return InParamedicCar[playerid] = 1;
}
else return InParamedicCar[playerid] = 0;
return 1;
}
Re: OnPlayerEnterVehicle bug -
CrossUSAAF - 05.06.2017
Please try something like this:
PHP код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) {
if (!ispassenger) {
for (new i = 1; i < sizeof(PoliceVehicle); i++) {
if (vehicleid == PoliceVehicle[i]) {
if (PlayerInfo[playerid][pFaction] != 1) {
ClearAnimations(playerid);
} else {
InCopCar[playerid] = 1;
}
break;
}
}
}
return 1;
}
Re: OnPlayerEnterVehicle bug -
AlexGheorghe - 05.06.2017
This code works. Thank you very much for helping! Rep+