How can i restrict players from entering a specific vehicle?
#1

Right now im using this code

Code:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
    if(vehicleid == 520 && User[playerid][accountVIP] == 0))
    {
        RemovePlayerFromVehicle(playerid);
        SendClientMessage(playerid, -1, "I'm sorry, but this car has been reserved for Admins only!");
    }
    return 1;
}
If the player is not VIP he will not be able to enter hydra.
It doesn't seem to do anything though.
Reply
#2

new model = GetVehicleModel(vehicleid);
if(model == 411 && User[playerid][accountVIP] == 0))
{
RemovePlayerFromVehicle(playerid);
SendClientMessage(playerid, -1, "I'm sorry, but this car has been reserved for VIPS only!");
}
return 1;
}

411 = infernus
https://sampwiki.blast.hk/wiki/Vehicle_Model_ID_List
Reply
#3

You need to use OnPlayerStateChange. When onPlayerEnterVehicle is called, the player is not yet in the vehicle. Plus you need to use GetVehicleModel like the guy before me suggested.
Reply
#4

PHP Code:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
newstate == PLAYER_STATE_DRIVER)
    {
        new 
vmodel GetVehicleModel(GetPlayerVehicleID(playerid));
        if(
vmodel == 520 && User[playerid][accountVIP] <= 0)
        {
            
RemovePlayerFromVehicle(playerid);
            
SendClientMessage(playerid, -1"I'm sorry, but this car has been reserved for Admins only!");
        }
    }
    return 
1;

Reply
#5

Quote:
Originally Posted by The King's Bastard
View Post
You need to use OnPlayerStateChange. When onPlayerEnterVehicle is called, the player is not yet in the vehicle. Plus you need to use GetVehicleModel like the guy before me suggested.
Or he can replace RemovePlayerFromVehicle with ClearPlayerAnimations.
Reply
#6

Quote:
Originally Posted by Undef1ned
View Post
PHP Code:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
newstate == PLAYER_STATE_DRIVER)
    {
        new 
vmodel GetVehicleModel(GetPlayerVehicleID(playerid));
        if(
vmodel == 520 && User[playerid][accountVIP] <= 0)
        {
            
RemovePlayerFromVehicle(playerid);
            
SendClientMessage(playerid, -1"I'm sorry, but this car has been reserved for Admins only!");
        }
    }
    return 
1;

Get Player Vehicle ID
You don't need to use GetVehicleModel...

pawn Code:
if(GetPlayerVehicleID(playerid) == 520...
Reply
#7

Quote:
Originally Posted by ConnorW
View Post
Get Player Vehicle ID
You don't need to use GetVehicleModel...

pawn Code:
if(GetPlayerVehicleID(playerid) == 520...
No he is actually correct, he will check if the vehicle is hydra and will remove the player from the vehicle, while you check if the car id is 520 not the model_id and will probably remove only from vehicle id 520 which can be any infernus, nrg, bus etc...
Reply
#8

Quote:
Originally Posted by Kasichok
View Post
No he is actually correct, he will check if the vehicle is hydra and will remove the player from the vehicle, while you check if the car id is 520 not the model_id and will probably remove only from vehicle id 520 which can be any infernus, nrg, bus etc...
what
Reply
#9

Quote:
Originally Posted by ConnorW
View Post
what
Khui Cherez Plecho re-read, You'r script can remove player from non restricted vehicle model
Reply
#10

GetPlayerVehicleID is same as playerid just for vehicles and GetVehicleModel is same as GetPlayerSkin just for vehicles

if you want only the admins to use skin_id 299 which function would you use?

PHP Code:
if(GetPlayerSkin(playerid) == playerid
or

PHP Code:
if(GetPlayerSkin(playerid) == 299
Reply
#11

It's basically the same..
Reply
#12

You don't need to use state change, OnPlayerEnterVehicle is fine.

Simply get their position and set it to current.

pawn Code:
new Float:PosX,
    Float:PosY;
    Float:PosZ;

GetPlayerPos(playerid, PosX, PosY, PosZ);

SetPlayerPos(playerid, PosX, PosY, PosZ);
You could still do it in OnPlayerStateChange aswell for an anti-cheat measure if you'd like.
Reply
#13

"OnPlayerEnterVehicle" is called when a player attempts to enter a vehicle. It doesn't mean that the player is already inside the vehicle. However "OnPlayerEnterVehicle" is not called, if a player ports into a vehicle by calling "PutPlayerInVehicle" or with cheats. The definitive answer to restrict vehicle access is actually to use "OnPlayerStateChange" and also "SetVehicleParamsForPlayer" just for a better user experience. I feel the entire thread just makes my brain loose cells while reading.
Reply
#14

Im trying to restrict every single hydra, how do i lock all hydras ingame and just let them unlocked for VIP Players?
I dont seem to understand it
Reply
#15

Quote:
Originally Posted by alexjanjaj
View Post
Im trying to restrict every single hydra, how do i lock all hydras ingame and just let them unlocked for VIP Players?
I dont seem to understand it
Quote:
Originally Posted by [HLF]Southclaw
View Post
Simply lock the vehicle for that specific player. https://sampwiki.blast.hk/wiki/SetVehicleParamsForPlayer
This combined with OnPlayerEnterVehicle or I'd rather use OnVehicleStreamIn for that, if you're not planning to change constantly the user's VIP level, else it would have some issues returning false positives. Then basically you're going to check if the player is vip, if so do nothing, else execute the code :

Code:
SetVehicleParamsForPlayer(vehicleid, playerid,0,1);
Reply
#16

PHP Code:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
GetVehicleModel(GetPlayerVehicleID(playerid)) == 520 && User[playerid][accountVIP] == 0)
    {
        if(
newstate == || newstate == 2)
        {
            
ClearAnimations(playerid);
            
SendClientMessage(playerid, -1"I'm sorry, but this car has been reserved for Admins only!");
        }
    }
    return 
1;

Reply
#17

Quote:
Originally Posted by Kasichok
View Post
PHP Code:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
User[playerid][accountVIP] == 0) return 1;
    if(
GetVehicleModel(GetPlayerVehicleID(playerid)) == 520)
    {
        if(
newstate == || newstate == 2)
        {
            
ClearAnimations(playerid);
            
SendClientMessage(playerid, -1"I'm sorry, but this car has been reserved for Admins only!");
        }
    }
    return 
1;

yea sure
pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(User[playerid][accountVIP] == 0) return 1;
Reply
#18

Quote:
Originally Posted by ConnorW
View Post
yea sure
pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(User[playerid][accountVIP] == 0) return 1;
fixed.
Reply
#19

Quote:
Originally Posted by Kasichok
View Post
PHP Code:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
GetVehicleModel(GetPlayerVehicleID(playerid)) == 520 && User[playerid][accountVIP] == 0)
    {
        if(
newstate == || newstate == 2)
        {
            
ClearAnimations(playerid);
            
SendClientMessage(playerid, -1"I'm sorry, but this car has been reserved for Admins only!");
        }
    }
    return 
1;

Just tried it, somehow it ends up creating a permanent loop of entering and leaving the vehicle.
Reply
#20

Quote:
Originally Posted by alexjanjaj
View Post
Just tried it, somehow it ends up creating a permanent loop of entering and leaving the vehicle.
Return true after the check? Not sure if it will affect something
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)