[Tutorial] Anti Drive-By
#1

Hi. Today I'm gonna learn you how to protect your server against drive-by. First, open your gamemode and search(CTRL+F) "public OnPlayerDeath". This callback is called everytime someone dies. You must find something like this:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}
We see 3 arguments there :
Код:
    •playerid - the id of the one that just died.
    •killerid - the id of the killer
    •reason - we don't need this now
We will use the IsPlayerInAnyVehicle function to check if the killer was in any vehicle when he killed the player. Like this:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(IsPlayerInAnyVehicle(killerid))
    {
    }
    return 1;
}
Done, now let's do something about that. We will kick the player and inform him about why he's been kicked:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(IsPlayerInAnyVehicle(killerid))
    {
        SendClientMessage(killerid, 0xFF0000FF, "You have been kicked because you killed someone from the car(drive-by)");
        Kick(killerid);
    }
    return 1;
}
Done. If you have any problem just tell me.
Reply
#2

Good tutorial
An alternative way to stop drive bying would be to just SetPlayerArmedWeapon(playerid,0); when they get into the vehicle.
Reply
#3

Quote:
Originally Posted by bensmart469
Посмотреть сообщение
Good tutorial
An alternative way to stop drive bying would be to just SetPlayerArmedWeapon(playerid,0); when they get into the vehicle.
Yes but on some RP servers DB is also when you kill someone by sitting with the car on him. So this function will be useless then.
Reply
#4

Quote:
Originally Posted by bensmart469
Посмотреть сообщение
Good tutorial
An alternative way to stop drive bying would be to just SetPlayerArmedWeapon(playerid,0); when they get into the vehicle.
You say to put SetPlayerWeapon(playeird,0); on
Код:
OnPlayerEnterVehicle
.Let think a little bit.The server will reset player's weapon ONLY WHEN ENTER IN A CAR!!!But,if it enter first in a car,when buy a weapon with a command,the server doesn't reset the player weapon,so,it can do Drive-by!!!

P.S:If I have an gramaticly wrong,soooory,I am Romanian!11
Reply
#5

Change the weapon when his state changes to inside a vehicle instead
Reply
#6

Too much off-topic here...
Reply
#7

You can use OnPlayerTakeDamage for detecting car ramming and just use SetPlayerArmedWeapon to make sure they can't drive-by.
Reply
#8

Won't this fail on car parking?
Reply
#9

Quote:
Originally Posted by Rajat_Pawar
Посмотреть сообщение
Won't this fail on car parking?
Um...why?
Reply
#10

Quote:
Originally Posted by DiGiTaL_AnGeL
Посмотреть сообщение
Um...why?
Player A which is in a vehicle parks his car on player B. While player B's health is draining, player A leaves the vehicle. I don't know if OnPlayerDeath's second parameter is the actual killer or INVALID_PLAYER_ID, but either way it fails because IsPlayerInAnyVehicle(killerid) returns `false`. You might want to use reason 49 (https://sampwiki.blast.hk/wiki/Weapons).

---

Anyway, good tutorial. Very "noob-friendly".
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)