Jump to content

[Help] Group Weapon Storage System


Recommended Posts

a system like putting a gun in the trunk of a car, but instead of a car trunk, I want to be able to take and put a specified amount of guns from a chosen object or marker.

If such a system exists, could you send it?

Link to comment

client.lua

local marker = createMarker(-2407.9291992188, -600.03851318359, 132.6484375, "cylinder", 1.5, 255, 255, 255, 150)
local guiWindow = nil  -- GUI penceresini tutacak değişken

-- GUI Paneli gösterme event'i
addEventHandler("onClientMarkerHit", marker, function(hitElement, matchingDimension)
    if hitElement ~= localPlayer or not matchingDimension then return end
    
    -- Ekranın ortasında bir pencere oluştur
    local screenWidth, screenHeight = guiGetScreenSize()
    local windowWidth = 600
    local windowHeight = 400
    local windowX = (screenWidth - windowWidth) / 2
    local windowY = (screenHeight - windowHeight) / 2

    guiWindow = guiCreateWindow(windowX, windowY, windowWidth, windowHeight, "Silah Yönetimi", false)
    
    -- Fare imleci gösterme
    showCursor(true)
    
    -- Pencere kapatma butonu oluşturma
    local closeButton = guiCreateButton(windowWidth - 30, 0, 30, 20, "X", false, guiWindow)
    addEventHandler("onClientGUIClick", closeButton, function()
        guiSetVisible(guiWindow, false)
        showCursor(false)
    end, false)

    -- Sol tarafta "Silahlar" alanı için gridlist oluştur
    local weaponsGrid = guiCreateGridList(0.05, 0.1, 0.4, 0.7, true, guiWindow)
    local weaponColumn = guiGridListAddColumn(weaponsGrid, "Silahlar", 0.9)

    -- Sağ tarafta "Sahip Olduğun Silahlar" alanı için gridlist oluştur
    local playerWeaponsGrid = guiCreateGridList(0.55, 0.1, 0.4, 0.7, true, guiWindow)
    local playerWeaponColumn = guiGridListAddColumn(playerWeaponsGrid, "Sahip Olduğun Silahlar", 0.9)

    -- "Silah Koy" butonu oluştur
    local giveWeaponButton = guiCreateButton(0.05, 0.85, 0.4, 0.1, "Silah Koy", true, guiWindow)
    local giveWeaponAmountEdit = guiCreateEdit(0.05, 0.75, 0.4, 0.05, "", true, guiWindow)
    guiEditSetMaxLength(giveWeaponAmountEdit, 3) -- Maksimum 3 karakter uzunluğunda sayı girişi yapılabilir
    addEventHandler("onClientGUIClick", giveWeaponButton, function()
        local selectedRow, _ = guiGridListGetSelectedItem(playerWeaponsGrid)
        local amount = tonumber(guiGetText(giveWeaponAmountEdit)) or 1
        if selectedRow ~= -1 then
            local weaponName = guiGridListGetItemText(playerWeaponsGrid, selectedRow, playerWeaponColumn)
            triggerServerEvent("putPlayerWeapon", resourceRoot, weaponName, amount)
        else
            outputChatBox("Lütfen bir silah seçin!", 255, 0, 0)
        end
    end, false)

    -- "Silah Ver" butonu oluştur
    local takeWeaponButton = guiCreateButton(0.55, 0.85, 0.4, 0.1, "Silah Ver", true, guiWindow)
    local takeWeaponAmountEdit = guiCreateEdit(0.55, 0.75, 0.4, 0.05, "", true, guiWindow)
    guiEditSetMaxLength(takeWeaponAmountEdit, 3) -- Maksimum 3 karakter uzunluğunda sayı girişi yapılabilir
    addEventHandler("onClientGUIClick", takeWeaponButton, function()
        local selectedRow, _ = guiGridListGetSelectedItem(weaponsGrid)
        local amount = tonumber(guiGetText(takeWeaponAmountEdit)) or 1
        if selectedRow ~= -1 then
            local weaponName = guiGridListGetItemText(weaponsGrid, selectedRow, weaponColumn)
            triggerServerEvent("givePlayerWeapon", resourceRoot, weaponName, amount)
        else
            outputChatBox("Lütfen bir silah seçin!", 255, 0, 0)
        end
    end, false)

    
    local playerWeaponsCloseButton = guiCreateButton(windowWidth - 30, 20, 30, 20, "X", false, guiWindow)
    addEventHandler("onClientGUIClick", playerWeaponsCloseButton, function()
        guiSetVisible(guiWindow, false)
        showCursor(false)
    end, false)

    -- GUI oluşturulduğunu sunucuya bildir
    triggerServerEvent("onClientRequestWeapons", resourceRoot)
end)

-- Sunucudan silahları al ve güncelle
addEvent("onServerSendWeapons", true)
addEventHandler("onServerSendWeapons", resourceRoot, function(weapons, playerWeapons)
    -- "Silahlar" alanını güncelle
    local weaponsGrid = guiGridListGetItem(weaponsGrid)
    guiGridListClear(weaponsGrid)
    for _, weaponName in ipairs(weapons) do
        guiGridListAddRow(weaponsGrid, weaponName)
    end

    -- "Sahip Olduğun Silahlar" alanını güncelle
    local playerWeaponsGrid = guiGridListGetItem(playerWeaponsGrid)
    guiGridListClear(playerWeaponsGrid)
    for _, weaponName in ipairs(playerWeapons) do
        guiGridListAddRow(playerWeaponsGrid, weaponName)
    end
end)

-- Silah verme event'i
addEvent("givePlayerWeapon", true)
addEventHandler("givePlayerWeapon", resourceRoot, function(weaponName, amount)
    giveWeapon(localPlayer, getWeaponIDFromName(weaponName), amount)
    outputChatBox("Silah başarıyla verildi: " .. weaponName)
    triggerServerEvent("onClientRequestWeapons", resourceRoot)
end)

-- Silah alma event'i
addEvent("takePlayerWeapon", true)
addEventHandler("takePlayerWeapon", resourceRoot, function(weaponName, amount)
    takeWeapon(localPlayer, getWeaponIDFromName(weaponName), amount)
    outputChatBox("Silah başarıyla alındı: " .. weaponName)
    triggerServerEvent("onClientRequestWeapons", resourceRoot)
end)

-- Playerden silah alma ve "Silahlar" alanına ekleme event'i
addEvent("putPlayerWeapon", true)
addEventHandler("putPlayerWeapon", resourceRoot, function(weaponName, amount)
    guiGridListAddRow(playerWeaponsGrid, weaponName)
end)

-- GUI kapatma event'i
addEventHandler("onClientResourceStop", resourceRoot, function()
    if guiWindow and isElement(guiWindow) then
        destroyElement(guiWindow)
        showCursor(false)
    end
end)

I've done a few things, but the weapons on the player aren't showing up on the table. Can you help?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...