Вопрос Вопрос по веапону селектору

  • 52
  • 1
  • 5
Контакты для связи отсутствуют.
Можно ли как-то оружие перенести во вкладку оружия.
1673845038418.png

пытался прописать в самом конфиге этого селектора , но безуспешно.
Lua:
local categories = {
    'Строительство',
    'Ролеплей',
    'Другое',
    'Оружие'
}

local weaponMap = {
    weapon_physgun = {
        Name = 'Физ-Ган',
        Slot = 1
    },
    weapon_physcannon = {
        Name = 'Гравити-Ган',
        Slot = 1
    },
    weapon_rpg = {
        Name = 'RPG',
        Slot = 4
    },
    weapon_crossbow = {
        Name = 'Crossbow',
        Slot = 4
    },
    weapon_crowbar = {
        Name = 'Монтировка',
        Slot = 3
    },
    weapon_slam = {
        Name = 'SLAM',
        Slot = 4
    },
    itemstore_pickup = {
        Name = 'Инвентарь',
        Slot = 2
    },
    keys = {
        Name = 'Ключи',
        Slot = 2
    },
    weapon_stunstick = {
        Name = 'Stunstick',
        Slot = 4
    }
}   

local function getWeaponSlot(wep)
    if (wep.GetSwitcherSlot) then
        wep.Slot = wep:GetSwitcherSlot()
    end

    local map = weaponMap[wep:GetClass()]
    return (wep.Slot and math.Clamp(wep.Slot, 1, 4)) or (map and map.Slot) or 2
end

local wepsCache = {}
local weaponsByCategory = {}
local weaponsByOrder = {}
local weaponsByClass = {}
local selectedWeapon = -1
local lastCache = CurTime()
local function ensureWeapons(force)
    local weps = LocalPlayer():GetWeapons()

    if (lastCache <= CurTime() or force) then
        wepsCache = weps

        table.Empty(weaponsByCategory)
        table.Empty(weaponsByOrder)
        table.Empty(weaponsByClass)
        for k, cat in ipairs(categories) do
            local wepSlot = k

            weaponsByCategory[wepSlot] = {}
            for _, wep in pairs(weps) do
                if (getWeaponSlot(wep) == wepSlot) then
                    local ind = table.insert(weaponsByCategory[wepSlot], {
                        ID = #weaponsByOrder + 1,
                        Class = wep:GetClass(),
                        Name = (weaponMap[wep:GetClass()] and weaponMap[wep:GetClass()].Name) or wep.PrintName or wep:GetClass(),
                        Ent = wep
                    })

                    weaponsByOrder[#weaponsByOrder + 1] = weaponsByCategory[wepSlot][ind]
                    weaponsByClass[wep:GetClass()] = weaponsByCategory[wepSlot][ind]
                end
            end
        end
    end

    if (selectedWeapon == 0 and IsValid(LocalPlayer():GetActiveWeapon()) and weaponsByClass[LocalPlayer():GetActiveWeapon():GetClass()]) then
        selectedWeapon = weaponsByClass[LocalPlayer():GetActiveWeapon():GetClass()].ID
    end

    lastCache = CurTime() + 0.25
end

local showTime = 0
local fadeTime = 0

local lastWep
local currentWep
local function switchWeapon(wep)
    wep = wep or weaponsByOrder[selectedWeapon]

    showTime = 0

    if not wep then
        return
    end

    lastWep = currentWep
    currentWep = wep

    if not IsValid(LocalPlayer():GetActiveWeapon()) or LocalPlayer():GetActiveWeapon() ~= wep.Ent then
        input.SelectWeapon(wep.Ent)
    else
        return
    end

    surface.PlaySound('buttons/lightswitch2.wav')
    return true
end

local color_white         = ui.col.White
local color_flatblack     = ui.col.FlatBlack
local color_background     = ui.col.Background
local color_highlight     = ui.col.TransWhite100
local color_sup         = ui.col.SUP
local color_red         = ui.col.Red

function GM:DrawWepSwitch()
    local st = SysTime()
    local w, h = 185, 35
    local x, y = (ScrW() - #categories * (w + 3)) * 0.5, 35

    if (showTime + 0.25 <= st) then return end
    ensureWeapons()

    if (showTime <= st) then
        surface.SetAlphaMultiplier(Lerp((st - showTime) / 0.1, 1, 0))
    else
        surface.SetAlphaMultiplier(Lerp((st - fadeTime) / 0.1, 0, 1))
    end

    for k, cat in ipairs(categories) do
        local x, y = x + ((k - 1) * (w + 3)), y
        local wepSlot = k
        draw.Box(x, y, w, h, color_flatblack)
        draw.SimpleText(wepSlot, 'ui.17', x + 3, h + 3, color_sup, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
        draw.SimpleText(cat, 'ui.20', x + (w * 0.5), y + (h * 0.5), color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

        for i, wep in ipairs(weaponsByCategory[wepSlot]) do
            local y = y + (i * (h + 3))
            draw.Box(x, y, w, h, color_background)

            if (wep.ID == selectedWeapon) then
                draw.Box(x, y, w, h, color_highlight)
            end

            draw.SimpleText(wep.Name, 'ui.18', x + 5, y + 3, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)

            if (not IsValid(wep.Ent)) then continue end

            local clip1, maxClip1 = wep.Ent:Clip1(), wep.Ent:GetMaxClip1()
            local isUnlimited = (maxClip1 < 1) and (clip1 < 1) or (not wep.Ent.DrawAmmo)

            draw.SimpleText(isUnlimited and '∞' or (clip1 .. '/' .. maxClip1) , 'ui.17', (x + w) - 5, (y + h) - 3, ((not isUnlimited) and (clip1 == 0)) and color_red or color_sup, TEXT_ALIGN_RIGHT, TEXT_ALIGN_BOTTOM)
        end
    end
end

local lastSnd = 0
hook('PlayerBindPress', 'rp.wepswitch.PlayerBindPress', function(pl, bind, pressed)
    if (!pressed) then return end
    if (!LocalPlayer():Alive()) then return end
    if (!IsValid(LocalPlayer():GetActiveWeapon())) then return end
    if (table.Count(LocalPlayer():GetWeapons()) <= 1) then return end

    local wep = pl:GetActiveWeapon()

    if IsValid(wep) and wep.SWBWeapon and wep.dt and (wep.dt.State == SWB_AIMING) and wep.AdjustableZoom then
        return
    end

    if hook.Call('SuppressWeaponSwitcher', nil, pl, bind, pressed) then return end

    if ((bind == 'invprev') or (bind == 'lastinv') or (bind == 'invnext') or (string.sub(bind, 1, 4) == 'slot')) and (not pl:KeyDown(IN_ATTACK)) then
        if (bind == 'lastinv') and lastWep and IsValid(lastWep.Ent) then
            switchWeapon(lastWep)
            selectedWeapon = currentWep.ID
        elseif (string.sub(bind, 1, 3) == 'inv') then
            if (showTime < SysTime()) then
                ensureWeapons(true)
                selectedWeapon = 0
            else
                local scroll = (bind == 'invprev') and -1 or 1

                selectedWeapon = selectedWeapon + scroll
                if (!weaponsByOrder[selectedWeapon]) then
                    selectedWeapon = (scroll == 1 and 1) or #weaponsByOrder
                end
            end
        else -- using number keys
            if (showTime < SysTime()) then
                ensureWeapons(true)
                fadeTime = SysTime()
            end

            local slot = tonumber(string.sub(bind, -1))

            if (!categories[slot]) then return end

            if (weaponsByCategory[slot][1]) then
                local found = false
                for k, v in ipairs(weaponsByCategory[slot]) do
                    if (v.ID == selectedWeapon) then
                        found = true

                        if (weaponsByCategory[slot][k + 1]) then
                            selectedWeapon = v.ID + 1
                        else
                            selectedWeapon = weaponsByCategory[slot][1].ID
                        end

                        break
                    end
                end

                if (!found) then
                    selectedWeapon = weaponsByCategory[slot][1].ID
                end
            end
        end

        ensureWeapons(true)
        showTime = SysTime() + 2

        if (lastSnd < SysTime() - 0.05) then
            surface.PlaySound('garrysmod/ui_hover.wav')
            lastSnd = SysTime()
        end
    elseif (showTime > SysTime() and bind == '+attack') then
        showTime = 0
        if (IsValid(LocalPlayer():GetActiveWeapon()) and weaponsByOrder[selectedWeapon] and weaponsByClass[LocalPlayer():GetActiveWeapon():GetClass()] and selectedWeapon != weaponsByClass[LocalPlayer():GetActiveWeapon():GetClass()].ID) then
            switchWeapon()
        end
        return true
    elseif (bind == 'phys_swap') then
        showTime = 0
    end
end)
 
Сверху Снизу