Jump to content

Weapon Name in GridList, HELP!


iPanda

Recommended Posts

wind = guiCreateWindow(X, Y, W, H, "", true) 
tab = guiCreateTabPanel(X, Y, W, H, true, wind) 
tab_inventory = guiCreateTab("Weapon", tab) 
  
inventory_gridlist = guiCreateGridList(X, Y, W, H, true, tab_inventory) 
guiGridListAddColumn(inventory_gridlist, "Weap:", 0.9) 
guiGridListAddRow(inventory_gridlist) 
guiGridListSetItemText(inventory_gridlist, 0, 1, "SLOTS!!!", false, false) 

"SLOTS!!!" - slots can be any weapon. That is, if a player has, say, a weapon M4, it is displayed it in the slot, and if it does not have these weapons, respectively, then it is not displayed in the slots. How to make this function?

Two screenshot, which shows when the player has arms M4 or when it had not.

AnMdpbizl9Q.jpg

JzUyXoed8F4.jpg

Link to comment

Here, I wrote this code. But it does not work:

local player = getLocalPlayer() 
kpk = guiCreateStaticImage(X, Y,W,H, "images/kpk.png", true) 
tab = guiCreateTabPanel(X, Y,W,H, true, kpk) 
tab_inventory = guiCreateTab("Weap:", tab) 
  
function weapItemInInventory ( ) 
    local inventory_gridlist = guiCreateGridList (0.03, 0.03, 0.46, 0.94, true, tab_inventory) 
    local weapSlots = guiGridListAddColumn(inventory_gridlist, "Оружие", 0.9) 
    if ( weapSlots ) then  
        for id, playeritem in ipairs(getElementModel(player,356)) do  
            local row = guiGridListAddRow ( inventory_gridlist ) 
            guiGridListSetItemText ( inventory_gridlist, row, weapSlots, getWeaponNameFromID ( playeritem ), false, false ) 
        end 
    end 
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement(), weapItemInInventory ) 

Here, he writes debug:

L0dFcjFJN1M.jpg

Also, I know that the error in this line. Can you help me fix it, because I understand that this is not right, but I do not know how to solve this problem correctly!

for id, playeritem in ipairs(getElementModel(player,356)) do 

Link to comment
for id, playeritem in ipairs(getElementModel(player,356)) do 

You can use:

for playeritem=1,46 do 

And it will return an id for all the weapons

Thank you, your code works perfectly! But there is one konvuz, your code shows everything arms, even if the player does not have them. I need a code that will show only the weapons have a player at the moment.

Link to comment
local player = getLocalPlayer() 
kpk = guiCreateStaticImage(X, Y,W,H, "images/kpk.png", true) 
tab = guiCreateTabPanel(X, Y,W,H, true, kpk) 
tab_inventory = guiCreateTab("Weap:", tab) 
  
function weapItemInInventory ( ) 
    local inventory_gridlist = guiCreateGridList (0.03, 0.03, 0.46, 0.94, true, tab_inventory) 
    local weapSlots = guiGridListAddColumn(inventory_gridlist, "??????", 0.9) 
    if ( weapSlots ) then 
        for slot = 1, 12 do 
            local weapon = getPedWeapon ( localPlayer, slot ) 
            if ( weapon > 0 ) then 
                local row = guiGridListAddRow ( inventory_gridlist ) 
                guiGridListSetItemText ( inventory_gridlist, row, weapSlots, getWeaponNameFromID ( weapon ), false, false ) 
            end 
        end 
    end 
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement(), weapItemInInventory ) 

Link to comment
local player = getLocalPlayer() 
kpk = guiCreateStaticImage(X, Y,W,H, "images/kpk.png", true) 
tab = guiCreateTabPanel(X, Y,W,H, true, kpk) 
tab_inventory = guiCreateTab("Weap:", tab) 
  
function weapItemInInventory ( ) 
    local inventory_gridlist = guiCreateGridList (0.03, 0.03, 0.46, 0.94, true, tab_inventory) 
    local weapSlots = guiGridListAddColumn(inventory_gridlist, "??????", 0.9) 
    if ( weapSlots ) then 
        for slot = 1, 12 do 
            local weapon = getPedWeapon ( localPlayer, slot ) 
            if ( weapon > 0 ) then 
                local row = guiGridListAddRow ( inventory_gridlist ) 
                guiGridListSetItemText ( inventory_gridlist, row, weapSlots, getWeaponNameFromID ( weapon ), false, false ) 
            end 
        end 
    end 
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement(), weapItemInInventory ) 

Thank you very much. But there is a small flaw. When my player gets a new weapon, it does not appear in my dashboard. Add onClientRender, or something otherwise?

Link to comment

Try this:

local player = getLocalPlayer() 
kpk = guiCreateStaticImage(X, Y,W,H, "images/kpk.png", true) 
tab = guiCreateTabPanel(X, Y,W,H, true, kpk) 
tab_inventory = guiCreateTab("Weap:", tab) 
inventory_gridlist = guiCreateGridList (0.03, 0.03, 0.46, 0.94, true, tab_inventory) 
weapSlots = guiGridListAddColumn(inventory_gridlist, "??????", 0.9) 
  
function weapItemInInventory ( ) 
    if ( weapSlots ) then 
        for slot = 1, 12 do 
            local weapon = getPedWeapon ( localPlayer, slot ) 
            if ( weapon > 0 ) then 
                local row = guiGridListAddRow ( inventory_gridlist ) 
                guiGridListSetItemText ( inventory_gridlist, row, weapSlots, getWeaponNameFromID ( weapon ), false, false ) 
            end 
        end 
    end 
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement(), weapItemInInventory ) 
  
setTimer ( function ( ) 
    guiGridListClear ( inventory_gridlist ) 
    weapItemInInventory ( ) 
end, 5000, 0 ) 

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...