[Tutorial] Server Sided Wepons
#1

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
pawn Код:
#include <foreach>
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..
Reply
#2

Forgetting parachutes from planes/helis? You should just leave parachutes out, it's not like they do damage.
Reply
#3

Jeesh, this is exactly what I was looking for. Thanks pal. Now I know how to save weapons too. Hah, nice tutorial. Clean & simple.
Reply
#4

This is creative, Nice work.
Reply
#5

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?
Reply
#6

CookieJar, yes it would. I recommend giving the player no weapons via AddPlayerClass, but giving them upon spawn using the correct anticheat method.
Reply
#7

Nice work, Snipa.
Reply
#8

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
Reply
#9

Quote:
Originally Posted by Garsino
Посмотреть сообщение
They do... on unoccupied vehicles
What do they do?
Reply
#10

Parachutes can damage unoccupied vehicles
Reply
#11

Quote:
Originally Posted by Snipa
Посмотреть сообщение
Parachutes can damage unoccupied vehicles
How?
Reply
#12

Equip parachute -> punch vehicle -> VIOLA!
Reply
#13

I'll done add that codes, but when i give / buy a weapons its say "Unknown Commands"
Reply
#14

Quote:
Originally Posted by Snipa
Посмотреть сообщение
Equip parachute -> punch vehicle -> VIOLA!
Will other players see this damage?
Reply
#15

Quote:
Originally Posted by jameskmonger
Посмотреть сообщение
Will other players see this damage?
Yes, and eventually the vehicle will catch on fire and explode too.
Reply
#16

wow this is very sweet and smooth code
Reply
#17

Goodjob, smooth coding, nice understanding.
Reply
#18

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 ?
Reply
#19

You need to replace every GivePlayerWeapon with GivePlayerWeaponEx
Reply
#20

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)