Benny/gamemodes/benny/gamemode/inventory.lua

86 lines
1.8 KiB
Lua

local Emeta = FindMetaTable("Entity")
local qt2 = {
["slot1"] = 1,
["slot2"] = 2,
["slot3"] = 3,
["slot4"] = 4,
["slot5"] = 5,
["slot6"] = 6,
["slot7"] = 7,
["slot8"] = 8,
["slot9"] = 9,
["slot0"] = 0,
}
local qt = {
["invprev"] = -1,
["invnext"] = 1,
}
hook.Add( "PlayerBindPress", "Benny_PlayerBindPress_Original", function( ply, bind, pressed, code )
if qt2[bind] then
local Num = qt2[bind]
if pressed then
local inv = ply:GetInventory():GetWeighted()
local wep = ply:HandlerCheck()
local invf = table.Flip( inv )
local NumOfActive = 0
NumOfActive = invf[wep:GetDesireR()]
if Num == NumOfActive then
Num = 0
end
input.SelectWeapon( ply:GetWeapon("goat_"..Num) )
end
return true
end
if qt[bind] then
if pressed then
local Num = 0
local inv = ply:GetInventory():GetWeighted()
local wep = ply:HandlerCheck()
local invf = table.Flip( inv )
local invc = #inv
Num = wep:GetDesireR() and invf[wep:GetDesireR()] or 0
Num = Num + qt[bind]
if Num > invc then
Num = 0
elseif Num < 0 then
Num = invc
end
input.SelectWeapon( ply:GetWeapon("goat_"..Num) )
end
return true
end
end)
hook.Add( "PlayerSwitchWeapon", "Benny_PlayerSwitchWeapon_Goat", function( ply, old, ent )
if ent.BennyItemHandler then return true end -- what happened?
local wep = ply:HandlerCheck()
if !wep then print("PlayerSwitchWeapon Benny Handler Missing!!") return false end
if ent:IsValid() and ent.Goat then
local inv = ply:GetInventory():GetWeighted()
if ent.Goat == 0 then wep:SetDesireR( NULL ) return false end
local ent = inv[ent.Goat]
if ent then
wep:SetDesireR( ent )
end
end
return false
end)
for i=0, 9 do
local tent = {}
tent.Goat = i
weapons.Register( tent, "goat_" .. i )
end