Serverside for weapons
#1

I started o make anti-cheat and i don`t have ideea how to make that serverside for weapons, anybody can help me with informations ?
Reply
#2

Quote:
Originally Posted by jamal1992
Посмотреть сообщение
I started o make anti-cheat and i don`t have ideea how to make that serverside for weapons, anybody can help me with informations ?
Simple example:
PHP код:
// Init checker for players
static bool:cheater[MAX_PLAYER_NAME];
stock GivePlayerValidWeapon(playeridweaponidammo) {    
     new 
         
str[16]
     ;
     
format(strsizeof(str), "WEAPON%d"weaponid);
     
SetPVarInt(playeridstrweaponid);
     
format(strsizeof(str), "AMMO%d"weaponid);
     
SetPVarInt(playeridstrGetrPVarInt(playeridstr) + ammo);
     
GivePlayerWeapon(playeridweaponidammo);   
}
stock GetPlayerValidAmmo(playerid) {
     new 
weaponid GetPlayerWeapon(playerid);
     if (!
weaponid) return 0;
     new 
         
str[16]
     ;
     
format(strsizeof(str), "AMMO%d"weaponid);
     return 
GetPVarInt(playeridstr);
}
stock GetPlayerValidWeapon(playerid) {
     new 
weaponid GetPlayerWeapon(playerid);
     if (!
weaponid) return 0;
     new 
         
str[16]
     ;
     
format(strsizeof(str), "WEAPON%d"weaponid);
     return 
GetPVarInt(playeridstr);
}
stock ResetPlayerValidWeapon(playerid) {
     new 
         
str[16]
     ;
     for (new 
i47i++) {
         
format(strsizeof(str), "AMMO%d"i);
         
DeletePVar(playeridstr);
         
format(strsizeof(str), "WEAPON%d"i);
         
DeletePVar(playeridstr);
     }
}
forward KickPlayer(playerid);
public 
KickPlayer(playerid) {
     
Kick(playerid);
     return 
true;
}
public 
OnPlayerSpawn(playerid) {
     
GivePlayerValidWeapon(playerid31200); // Give M4 ammo x200
     
return true;
}
public 
OnPlayerDisconnect(playeridreason) {
     
ResetPlayerValidWeapon(playerid); // Reset all weapons
     
cheater[playerid] = false;
     return 
true;
}
public 
OnPlayerUpdate(playerid) {
     if (
GetPlayerValidWeapon(playerid) != GetPlayerWeapon(playerid) && !cheater[playerid]) { // Cheсk hack weapon
           
new
                
msg[256],
                
name[MAX_PLAYER_NAME],
                
weapon[24]
           ;
           
GetPlayerName(playeridnamesizeof(name));
           
GetWeaponName(GetPlayerWeapon(playerid), weaponsizeof(weapon));
           
format(msgsizeof(msg), "Srever: %s(%d) has kicked for WeaponHack %s"nameplayeridweapon);
           
SendClientMessageToAll(-1msg);
           
SetTimerEx("KickPlayer"2000"i"playerid); // Kick cheater
           
cheater[playerid] = true;
     }
     return 
true;

Reply
#3

PVars are way too slow, especially if coupled with format and OnPlayerUpdate. I'd rather use an array like:
pawn Код:
gPlayerWeaponData[MAX_PLAYERS][47]
And then use something like:
pawn Код:
SafeGivePlayerWeapon(playerid, weaponid, ammo)
{
    gPlayerWeaponData[playerid][weaponid] = ammo;
    return GivePlayerWeapon(playerid, weaponid, ammo);
}
Next, check the example for OnPlayerWeaponChange on the wiki page of OnPlayerUpdate (which regrettably also uses PVars, but that aside). If the player changes to a weapon for which he has no ammo then the weapon is being hacked in. Take note to exclude parachutes and detonators as these are given automatically by the game.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
PVars are way too slow, especially if coupled with format and OnPlayerUpdate. I'd rather use an array like:
pawn Код:
gPlayerWeaponData[MAX_PLAYERS][47]
And then use something like:
pawn Код:
SafeGivePlayerWeapon(playerid, weaponid, ammo)
{
    gPlayerWeaponData[playerid][weaponid] = ammo;
    return GivePlayerWeapon(playerid, weaponid, ammo);
}
Next, check the example for OnPlayerWeaponChange on the wiki page of OnPlayerUpdate (which regrettably also uses PVars, but that aside). If the player changes to a weapon for which he has no ammo then the weapon is being hacked in. Take note to exclude parachutes and detonators as these are given automatically by the game.
In this case, the speed is not so important. In addition, they global and I can use these functions filterscripts

If you use an array, then the function GivePlayerValidWeapon
It will not be accessible from filterscript.
Reply
#5

For example, I have a script that gives a weapon, and I have it saved as filterscript

If I try to do

GivePlayerValidWeapon(playerid, 31, 20);

What I did not keep my arms. That's why I gave the example is to PVars
Reply
#6

Next, check the example for OnPlayerWeaponChange on the wiki page of OnPlayerUpdate (which regrettably also uses PVars, but that aside). If the player changes to a weapon for which he has no ammo then the weapon is being hacked in. Take note to exclude parachutes and detonators as these are given automatically by the game.

PS: I have a standard example of a wiki is not use for a long time because I know it
Reply
#7

Quote:
Originally Posted by Vince
Посмотреть сообщение
PVars are way too slow, especially if coupled with format and OnPlayerUpdate. I'd rather use an array like:
pawn Код:
gPlayerWeaponData[MAX_PLAYERS][47]
And then use something like:
pawn Код:
SafeGivePlayerWeapon(playerid, weaponid, ammo)
{
    gPlayerWeaponData[playerid][weaponid] = ammo;
    return GivePlayerWeapon(playerid, weaponid, ammo);
}
Next, check the example for OnPlayerWeaponChange on the wiki page of OnPlayerUpdate (which regrettably also uses PVars, but that aside). If the player changes to a weapon for which he has no ammo then the weapon is being hacked in. Take note to exclude parachutes and detonators as these are given automatically by the game.
I make something like you tell me, thanks a lot !
Reply
#8

Is bugged on 'WEAPON_SATCHEL' after place the bomb an get detonater.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)