18.10.2014, 15:08
Here's one possible approach:
In order for this code to function without false positives, it will be necessary to prevent players from acquiring weapons using the default ammunition, add your own checkpoint etc.
- Keep track of the weapons that each player has been given by the server using an array of length 13.
- When a player is given a weapon by the server, store the ID of that weapon in their array to indicate that they are supposed to have that gun.
- When a player damages another player, make sure that they are expected to have the weapon they're using.
Код:
#define MAX_PLAYERS 32 //Player capacity of your server
new weapons[MAX_PLAYERS][13]; //Store the weapon each player should have in a specific slot
//Function to give players a weapon
giveGun(playerid, weaponid, ammo)
{
GivePlayerWeapon(playerid, weaponid, ammo);
//Keep track of what weapons the player has
for(new i = 0; i < 13; i++)
{
new temp;
GetPlayerWeaponData(playerid, i, weapons[playerid][i], temp);
}
}
public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid, bodypart)
{
new bool:allowedWeapon = false;
for(new i = 0; i < 13; i++)
{
if(weapons[playerid][i] == weaponid)
{
allowedWeapon = true;
break;
}
}
if(allowedWeapon == false)
{
//We did not expect the player to have this weapon, they must have cheated!
//Do something.
}
return 1;
}

