Skip to content

Commit 672cb6e

Browse files
authored
Make giveweapon give explicit class name and check if weapon is npc useable (thegrb93#2428)
1 parent 796030c commit 672cb6e

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

lua/starfall/libs_sh/npc.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,19 @@ if SERVER then
119119
local npc = unwrap(self)
120120
checkpermission(instance, npc, "npcs.giveweapon")
121121

122+
local npcSpawnable = false
123+
for _, v in ipairs(list.GetForEdit("NPCUsableWeapons")) do
124+
if v.class == wep then npcSpawnable = true break end
125+
end
126+
if not npcSpawnable then SF.Throw("Weapon "..wep.." is not in npc useable weapons list!", 2) end
127+
122128
local weapon = npc:GetActiveWeapon()
123129
if Ent_IsValid(weapon) then
124-
if (Ent_GetClass(weapon) == "weapon_" .. wep) then return end
130+
if (Ent_GetClass(weapon) == wep) then return end
125131
Ent_Remove(weapon)
126132
end
127133

128-
Npc_Give(npc, "ai_weapon_" .. wep)
134+
Npc_Give(npc, wep)
129135
end
130136

131137
--- Tell the npc to fight this

0 commit comments

Comments
 (0)