How can i restrict players from entering a specific vehicle? -
alexjanjaj - 17.02.2019
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.
Re: How can i restrict players from entering a specific vehicle? -
rockys - 17.02.2019
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
Re: How can i restrict players from entering a specific vehicle? -
The King's Bastard - 17.02.2019
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.
Re: How can i restrict players from entering a specific vehicle? -
Undef1ned - 17.02.2019
PHP Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
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;
}
Re: How can i restrict players from entering a specific vehicle? -
SymonClash - 17.02.2019
Quote:
Originally Posted by The King's Bastard
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.
Re: How can i restrict players from entering a specific vehicle? -
d3Pedro - 18.02.2019
Quote:
Originally Posted by Undef1ned
PHP Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
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...
Re: How can i restrict players from entering a specific vehicle? -
Kasichok - 18.02.2019
Quote:
Originally Posted by ConnorW
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...
Re: How can i restrict players from entering a specific vehicle? -
d3Pedro - 18.02.2019
Quote:
Originally Posted by Kasichok
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
Re: How can i restrict players from entering a specific vehicle? -
Kasichok - 18.02.2019
Quote:
Originally Posted by ConnorW
what
|
Khui Cherez Plecho re-read, You'r script can remove player from non restricted vehicle model
Re: How can i restrict players from entering a specific vehicle? -
Kasichok - 18.02.2019
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)
Re: How can i restrict players from entering a specific vehicle? -
d3Pedro - 18.02.2019
It's basically the same..
Re: How can i restrict players from entering a specific vehicle? -
Kane - 18.02.2019
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.
Re: How can i restrict players from entering a specific vehicle? -
BigETI - 18.02.2019
"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.
Re: How can i restrict players from entering a specific vehicle? -
alexjanjaj - 18.02.2019
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
Re: How can i restrict players from entering a specific vehicle? -
TheToretto - 18.02.2019
Quote:
Originally Posted by alexjanjaj
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
|
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);
Re: How can i restrict players from entering a specific vehicle? -
Kasichok - 18.02.2019
PHP Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 520 && User[playerid][accountVIP] == 0)
{
if(newstate == 3 || newstate == 2)
{
ClearAnimations(playerid);
SendClientMessage(playerid, -1, "I'm sorry, but this car has been reserved for Admins only!");
}
}
return 1;
}
Re: How can i restrict players from entering a specific vehicle? -
d3Pedro - 18.02.2019
Quote:
Originally Posted by Kasichok
PHP Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(User[playerid][accountVIP] == 0) return 1;
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 520)
{
if(newstate == 3 || 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;
Re: How can i restrict players from entering a specific vehicle? -
Kasichok - 18.02.2019
Quote:
Originally Posted by ConnorW
yea sure
pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate) { if(User[playerid][accountVIP] == 0) return 1;
|
fixed.
Re: How can i restrict players from entering a specific vehicle? -
alexjanjaj - 18.02.2019
Quote:
Originally Posted by Kasichok
PHP Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 520 && User[playerid][accountVIP] == 0)
{
if(newstate == 3 || 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.
Re: How can i restrict players from entering a specific vehicle? -
TheToretto - 18.02.2019
Quote:
Originally Posted by alexjanjaj
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