Anti Drive-By -
DiGiTaL_AnGeL - 05.03.2013
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.
Re: Anti Drive-By -
bensmart469 - 05.03.2013
Good tutorial
An alternative way to stop drive bying would be to just SetPlayerArmedWeapon(playerid,0); when they get into the vehicle.
Re: Anti Drive-By -
DiGiTaL_AnGeL - 05.03.2013
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.
Re: Anti Drive-By -
burnfire - 05.03.2013
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
Re: Anti Drive-By -
Johndaonee - 05.03.2013
Change the weapon when his state changes to inside a vehicle instead
Re: Anti Drive-By -
DiGiTaL_AnGeL - 05.03.2013
Too much off-topic here...
Re: Anti Drive-By -
SuperViper - 06.03.2013
You can use
OnPlayerTakeDamage for detecting car ramming and just use
SetPlayerArmedWeapon to make sure they can't drive-by.
Re: Anti Drive-By -
RajatPawar - 06.03.2013
Won't this fail on car parking?
Re: Anti Drive-By -
DiGiTaL_AnGeL - 06.03.2013
Quote:
Originally Posted by Rajat_Pawar
Won't this fail on car parking?
|
Um...why?
Re: Anti Drive-By -
Dan.. - 17.03.2013
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".