[FilterScript] Prevent AFK Drivers Bug
#1

There is a SA-MP bug, that when someone goes AFK in a vehicle, and a player who does not have them streamed in comes and gets in the car.

So when the other player is back from AFK, both players are driving the same vehicle ID, but different vehicles localy

While making my anti cheat system I saw that without preventing this bug, vehicle health cheat systems would be spammed and ban innocent players. Other hacks such as the CLEO cheats that make people very quickly be a vehicle driver to move the vehicle are also prevented by this system.

This can be both a Filter script or a game mode, as the only code used goes into OnPlayerUpdate

pawn Код:
#include <a_samp>

public OnFilterScriptInit() {
    print("AFK Driver Protection Started");
    return 1;
}
public OnFilterScriptExit() {
    print("AFK Driver Protection Stopped");
    return 1;
}
public OnPlayerUpdate(playerid) {
    new playerState=GetPlayerState(playerid);
    if (playerState == PLAYER_STATE_DRIVER) {
        new vehicleid = GetPlayerVehicleID(playerid);
        if (vehicleid>0) {
            for (new plid=0; plid<MAX_PLAYERS; plid++) {
                if (plid!=playerid) {
                    if (IsPlayerConnected(plid)) {
                        if(!IsPlayerNPC(plid)) {
                            if (GetPlayerState(plid)==PLAYER_STATE_DRIVER) {
                                if (GetPlayerVehicleID(plid)==vehicleid) {
                                    kick = true;
                                    RemovePlayerFromVehicle(plid);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (kick) RemovePlayerFromVehicle(playerid);
    return 1;
}
Hopefully I have posted this in the right section, correct me if im wrong, Thanks.
Reply
#2

What is with vehicleid 0 ?

if (vehicleid>0) {
should be:
if(vehicleid != INVALID_VEHICLE_ID)
Reply
#3

I agree with Nanory, if(vehicleid != INVALID_VEHICLE_ID) is the appropriate code to check if the vehicle is valid.
Reply
#4

I dont get it, what is this?
Reply
#5

Good work dude! Simple but nice and useful.
Reply
#6

useful ,
i too developed a code for such abuser/lamer(s)
Reply
#7

Quote:
Originally Posted by Littlehelper[MDZ]
Посмотреть сообщение
I dont get it, what is this?
As he stated in his topic:

Quote:
There is a SA-MP bug, that when someone goes AFK in a vehicle, and a player who does not have them streamed in comes and gets in the car, then the other player is back from AFK, both players are driving the same vehicle ID, but different vehicles locally.
Reply
#8

Nice work man, Simple but it's good.
Reply
#9

Quote:
Originally Posted by Nanory
Посмотреть сообщение
What is with vehicleid 0 ?

if (vehicleid>0) {
should be:
if(vehicleid != INVALID_VEHICLE_ID)
In my opinion both ways are valid.
INVALID_VEHICLE_ID is 65535, I think.
Vehicles ids start from 1, try make a command to teleport to vehicle with ID 1000 just having 5 vehicles in your server and checking if the typed id isn't the same as INVALID_VEHICLE_ID. For example:
pawn Код:
COMMAND:gotoveh(playerid, params[])
{
    new veh_id;
    if(sscanf(params,"d",veh_id)) return 1;
    if(veh_id != INVALID_VEHICLE_ID)
    {
         //Teleport
    } else { SendClientMessage(playerid,-1,"You won't get this message never"); }
    return 1;
}
_______________________
Good idea, and good job.
As they say, I think the looping form isn't the best.

Best regards!
Reply
#10

Quote:
Originally Posted by Nanory
Посмотреть сообщение
What is with vehicleid 0 ?

if (vehicleid>0) {
should be:
if(vehicleid != INVALID_VEHICLE_ID)
That won't work because INVALID_VEHICLE_ID is 0xFFFF. However GetPlayerVehicleID returns 0 if the player is not inside a vehicle. So if you were to check if the result is INVALID_VEHICLE_ID you'd always loop through the players even if they are not in a vehicle.

EDIT:

What you however could have mentioned is that if the state of the player is "PLAYER_STATE_DRIVER" he MUST be inside of a vehicle so how could it return 0?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)