Team Jacking/ Passenger Abuse
#1

Guys, I have this located at OnPlayerEnterVehicle, which works fine but the problem is with this applied, even with a driver, passengers of the same team are unable to enter as passenger. The team jack is only to work as anti team jacking the driver, but it does not allow for the use of Passengers also (G).

Код:
new id = GetDriverID(vehicleid);  //Anti Team-Jack
    if(IsPlayerInAnyVehicle(id) && !ispassenger && GetPlayerTeam(playerid) == GetPlayerTeam(id))
    {
	   GameTextForPlayer(playerid, "~r~Team Jack is not allowed!", 2100, 3);
	   SetVehicleParamsForPlayer(vehicleid, playerid, false, true);
    }
Another thing, because while I'm at it, how do I add an anti G abuse, where there is no driver, the player can't enter as passenger?

Here is the stock details:
Код:
stock GetDriverID(vehicleid)
{
    for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i)) 
    {
        if(GetPlayerVehicleID(i) == vehicleid && GetPlayerState(i) == PLAYER_STATE_DRIVER) return i;
    }
    return 1;
}
+REP to those who help me in this endeavour. Thank you.
Reply
#2

try
Код:
if(IsPlayerInAnyVehicle(id) && GetPlayerTeam(playerid) == GetPlayerTeam(id))
    {
	   if(!ispassenger)
	{
           GameTextForPlayer(playerid, "~r~Team Jack is not allowed!", 2100, 3);
	   SetVehicleParamsForPlayer(vehicleid, playerid, false, true);
         }
    }
or
Код:
if(IsPlayerInAnyVehicle(id) && GetPlayerTeam(playerid) == GetPlayerTeam(id))
    {
	   if(ispassenger)
	{
           return 1;
         }
        else
        {
         GameTextForPlayer(playerid, "~r~Team Jack is not allowed!", 2100, 3);
	   SetVehicleParamsForPlayer(vehicleid, playerid, false, true);
         }
    }
Reply
#3

I haven't tried it with someone, although it compiled. But does this include the Anti "G" abuse too? Passenger drive by abuse?
Reply
#4

I suggest you to use ClearAnimations instead of SetVehicleParamsForPlayer (or both). If the door is damaged or open for the client, the player might still be able to enter the vehicle.

Another advantage of ClearAnimations is that any animations will be interupted for other players too.
It can happen that if you press F and then break the animation with WASD (so you actually don't enter the vehicle), other players will still see you jacking the car (including the driver who then gets kicked out of the car even tho the entering player actually didn't enter).

This is rather a rare case and mostly the params work well, but ClearAnimations or SetPlayerPos is the best way of doing it. Just saying if you want to make sure.


For anti G abuse you can use a loop to check if any player is the driver of that vehicle. If no driver is found, do the same as you do for anti-car-jack.

Код:
new bool:driver = false;
for(new i = 0; i < MAX_PLAYERS; i ++) // If you use foreach, use that instead of a for loop
{
	if(GetPlayerVehicleID(i) != vehicleid || GetPlayerState(i) != PLAYER_STATE_DRIVER) continue;
	
	driver = true;
	break;
}

if(!driver) // No driver found for that vehicle
{
	// Do stuff to prevent vehicle entering
}
You can also do a similar thing in OnPlayerStateChange to check if there are passengers left in a vehicle when a driver leaves a vehicle.
Reply
#5

That's if you're more specific to a certain weapon.

Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_PASSENGER)
    {
        if(GetPlayerWeapon(playerid) == 24) //Deagle
        {
        SetPlayerArmedWeapon(playerid,0);
        }
    }
    return 1;
}
Reply
#6

@NaS, I tried your code, and I used ClearAnimations(playerid);, but I seem to have another problem, at first the passenger's could not enter without a driver. But they even can't enter as a driver. Its like I disable driving in this game. Hahaha. How do I fix it?
Reply
#7

Quote:
Originally Posted by Sting.
Посмотреть сообщение
@NaS, I tried your code, and I used ClearAnimations(playerid);, but I seem to have another problem, at first the passenger's could not enter without a driver. But they even can't enter as a driver. Its like I disable driving in this game. Hahaha. How do I fix it?
If you mean they can't enter the car that means you're locking it by using setvehicleparams/ex/forplayer so check that in your code and remove it, also i'd advise onplayerstatechange to check for the player entering if newstate is passenger or driver, goodluck.
Reply
#8

Quote:
Originally Posted by Sting.
Посмотреть сообщение
@NaS, I tried your code, and I used ClearAnimations(playerid);, but I seem to have another problem, at first the passenger's could not enter without a driver. But they even can't enter as a driver. Its like I disable driving in this game. Hahaha. How do I fix it?
Make sure the code I posted is only executed in OnPlayerEnterVehicle if the player tries to enter as passenger, if the player enters as driver you should unlock the vehicle using SetVehicleParamsForPlayer.
You could (for testing) leave away the params and only work with ClearAnimations to see if the code runs in the right situations, or if the vehicle was just locked.
Reply
#9

Quote:
Originally Posted by NaS
Посмотреть сообщение
Make sure the code I posted is only executed in OnPlayerEnterVehicle if the player tries to enter as passenger, if the player enters as driver you should unlock the vehicle using SetVehicleParamsForPlayer.
You could (for testing) leave away the params and only work with ClearAnimations to see if the code runs in the right situations, or if the vehicle was just locked.
Yes, I entered it at OnPlayerEnterVehicle, exactly like how you put it,

Код:
new bool:driver = false;  //Anti 'G' Abuse
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
	if(GetPlayerVehicleID(i) != vehicleid || GetPlayerState(i) != PLAYER_STATE_DRIVER) continue;

	driver = true;
	break;
    }
    if(!driver) // No driver found for that vehicle
	{
	  ClearAnimations(playerid);
    }
Reply
#10

Quote:
Originally Posted by Sting.
Посмотреть сообщение
Yes, I entered it at OnPlayerEnterVehicle, exactly like how you put it,

Код:
new bool:driver = false;  //Anti 'G' Abuse
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
	if(GetPlayerVehicleID(i) != vehicleid || GetPlayerState(i) != PLAYER_STATE_DRIVER) continue;

	driver = true;
	break;
    }
    if(!driver) // No driver found for that vehicle
	{
	  ClearAnimations(playerid);
    }
It looks like you didn't check if the player is entering as passenger. Without that, an empty vehicle cannot be entered even as driver (what you described before).

So you need to add a check for ispassenger.

Since you also want to prevent team car jacking, you could also use this code to determine if the driver of the car is on the same team (with a little modification):

Код:
    new driver = -1;  //Anti 'G' Abuse
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
	if(GetPlayerVehicleID(i) != vehicleid || GetPlayerState(i) != PLAYER_STATE_DRIVER) continue;

	driver = i;
	break;
    }
    if(driver == -1 && ispassenger) // No driver found for that vehicle, player is trying to enter as passenger - prevent that
    {
	  ClearAnimations(playerid);
    }
    else if(driver != -1 && !ispassenger && GetPlayerTeam(driver) == GetPlayerTeam(playerid)) // player tries to enter as driver but the vehicle already has a driver which is on the same team - don't allow it
    {
        ClearAnimations(playerid);
    }
Hope that fixes both issues, it should now prevent team car jacking and G abuse.

EDIT: Okay, RogueDrifter was faster

Although, his code will not allow players to enter a vehicle as passenger if the vehicle is driven by someone of the same team.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)