29.12.2016, 14:23
Hello.
I am experiencing unexpected weapon hack warnings from a system that I scripted. It is using variables for all 13 weapon slots.
This is where the weapons are given:
This is located under my 1 second timer right now because of testing, I can use it under OnPlayerUpdate too with checking if the player's current weapon is different to his last one:
^^ I have tried using if and else if here too for checking each slot and each weapon. Still the same problem. I found out using a loop is the same but a lot shorter and not complicated.
This isn't that important but here you go:
An example where the unexpected warning gets triggered is the tazer, givegun, takeguns and weapon pickups:
This is the remove player weapon function:
And the resetplayerweaponsex:
Anyone have an idea why this is happening? Please help me down below. Thank you
I am experiencing unexpected weapon hack warnings from a system that I scripted. It is using variables for all 13 weapon slots.
This is where the weapons are given:
PHP Code:
stock GivePlayerValidWeapon(playerid, weaponid, ammo)
{
switch(weaponid)
{
case 0, 1:
{
PlayerInfo[playerid][pGuns][0] = weaponid;
GivePlayerWeapon(playerid, weaponid, ammo);
}
case 2 .. 9:
{
PlayerInfo[playerid][pGuns][1] = weaponid;
GivePlayerWeapon(playerid, weaponid, ammo);
}
case 22, 23, 24:
{
PlayerInfo[playerid][pGuns][2] = weaponid;
GivePlayerWeapon(playerid, weaponid, ammo);
}
case 25, 26, 27:
{
PlayerInfo[playerid][pGuns][3] = weaponid;
GivePlayerWeapon(playerid, weaponid, ammo);
}
case 28, 29, 32:
{
PlayerInfo[playerid][pGuns][4] = weaponid;
GivePlayerWeapon(playerid, weaponid, ammo);
}
case 30, 31:
{
PlayerInfo[playerid][pGuns][5] = weaponid;
GivePlayerWeapon(playerid, weaponid, ammo);
}
case 33, 34:
{
PlayerInfo[playerid][pGuns][6] = weaponid;
GivePlayerWeapon(playerid, weaponid, ammo);
}
case 35 .. 38:
{
PlayerInfo[playerid][pGuns][7] = weaponid;
GivePlayerWeapon(playerid, weaponid, ammo);
}
case 16, 17, 18, 39:
{
PlayerInfo[playerid][pGuns][8] = weaponid;
GivePlayerWeapon(playerid, weaponid, ammo);
}
case 41, 42, 43:
{
PlayerInfo[playerid][pGuns][9] = weaponid;
GivePlayerWeapon(playerid, weaponid, ammo);
}
case 10 .. 15:
{
PlayerInfo[playerid][pGuns][10] = weaponid;
GivePlayerWeapon(playerid, weaponid, ammo);
}
case 44, 45, 46:
{
PlayerInfo[playerid][pGuns][11] = weaponid;
GivePlayerWeapon(playerid, weaponid, ammo);
}
case 40:
{
PlayerInfo[playerid][pGuns][12] = weaponid;
GivePlayerWeapon(playerid, weaponid, ammo);
}
}
return 1;
}
PHP Code:
new weapon[13], ammo[13];
for(new w=0; w < 13; w++)
{
GetPlayerWeaponData(i, w, weapon[w], ammo[w]);
if(weapon[w] != PlayerInfo[i][pGuns][w] && weapon[w] != 0)
{
ExecuteHackerAction(i, weapon[w]);
}
}
This isn't that important but here you go:
PHP Code:
stock ExecuteHackerAction(playerid, weaponid)
{
new string[144];
format(string,sizeof(string)," ** AdmWarning: {FFFF00}%s (ID %d) is possibly weapon hacking %s (ID %d)", GetName(playerid), playerid, GetGunName(weaponid), weaponid);
ABroadcast(COLORRED, string, 1);
format(string,sizeof(string),"Possible weapon hack (%s)",GetGunName(weaponid));
AddAutomatedFlag(playerid, string);
format(string,sizeof(string),"%s has possibly weapon hacked %s (ID %s)", GetName(playerid), GetGunName(weaponid), weaponid);
Log("logs/hacks.txt", string);
return 1;
}
PHP Code:
if(PlayerState[playerid][pTazer] == 0)
{
GetPlayerWeaponData(playerid, 2, tazerlastweapons[0][playerid], tazerlastweapons[1][playerid]);
if(PlayerInfo[playerid][pGuns][2]) RemovePlayerWeapon(playerid, PlayerInfo[playerid][pGuns][2]);
PlayerState[playerid][pTazer] = 1;
format(msg,sizeof(msg)," * %s unholsters their tazer.", GetName(playerid));
ProxDetector(20.0, playerid, msg, COLORRP);
GivePlayerValidWeapon(playerid, 23, 60000);
}
else
{
RemovePlayerWeapon(playerid, 23);
GivePlayerValidWeapon(playerid, tazerlastweapons[0][playerid], tazerlastweapons[1][playerid]);
PlayerInfo[playerid][pGuns][2] = tazerlastweapons[0][playerid];
PlayerState[playerid][pTazer] = 0;
format(msg,sizeof(msg)," * %s holsters their tazer.", GetName(playerid));
ProxDetector(20.0, playerid, msg, COLORRP);
}
PHP Code:
CMD:givegun(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] >= 3)
{
new targetid, gun, ammo;
new msg[144];
if(PlayerInfo[playerid][pAdminDuty] == 0 && PlayerInfo[playerid][pAdmin] < 4) return SendMessage(playerid, COLORERROR,"AdmCmd: You must be on duty to do this. (/aduty)");
if(sscanf(params,"uii", targetid, gun, ammo)) return SendMessage(playerid, -1,"USAGE: /givegun <playerid/partofname> <weaponid> <ammo>");
if(targetid == INVALID_PLAYER_ID) return SendMessage(playerid,COLORERROR,"AdmCmd: That player is not connected.");
if(InDuel[targetid]) return SendMessage(playerid,COLORERROR,"AdmCmd: That player is currently in a duel, try again later.");
if(PlayerState[targetid][pPrisoned] == 1 || PlayerState[targetid][pAdmJail] == 1) return SendMessage(playerid,COLORERROR,"AdmCmd: That player is currently in jail, try again later.");
if(IsPlayerNPC(targetid)) return SendMessage(playerid,COLORERROR,"AdmCmd: You can't give weapons to an NPC.");
if(gun > 46 || gun < 1) return SendMessage(playerid, -1,"{00FFFF}AdmCmd:{FFFFFF} Valid weapon IDs: 1 - 46");
if(ammo > 99999 || ammo < 1) return SendMessage(playerid, -1,"{00FFFF}AdmCmd:{FFFFFF} Valid ammo: 1 - 99999");
GivePlayerValidWeapon(targetid, gun, ammo);
format(msg,sizeof(msg)," *** AdmCmd:{FFFFFF} You have given a(n) %s (ID %d) with %d ammo to %s.", GetGunName(gun), gun, ammo, GetName(targetid));
SendMessage(playerid, COLORAL, msg);
format(msg,sizeof(msg),"Admin %s has given you a(n) %s (ID %d) with %d ammo.", GetName(playerid), GetGunName(gun), gun, ammo);
SendMessage(targetid, COLORWHITE, msg);
format(msg,sizeof(msg),"[GIVEGUN] %s has given %s a(n) %s (ID %d) with %d ammo", GetName(playerid), GetName(targetid), GetGunName(gun), gun, ammo);
Log("logs/admin.txt", msg);
ABroadcast(COLORLIGHTRED, msg, 4);
} else return SendMessage(playerid, COLORERROR, "You must be atleast a Head Admin to use this!");
return 1;
}
PHP Code:
CMD:takeguns(playerid,params[])
{
new targetid;
new msg[144];
if(PlayerInfo[playerid][pAdmin] >= 2)
{
if(PlayerInfo[playerid][pAdminDuty] == 0 && PlayerInfo[playerid][pAdmin] < 4) return SendMessage(playerid, COLORERROR,"AdmCmd: You must be on duty to do this. (/aduty)");
if(sscanf(params,"u",targetid)) return SendMessage(playerid,COLORWHITE,"{00FFFF}AdmCmd:{FFFFFF} /takeguns <playerid/partofname>");
if(targetid == INVALID_PLAYER_ID) return SendMessage(playerid,COLORERROR,"AdmCmd: That player is not connected.");
if(PlayerInfo[targetid][pAdminDuty] == 1 && PlayerInfo[playerid][pAdmin] != 4) return SendMessage(playerid, COLORERROR,"AdmCmd: You can't do this to an on duty admin.");
if(InDuel[targetid]) return SendMessage(playerid,COLORERROR,"AdmCmd: That player is currently in a duel, try again later.");
if(PlayerInfo[targetid][pHunted] == 1) return SendMessage(playerid,COLORERROR,"AdmCmd: That player is currently hunted, try again later.");
if(IsPlayerNPC(targetid)) return SendMessage(playerid,COLORERROR,"AdmCmd: You can't take away guns from NPCs.");
ResetPlayerWeaponsEx(targetid);
format(msg, sizeof(msg), " *** AdmCmd:{FFFFFF} You have taken away %s's weapons.", GetName(targetid));
SendMessage(playerid, COLORAL, msg);
format(msg, sizeof(msg), "Admin %s has taken away your weapons.", GetName(playerid));
SendMessage(targetid, COLORERROR, msg);
format(msg,sizeof(msg),"[TAKEGUNS] %s has taken away %s's weapons", GetName(playerid), GetName(targetid));
Log("logs/admin.txt", msg);
ABroadcast(COLORLIGHTRED, msg, 4);
} else return SendMessage(playerid, COLORERROR, "You must be atleast a Lead Admin to use this!");
return 1;
}
PHP Code:
for(new i = 0; i < MAX_GUNDROP; i++)
{
if(pickupid == WeaponDrop[i][dPickup] && WeaponDrop[i][dWeapon] > 0)
{
for(new w=0;w<12;w++)
{
GetPlayerWeaponData(playerid, w, weapon, ammo);
if((WeaponDrop[i][dWeapon] == WEAPON_DEAGLE && PlayerState[playerid][pTazer] == 1) ||
(WeaponDrop[i][dWeapon] == WEAPON_SHOTGUN && weapon == WEAPON_SHOTGSPA) ||
(WeaponDrop[i][dWeapon] == WEAPON_SHOTGUN && weapon == WEAPON_SAWEDOFF) ||
(WeaponDrop[i][dWeapon] == WEAPON_SHOTGSPA && weapon == WEAPON_SHOTGUN) ||
(WeaponDrop[i][dWeapon] == WEAPON_SHOTGSPA && weapon == WEAPON_SAWEDOFF) ||
(WeaponDrop[i][dWeapon] == WEAPON_SAWEDOFF && weapon == WEAPON_SHOTGUN) ||
(WeaponDrop[i][dWeapon] == WEAPON_SAWEDOFF && weapon == WEAPON_SHOTGSPA) ||
(WeaponDrop[i][dWeapon] == WEAPON_AK47 && weapon == WEAPON_M4) ||
(WeaponDrop[i][dWeapon] == WEAPON_M4 && weapon == WEAPON_AK47) ||
(WeaponDrop[i][dWeapon] == WEAPON_UZI && weapon == WEAPON_MP5) ||
(WeaponDrop[i][dWeapon] == WEAPON_UZI && weapon == WEAPON_TEC9) ||
(WeaponDrop[i][dWeapon] == WEAPON_TEC9 && weapon == WEAPON_MP5) ||
(WeaponDrop[i][dWeapon] == WEAPON_TEC9 && weapon == WEAPON_UZI) ||
(WeaponDrop[i][dWeapon] == WEAPON_MP5 && weapon == WEAPON_UZI) ||
(WeaponDrop[i][dWeapon] == WEAPON_MP5 && weapon == WEAPON_TEC9) ||
(WeaponDrop[i][dWeapon] == WEAPON_SNIPER && weapon == WEAPON_RIFLE) ||
(WeaponDrop[i][dWeapon] == WEAPON_RIFLE && weapon == WEAPON_SNIPER) ||
(WeaponDrop[i][dWeapon] == WEAPON_GRENADE && weapon == WEAPON_TEARGAS) ||
(WeaponDrop[i][dWeapon] == WEAPON_GRENADE && weapon == WEAPON_MOLTOV) ||
(WeaponDrop[i][dWeapon] == WEAPON_MOLTOV && weapon == WEAPON_GRENADE) ||
(WeaponDrop[i][dWeapon] == WEAPON_MOLTOV && weapon == WEAPON_TEARGAS) ||
(WeaponDrop[i][dWeapon] == WEAPON_TEARGAS && weapon == WEAPON_MOLTOV) ||
(WeaponDrop[i][dWeapon] == WEAPON_TEARGAS && weapon == WEAPON_GRENADE))
{
SendMessage(playerid, COLORERROR, "You already have a similar weapon to this one. Use /dropgun.");
return 1;
}
}
GivePlayerValidWeapon(playerid, WeaponDrop[i][dWeapon], WeaponDrop[i][dAmmo]);
DestroyPickup(WeaponDrop[i][dPickup]);
WeaponDrop[i][dWeapon] = 0;
WeaponDrop[i][dSpawnedTime] = 0;
WeaponDrop[i][dAmmo] = 0;
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
}
}
PHP Code:
stock RemovePlayerWeapon(playerid, weaponid)
{
new plyWeapons[13][2];
for(new s = 0; s < 13; s++)
{
new wep, ammo;
GetPlayerWeaponData(playerid, s, wep, ammo);
if(wep != weaponid)
{
GetPlayerWeaponData(playerid, s, plyWeapons[s][0], plyWeapons[s][1]);
}
else
{
PlayerInfo[playerid][pGuns][s] = 0;
}
}
ResetPlayerWeaponsEx(playerid);
for(new s = 0; s < 13; s++)
{
GivePlayerValidWeapon(playerid, plyWeapons[s][0], plyWeapons[s][1]);
}
return 1;
}
PHP Code:
stock ResetPlayerWeaponsEx(playerid)
{
ResetPlayerWeapons(playerid);
for(new i = 0; i < 13; i++)
{
PlayerInfo[playerid][pGuns][i] = 0;
}
return 1;
}