Skip to content

NPC_SetWeaponSkillLevel guard is inverted (doesn't do anything for valid skill ids) - #1298

Open
DignitySAMP wants to merge 3 commits into
openmultiplayer:masterfrom
DignitySAMP:fix/npc-weapon-skill
Open

DignitySAMP wants to merge 3 commits into
openmultiplayer:masterfrom
DignitySAMP:fix/npc-weapon-skill

Conversation

@DignitySAMP

@DignitySAMP DignitySAMP commented Nov 17, 2026 •

Copy link
Copy Markdown

I encountered a problem with NPC's where NPC_SetWeaponSkillLevel wouldn't actually set the skill level. My intent was for NPC's to hold pistols in a single hand. I noticed that NPC_GetWeaponSkillLevel returns 999 despite valid code:

new npc = NPC_Create("SkillTest");
NPC_Spawn(npc);
NPC_SetWeapon(npc, WEAPON_COLT45);
NPC_SetWeaponSkillLevel(npc, WEAPONSKILL_PISTOL, 200);
printf("%d", NPC_GetWeaponSkillLevel(npc, WEAPONSKILL_PISTOL));

Expected: 200
Actual: 999

It seems this is the cause:

void NPC::setWeaponSkillLevel(PlayerWeaponSkill weaponSkill, int level)
{
if (weaponSkill >= 11 || weaponSkill < 0)

if (weaponSkill >= 11 || weaponSkill < 0)

Looking at getWeaponSkillLevel, the check in setWeaponSkillLevel is inverted and should be weaponSkill >= 0 && weaponSkill < 11. The first commit in this PR addresses that.

While testing this I also noticed NPC's on the default skill (999) have two guns, which is valid, but the server still counts it as a single mag which plays the short reload for them. This makes them start shooting again before the reload animation is done.

isWeaponDoubleHanded currently checks skillLevel > 999 while the client already dual wields at 999. The second commit changes that to >= 999.

A Colt 45 on 999 then goes from clip 17 / reload 1300 ms to clip 34 / reload 2000 ms. Also tested and confirmed the fix with the sawn-off, Micro Uzi and Tec-9.

I ran this on 1.6.7.3218 master and tested/fixed it on an empty server with a 0.3.7-R1 client (CachyOS, arch btw).

Worth noting: NPC's have all their skills on 999 by default, so after the second commit any NPC holding a Colt 45, sawn-off, Micro Uzi or Tec-9 counts as dual wield on the server too (double clip, dual reload time). Clients already showed them like that, but scripts that keep track of NPC ammo will see the bigger clip.

@itsneufox

Copy link
Copy Markdown
Contributor

both commits look good, i ran some tests and got the same issue, skills 0-10 never change and remain at 999.

one thing worth mentioning in the PR description tho, NPCs have all their skills set to 999 by default, so after the second commit any NPC using a Colt, sawn-off, Uzi or Tec-9 will actually dual wield. the clip size doubles (17 to 34 for the Colt) and the dual wield reload time applies. clients already render them dual wielding at 999, so this is just making the server behave accordingly, but it does affect scripts that keep track of NPC ammo.

also, the native still returns true when passing an invalid skill ID, might as well fix that in the same PR.

@DignitySAMP

Copy link
Copy Markdown
Author

Thanks for the repro and testing. I added the note and pushed the out of bounds guard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants