GetPlayerWeapon - 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: GetPlayerWeapon (
/showthread.php?tid=595740)
GetPlayerWeapon -
JaKe Elite - 07.12.2015
I have been working on an Ammo System where in the player's ammo is detected of getting reduced by using the OnPlayerKeyStateChange. This code works somehow (I am not sure if i coded it right, Judge it by yourself.) I have been getting an issue with GetPlayerWeapon. Here's an example, I have a Tec-9, GetPlayerWeapon returns the weaponID. I shoot the weapon until it ran out of ammo, The next time i used the KEY_FIRE, GetPlayerWeapon still returns the weaponID of Tec-9 even if it wasn't there.
I am testing this out with one weapon, I haven't tested this out with multiple weapons (for example, I have Tec-9 & Deagle on my gun inventory) In case i have misunderstood the issue i am trying to point it out here, let me know.
PHP код:
// OnPlayerKeyStateChange
if(HOLDING(KEY_FIRE))
{
new weap = GetPlayerWeapon(playerid);
new slot = GetWeaponSlot(weap);
if(weap <= 22 || weap >= 34 || weap == 41 || weap == 42 || weap == 43) // Weapons with ammos [cameras,spray,fire extinguisher included]
{
if(GetPlayerWeaponState(playerid) != WEAPONSTATE_RELOADING)
{
PlayerInfo[playerid][pGunAmmo][slot] --;
if(PlayerInfo[playerid][pGunAmmo][slot] <= 0)
{
SendClientMessage(playerid, -1, "You are out of ammo."); // Debug message.
PlayerInfo[playerid][pGunAmmo][slot] = 0;
PlayerInfo[playerid][pGuns][slot] = 0;
SetPlayerArmedWeapon(playerid, 0);
}
}
}
}
Re: GetPlayerWeapon -
TwinkiDaBoss - 07.12.2015
Use
https://sampwiki.blast.hk/wiki/OnPlayerWeaponShot
That way you can actually detect if they are shooting or not safely.
Also make a system that will simply detect when they ran out of ammo.
example:
pawn Код:
if(GetPlayerAmmo(playerid) != PlayerInfo[playerid][pGunAmmo][slot]) //if they dont match
Altho this would work only on the weapon they are currently holding, so not 100% reliable but I think you get my point
Re: GetPlayerWeapon -
Vince - 07.12.2015
There seems to be some misunderstanding about "holding" a key. OnPlayerKeyStateChange only gets called when a key actually changes. You can be holding KEY_FIRE for an hour and still OnPlayerKeyStateChange won't be called until you either release the key you're currently holding or press another one in addition to the one you're holding.