onplayerenter deny entry
#1

Hello everyone, my question is very simple.
How do I make it so when a player tries to enter a restricted vehicle, instead of clearing their animations and making them stop with a message. They instead attempt to open it but its locked to them, but still displaying the message.

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)//click
{
    if(!ispassenger)
    {
        if(IsSkipperVeh(vehicleid) && (PlayerInfo[playerid][pJob] != JOB_SKIPPER && PlayerInfo[playerid][pVIPJob] != JOB_SKIPPER))
        {
            ClearAnimations(playerid);
            SendClientMessage(playerid, COLOR_ORANGE, "You can't access this vehicle.");
        }
    }
    return 1;
}
Reply
#2

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)//click
{
    if(!ispassenger)
    {
        if(IsSkipperVeh(vehicleid) && (PlayerInfo[playerid][pJob] != JOB_SKIPPER && PlayerInfo[playerid][pVIPJob] != JOB_SKIPPER))
        {
            new Float:VBPos[3];
            GetPlayerPos(playerid,VBPos[0],VBPos[1],VBPos[2]);
            SetPlayerPos(playerid,VBPos[0],VBPos[1],VBPos[2]);
            SendClientMessage(playerid, COLOR_ORANGE, "You can't access this vehicle.");
        }
    }
    return 1;
}
Reply
#3

That code is bad, the car is still accessible from a specific point, remove him from the vehicle once his state is changed.
Reply
#4

Hmm, I wanted to test it before I replied but im getting tag mismatch warnings when I compile..
edit: ah okay, i wasnt too sure of it either but im not a pro scripter so i wasnt sure.
If I do that, he would not look like his trying to get in it but in turn fails because he doesnt have the keys.
I mean theres got to be a way to make it so Skippers have the keys to the boats so they can use it where as
if your not, you dont have keys and you cant get in..
Reply
#5

new VBPos[3]; isn't a defined as Float, thats why. Also it can bug your players , use new Float:VBPos[MAX_PLAYERS][3]; and use VBPos[playerid][0] etc.
Reply
#6

Quote:
Originally Posted by EV007
Посмотреть сообщение
new VBPos[3]; isn't a defined as Float, thats why. Also it can bug your players , use new Float:VBPos[MAX_PLAYERS][3]; and use VBPos[playerid][0] etc.
Use only new Float:VBPos[3];

[MAX_PLAYERS] isn't necessary
Reply
#7

Yeah I edited my last post.
I basically want it so that the vehicle is locked to someone who doesnt have that particular job.
Reply
#8

if two players access a vehicle at the same time, the result won't be the same.

i.e : I'm in LS and you're in SF, we both enter locked vehicle at the same time,some milisec difference, we can end up getting switched places, i'd be in SF, u in LS or, we both at same spot.

If this was C++, then of course it would work 100 or 99.9999%, but SAMP doesn't read this fast as that language does.


EDIT: You can just use setvehicleparamsforplayer functions, or something like that. It locks the vehicle.
Reply
#9

oh kay sweet EV007, Would you be able to give me a quit example of what I would be trying to do in the way of using that?
Reply
#10

Quote:
Originally Posted by EV007
Посмотреть сообщение
if two players access a vehicle at the same time, the result won't be the same.

i.e : I'm in LS and you're in SF, we both enter locked vehicle at the same time,some milisec difference, we can end up getting switched places, i'd be in SF, u in LS or, we both at same spot.
This will not happen ...
Reply
#11

This will happen, it happens MOST of the time when player ping is high , 150+. I have done many tests.

edit:

heres the code I got in my /lock command

pawn Code:
for(new i=0;i<MAX_PLAYERS;i++)
        {
            if(i != playerid)
            {
                SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 1);
            }
        }
Reply
#12

Could I just make it onplayerentervehicle, if they are restricted then:
SetVehicleParamsForPlayer(vehicleid,playerid,0,1); ?
Or maybe I can figure out a way to make it so when you become the job it unlocks then, when you quit it locks it..
Reply
#13

The command locks the vehicle for everyone except you. you have to be in the vehicle, if you want to lock the vehicle while its unoccupied, just specify the vehicle id instead of getplayervehicleid
Reply
#14

Couldnt I just use
SetVehicleParamsForPlayer(vehicleid,playerid,0,1);
?
Reply
#15

It will probably lock the vehicle, but the person will still be able to enter it from FIRST time. it won't work afterwards tho.
Reply
#16

hmm i tried it and they could enter it no matter what :/
Is there a way to get around that? To make it function correctly?
Reply
#17

Told you, you can lock vehicles by specifying their correct vehicleid in gamemodeinit maybe, or where ever you have them added.

edit: onvehiclestreamin can work fine too
Reply
#18

is there a certain way i need to do that?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)