[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


Messages In This Thread
Server Sided Wepons - by Snipa - 18.03.2012, 02:30
Re: Server Sided Wepons - by MP2 - 18.03.2012, 02:38
Re: Server Sided Wepons - by antonio112 - 18.03.2012, 02:58
Re: Server Sided Wepons - by -Rebel Son- - 18.03.2012, 05:23
Re: Server Sided Wepons - by Max_Coldheart - 18.03.2012, 09:01
Re: Server Sided Wepons - by jameskmonger - 18.03.2012, 09:53
Re: Server Sided Wepons - by Nicholas. - 18.03.2012, 14:07
Re: Server Sided Wepons - by Garsino - 18.03.2012, 14:18
Re: Server Sided Wepons - by jameskmonger - 19.03.2012, 01:19
Re: Server Sided Wepons - by Snipa - 19.03.2012, 01:22
Re: Server Sided Wepons - by jameskmonger - 19.03.2012, 01:24
Re: Server Sided Wepons - by Snipa - 19.03.2012, 01:26
Re: Server Sided Wepons - by Tama - 19.03.2012, 04:21
Re: Server Sided Wepons - by jameskmonger - 19.03.2012, 07:05
Re: Server Sided Wepons - by Garsino - 19.03.2012, 07:40
Re: Server Sided Wepons - by Niko_boy - 19.03.2012, 11:42
Re: Server Sided Wepons - by .:Kaos:. - 19.03.2012, 11:52
Re: Server Sided Wepons - by Scripter12345 - 02.04.2012, 20:04
Respuesta: Server Sided Wepons - by Marricio - 03.04.2012, 01:53
Re: Respuesta: Server Sided Wepons - by Scripter12345 - 03.04.2012, 11:48
Re: Server Sided Wepons - by Snipa - 10.04.2012, 12:15
Re: Server Sided Wepons - by nickdodd25 - 21.04.2012, 05:48
Re: Server Sided Wepons - by Passout - 09.07.2013, 19:21
Re: Server Sided Wepons - by Konstantinos - 09.07.2013, 19:41
Re: Server Sided Wepons - by iNoBoDy - 09.07.2013, 23:27
Re: Server Sided Wepons - by Snipa - 28.07.2014, 00:12
Re: Server Sided Wepons - by billy123321 - 27.08.2014, 00:34
Re: Server Sided Wepons - by Snipa - 02.08.2015, 00:40
Re: Server Sided Wepons - by Cypress - 02.08.2015, 08:42
Re: Server Sided Wepons - by MBilal - 02.08.2015, 14:38
Re: Server Sided Wepons - by xVIP3Rx - 02.08.2015, 15:32
Re: Server Sided Wepons - by Jay_ - 02.08.2015, 15:45
Re: Server Sided Wepons - by Abagail - 02.08.2015, 19:04
Re: Server Sided Wepons - by Calgon - 02.08.2015, 19:04

Forum Jump:


Users browsing this thread: 1 Guest(s)