Workaround for OnPlayerWeaponShot - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Workaround for OnPlayerWeaponShot (
/showthread.php?tid=610264)
Workaround for OnPlayerWeaponShot -
TwinkiDaBoss - 21.06.2016
So okay, for some reason (I just noticed) OnPlayerWeaponShot doesn't get called with bombs and rocket launchers.
PHP код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ) {
print("OnPlayerWeaponShot called");
printf("Weapon ID: %i :: Ammo: %i",GetPlayerWeapon(playerid),GetPlayerAmmo(playerid));
printf("Weapon ID: %i :: Ammo: %i",weaponid,GetPlayerAmmo(playerid));
return 1;
}
Tested with that code.
Now, there is only 1 work around I found for bombs and thats it with KeyStateChange
PHP код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if ((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE)) {
if(GetPlayerWeapon(playerid) == 16) {
printf("Weapon ID: %i :: Ammo: %i",GetPlayerWeapon(playerid),GetPlayerAmmo(playerid));
}
}
return 1;
}
But is there another way for it?
Re: Workaround for OnPlayerWeaponShot -
TwinkiDaBoss - 21.06.2016
The problem is basically
PHP код:
public CheckPlayerWeapons(playerid) {
new weapons[13][2];
for (new i = 0; i <= 12; i++) {
GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
if(weapons[i][0] != PlayerWeapon[playerid][i][P_WeaponID] || weapons[i][1] != PlayerWeapon[playerid][i][P_Ammo]) {
if(weapons[i][0] != 0) {
new string[128];
format(string,sizeof(string),"Suspicious weapons on %s: %i %i",GetName(playerid),weapons[i][0], weapons[i][1]);
SendClientMessageToAll(COLOR_RED,string);
ResetPlayerWeaponsEx(playerid);
}
}
}
}
Thats how I check if player has the difference in his weapons aka if there are any new weapons they should have or if ammo doesnt match
Now with RPG and Bombs, it will never match for some reason.
PHP код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new weapons[13][2];
if ((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE)) { //bombs
if(GetPlayerWeapon(playerid) == 16) {
for (new i = 0; i <= 12; i++) {
GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
PlayerWeapon[playerid][i][P_WeaponID] = weapons[i][0];
PlayerWeapon[playerid][i][P_Ammo] = weapons[i][1];
}
}
}
if (HOLDING( KEY_FIRE ) && (PRESSED( KEY_FIRE ))) { //rockets
if(GetPlayerWeapon(playerid) == 35) {
for (new i = 0; i <= 12; i++) {
GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
PlayerWeapon[playerid][i][P_WeaponID] = weapons[i][0];
PlayerWeapon[playerid][i][P_Ammo] = weapons[i][1];
}
}
}
return 1;
}
Everything else works correctly but bombs and rpg's dont..