PDA

View Full Version : Enter Vehicle Problem


Nin9r
02/07/2017, 01:56 PM
Hi there ! I want to know how can I make a restriction for players to enter into a faction/job vehicle.
For the moment, i am using ONPLAYERSTATECHANGE and REMOVEPLAYERFROMVEHICLE to check if he is in that factions or job and then he is ejected from that vehicle. But, I want to make something, when he press F or ENTER to send directly that message and deny to enter in that vehicle. I hope that you understood. Sorry for my english.

Kane
02/07/2017, 02:04 PM
Use OnPlayerEnterVehicle

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(IsAFactionVehicle && PlayerFaction != CarFaction && !ispassenger) // Example. Put your code here to check the vehicle and player.
{
ClearAnimations(playerid);
SendClientMessage(playerid, -1, "This vehicle is restricted.");
}
return true;
}

Nin9r
02/07/2017, 02:12 PM
Thanks a lot !

Nin9r
05/07/2017, 03:19 PM
No, it doesn't work. Same problem. The player can entry in a vehicle and after he is eject+interdiction. I want to make something to show directly the interdiction message.

PS: I used ClearAnimations(playerid); after check if the player is in that faction/job or not.

Whatname
05/07/2017, 03:40 PM
-REMOVED-

Dayrion
05/07/2017, 04:03 PM
Can you show your actually code?

Nin9r
06/07/2017, 10:13 AM
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new newcar = GetPlayerVehicleID(playerid);
if(PlayerData[playerid][pGroup] != vehicleVariables[newcar][vVehicleGroup])
{
format(szMessage, sizeof(szMessage), "You can't drive this vehicle.");
SendClientMessage(playerid, COLOR_GREY,szMessage);
ClearAnimations(playerid);
}
return 1;
}

Dayrion
06/07/2017, 01:29 PM
Instead of "ClearAnimations", you should use "RemovePlayerFromVehicle"

JasonRiggs
06/07/2017, 01:35 PM
You didn't even give the order to remove the player out of the vehicle, you cleared the animations, Which totally won't reject the player from the car, Use "RemovePlayerFromVehicle" as Dayrion said..

Nin9r
06/07/2017, 02:19 PM
You misunderstand. I don't wanna remove a player from vehicle after he entry in it. I want to make a system to restrict the entry if it's a job/groupid car. What you said above doesn't help me. That thing will remove the player from vehicle after he is in it.

Kane
06/07/2017, 02:25 PM
. . .

https://image.prntscr.com/image/r_1--mbETPiDZideXLvnLQ.png

Not possible to enter if you ClearAnimations().

Sew_Sumi
06/07/2017, 02:25 PM
The callback is fired BEFORE the player enters, so therefore removing them from the vehicle won't do shit if they're not actually in it.

Maybe try set the doors to locked for them when they try to enter.

http://wiki.sa-mp.com/wiki/SetVehicleParamsForPlayer


Also your code is wrong...

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new newcar = GetPlayerVehicleID(playerid);
if(PlayerData[playerid][pGroup] != vehicleVariables[newcar][vVehicleGroup])
{
format(szMessage, sizeof(szMessage), "You can't drive this vehicle.");
SendClientMessage(playerid, COLOR_GREY,szMessage);
ClearAnimations(playerid);
}
return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
//new newcar = GetPlayerVehicleID(playerid);

if(PlayerData[playerid][pGroup] != vehicleVariables[vehicleid][vVehicleGroup])
{
format(szMessage, sizeof(szMessage), "You can't drive this vehicle.");
SendClientMessage(playerid, COLOR_GREY,szMessage);
ClearAnimations(playerid);
}
return 1;
}

You were checking the players 'current' car, when they weren't in one, and were simply entering.

Nin9r
06/07/2017, 02:30 PM
. . .

https://image.prntscr.com/image/r_1--mbETPiDZideXLvnLQ.png

Not possible to enter if you ClearAnimations().

I explained for three times. I don't want to enter in vehiclee, i want to display restriction message and stop him from entering. That's the point . CLEARANIMATIONS is good there.

JasonRiggs
06/07/2017, 02:34 PM
Try the code of Sew_Sumi, i believe it will work i guess, he simply spotted a problem in it, and made it 'fixed' what you're asking for..

EDIT: fixed it Sew ;)

Sew_Sumi
06/07/2017, 02:35 PM
Did you see what I put that you're checking for the players car, and not using the vehicleID provided by the callback?

Jason, I didn't so much 'make' it, I simply spotted a problem in it, and made it 'fixed'. ;)

Nin9r
06/07/2017, 03:07 PM
Did you see what I put that you're checking for the players car, and not using the vehicleID provided by the callback?

Jason, I didn't so much 'make' it, I simply spotted a problem in it, and made it 'fixed'. ;)

Thank you so much. I am so dumb. Thanks ! +REP