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;
}
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]);
}
}
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;
}
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);
}
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;
}
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;
}
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);
}
}
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;
}
stock ResetPlayerWeaponsEx(playerid)
{
ResetPlayerWeapons(playerid);
for(new i = 0; i < 13; i++)
{
PlayerInfo[playerid][pGuns][i] = 0;
}
return 1;
}
it should be GivePlayerWeaponEx instead of GivePlayerWeapon and then try as u seems using Server sided weapon cheat.
|
Are those examples the only places the warnings gets sent?
What if you posted the other pickups for instance, to compare the code? I've gone through this script now at least 10 times, and I can't honestly see why it should fail. You give weapons through the new function "GivePlayerValidWeapon(playerid, weaponid, ammo)" - , and you also assured to set the correct weapon data in the arrays for it. What happens on player death, spawn etc? |
if(weapon[w] != PlayerInfo[i][pGuns][w] && weapon[w] != 0)
{
ExecuteHackerAction(i, weapon[w]);
}
printf("DEBUG WH Content: weapon[w] = %d\nContent: PlayerInfo[i][pGuns][w] = %d", weapon[w], PlayerInfo[i][pGuns][w]);
Okay try to debug the script.
Add messages to print the contents of the arrays that doesn't match. pawn Code:
pawn Code:
|
I have a deagle.
I type in /tazer. It removes the deagle, gives me a silenced pistol, a warning pops up that I may be hacking a deagle. This is getting out of control. |
yes as expected, things that happen in online games are not instant, they take time.
when you set a variable it's instant, when you give someone a weapon data has to travel to their client and then the client sets the right weapon. GetPlayerWeapon doesn't query the players client, it returns data previously sent by the client. So when you give a player a deagle and then give them a silenced pistol the script says they should have a silenced pistol, but using GetPlayerWeaponData right under it will return a deagle since you're reading old data, you have to give the client time to update to the server, what I used to do was check every second but only warn on 5 and 10 seconds, then kick them at 15 seconds for more reading https://sampforum.blast.hk/showthread.php?tid=220089 |
new currweapon = GetPlayerWeapon(playerid);
new lastweapon = GetPVarInt(playerid, "LastWeap");
if(currweapon != lastweapon)
{
OnPlayerWeaponChange(playerid, lastweapon, currweapon);
SetPVarInt(playerid, "LastWeap", currweapon);
}
stock OnPlayerWeaponChange(playerid, lastweap, newweap)
{
if(PlayerInfo[playerid][pGuns][11] != 46 && newweap == 46)
// Assigning the parachute to pGuns (because i.e., if you jump out of a hydra, you get a parachute)
{
PlayerInfo[playerid][pGuns][11] = 46;
return 1;
}
if(newweap != 0)
{
if(PlayerInfo[playerid][pGuns][GetGunSlot(newweap)] != newweap)
{
// ... your ban code
return 1;
}
}
return 1;
}
stock GetGunSlot(weaponid)
{
switch(weaponid)
{
case 0, 1: return 0;
case 2 .. 9: return 1;
case 10 .. 15: return 10;
case 16 .. 18, 39: return 8;
case 22 .. 24: return 2;
case 25 .. 27: return 3;
case 28, 29, 32: return 4;
case 30, 31: return 5;
case 33, 34: return 6;
case 35 .. 38: return 7;
case 40: return 12;
case 41 .. 43: return 9;
case 44 .. 46: return 11;
}
return -1;
}