Server Sided Wepons -
Snipa - 18.03.2012
Alright, so this will allow you to enjoy your server without the pain of weapon hackers.
What we'll need first is foreach, a fast and easy to use looping system made by ******.
https://sampforum.blast.hk/showthread.php?tid=92679
Add
to the top of your script.
Alright, so under your includes and all, add this:
pawn Код:
new bool:Weapon[MAX_PLAYERS][47];
That'll create a variable (true/false) for every player, for every weapon.
pawn Код:
GivePlayerWeaponEx(playerid,weaponid,ammo)
{
Weapon[playerid][weaponid] = true;
return GivePlayerWeapon(playerid,weaponid,ammo);
}
ResetPlayerWeaponsEx(playerid)
{
for(new i=0;i<47;i++) Weapon[playerid][i] = false;
ResetPlayerWeapons(playerid);
}
Also add this to your script. That will make 2 new functions, one which makes sure the variable is set when the player is given the weapon and the other which makes sure the variable is set to false when weapons need to be reset.
REPLACE ALL INSTANCES OF GivePlayerWeapon AND ResetPlayerWeapon WITH GivePlayerWeaponEx AND ResetPlayerWeaponEx!
Now in your OnPlayerConnect:
pawn Код:
public OnPlayerConnect(playerid)
{
ResetPlayerWeaponsEx(playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
ResetPlayerWeaponsEx(playerid);
return 1;
}
That will set all weapons to false when a player connects and disconnects.
Now, time for a warning/ban code:
Add this:
pawn Код:
public OnGameModeInit()
{
SetTimer("AntiCheat", 1000, 1);
return 1;
}
forward AntiCheat();
public AntiCheat()
{
foreach(Player, i)
{
new weap = GetPlayerWeapon(i);
if(weap != 46 && weap != 40 && weap > 0 && Weapon[i][weap] == false)
{
if(GetPlayerState(i) == 1 || GetPlayerState(i) == 2 || GetPlayerState(i) == 3) {
//Ban or warning code here
}
}
}
return 1;
}
Let me explain, the OnGameModeInit sets a timer to execute the anticheat function every 1000 ms (1 second).
The AntiCheat loops through every player, gets their weapon, and if it's false, it checks their state, so if it's 1, 2, or 3........
Oh, almost forgot! Be sure to give a parachute on spawn or script a workaround. Also for police cars and the caddy.
Euh, if anything's wrong, just tell me..
Re: Server Sided Wepons -
MP2 - 18.03.2012
Forgetting parachutes from planes/helis? You should just leave parachutes out, it's not like they do damage.
Re: Server Sided Wepons -
antonio112 - 18.03.2012
Jeesh, this is exactly what I was looking for. Thanks pal. Now I know how to save weapons too. Hah, nice tutorial. Clean & simple.
Re: Server Sided Wepons -
-Rebel Son- - 18.03.2012
This is creative, Nice work.
Re: Server Sided Wepons -
Max_Coldheart - 18.03.2012
So if someone receives a weapon when he spawns (like in DM servers) would this count as false weapon and ban him, as it isn't given with GivePlayerWeaponEx, but with AddPlayerClass?
Re: Server Sided Wepons -
jameskmonger - 18.03.2012
CookieJar, yes it would. I recommend giving the player no weapons via AddPlayerClass, but giving them upon spawn using the correct anticheat method.
Re: Server Sided Wepons - Nicholas. - 18.03.2012
Nice work, Snipa.
Re: Server Sided Wepons -
Garsino - 18.03.2012
Quote:
Originally Posted by MP2
Forgetting parachutes from planes/helis? You should just leave parachutes out, it's not like they do damage.
|
They do... on unoccupied vehicles
Re: Server Sided Wepons -
jameskmonger - 19.03.2012
Quote:
Originally Posted by Garsino
They do... on unoccupied vehicles ![Tongue](images/smilies/razz.gif)
|
What do they do?
Re: Server Sided Wepons -
Snipa - 19.03.2012
Parachutes can damage unoccupied vehicles
Re: Server Sided Wepons -
jameskmonger - 19.03.2012
Quote:
Originally Posted by Snipa
Parachutes can damage unoccupied vehicles
|
How?
Re: Server Sided Wepons -
Snipa - 19.03.2012
Equip parachute -> punch vehicle -> VIOLA!
Re: Server Sided Wepons -
Tama - 19.03.2012
I'll done add that codes, but when i give / buy a weapons its say "Unknown Commands"
Re: Server Sided Wepons -
jameskmonger - 19.03.2012
Quote:
Originally Posted by Snipa
Equip parachute -> punch vehicle -> VIOLA!
|
Will other players see this damage?
Re: Server Sided Wepons -
Garsino - 19.03.2012
Quote:
Originally Posted by jameskmonger
Will other players see this damage?
|
Yes, and eventually the vehicle will catch on fire and explode too.
Re: Server Sided Wepons -
Niko_boy - 19.03.2012
wow this is very sweet and smooth code
Re: Server Sided Wepons -
.:Kaos:. - 19.03.2012
Goodjob, smooth coding, nice understanding.
Re: Server Sided Wepons -
Scripter12345 - 02.04.2012
If i have a admin command where you can spawn any gun will this still ban me if i spawn a gun and im admin ?
Respuesta: Server Sided Wepons -
Marricio - 03.04.2012
You need to replace every GivePlayerWeapon with GivePlayerWeaponEx
Re: Respuesta: Server Sided Wepons -
Scripter12345 - 03.04.2012
Quote:
Originally Posted by Marricio
You need to replace every GivePlayerWeapon with GivePlayerWeaponEx
|
I think i have my anti weapon hack system done at the moment if i have any problems may i come to you please