Jump to content

Help needed with script Shop panel


Quenix

Recommended Posts

So i have a shop script wich pretty much allows to buy items/weapons from this shop, the shop sells with "K.B.K Points" which is the player money but with another name to fit the server. The problem i have is when player buys one of the item they get all of them. I want to make them get the item they buy ONLY and get the right amount, for example if you buy a MK 48 Mod 0 Mag, you should get 100x of this item in your inventory because the mag itself is 100, otherwise wich ive tested it only gave 1x. But the problem is when i add more lines which i have shown below, it gives the player all the items listed below, i was trying to use if, and else if, but because i lack experience in lua coding i was not able to debug this even with debugscript! I would appreciate if someone could work out or help me out on how to make the shop only give the player the item the player buys and the right amount! The "+1" in the lists are the amount the player should get! If you need more of the code to understand and help me out then i will add it on request
 

local items = {
--items,cena(K.B.K Points)
{"M1911",50},
{"PDW",150},
{"Winchester 1866",150},
{"AK-107",300},
{"M4A1 Holo",300},
{"MK 48 Mod 0",450},
{"CZ550",300},
{"DMR",400},
{"M1911 Mag",50},
{"PDW Mag",100},
{"1866 Slug",125},
{"AK-107 Mag",100},
{"M4A1 Holo Mag",50},
{"MK 48 Mod 0 Mag",200},
{"CZ550 Mag",50},
{"DMR Mag",25},
{"Medic Kit",50},
{"Painkiller",10},
{"Morphine",10},
{"Bandage",5},
{"Water Bottle",15},
{"Burger",15},
{"Tire",75},
{"Engine",125},
{"Tank Parts",50},
{"Camouflage Clothing",100},
{"Army Clothing",150},
{"Ghost Clothing",200},
{"K.B.K Backpack",150},
{"Ghillie Suit",200},
{"Civilian Clothing",30},
{"GPS",15},
{"Map",15},
{"Toolbox",25}, 
}

SHOP = {
    button = {},
    window = {},
    gridlist = {},
    label = {}
}
addEventHandler("onClientResourceStart", resourceRoot,
    function()
        
        SHOP.window[1]  = guiCreateWindow(0.17, 0.23, 0.65, 0.55, "Kill Or Be Killed Shop", true)
        guiWindowSetMovable(SHOP.window[1], false)
        guiWindowSetSizable(SHOP.window[1], false)
        guiSetProperty(SHOP.window[1], "CaptionColour", "FF075205")

        SHOP.gridlist[1] = guiCreateGridList(0.01, 0.06, 0.97, 0.63, true, SHOP.window[1])
        column = guiGridListAddColumn(SHOP.gridlist[1], "Item", 0.5)
        column2 =guiGridListAddColumn(SHOP.gridlist[1], "K.B.K Points", 0.5)
       for _, v in ipairs(items) do
            local row = guiGridListAddRow ( SHOP.gridlist[1] )
            guiGridListSetItemText ( SHOP.gridlist[1], row, column, v[1], false, false )
            guiGridListSetItemText ( SHOP.gridlist[1], row, column2, v[2].."", false, false )
        end
        guiSetProperty(SHOP.gridlist[1], "SortSettingEnabled", "False")
        SHOP.label[1] = guiCreateLabel(0.02, 0.69, 0.97, 0.08, "Select item which you want to buy! \nThe shop value is K.B.K Points", true, SHOP.window[1])
        guiLabelSetColor( SHOP.label[1],255,255,255)
        guiSetFont(SHOP.label[1], "default-bold-small")
        guiLabelSetHorizontalAlign(SHOP.label[1], "center", true)
        guiLabelSetVerticalAlign(SHOP.label[1], "center")
        SHOP.button[1] = guiCreateButton(0.35, 0.79, 0.30, 0.12, "BUY", true, SHOP.window[1])
        guiSetFont(SHOP.button[1], "default-bold-small") 
        guiSetVisible ( SHOP.window[1], false )  
        addEventHandler ( "onClientGUIClick", SHOP.gridlist[1], click ) 
        addEventHandler ( "onClientGUIClick", SHOP.button[1], buttonClick ) 
    end
)

bindKey ( "f4", "down", function ( )
    if getElementData(localPlayer, "logedin") then
       -- if getElementData   (getLocalPlayer(),"playerlevel") >= 3 then
        local state = ( not guiGetVisible (SHOP.window[1]) )
        guiSetVisible ( SHOP.window[1], state )
        showCursor ( state )
 --   else
       -- outputChatBox   (" 3!")
  --  end
end
    end
)
function buttonClick(button)
    if getElementData(localPlayer, "logedin") then
    if button == "left" then
        local nRow, nColumn = guiGridListGetSelectedItem( SHOP.gridlist[1] ) 
         if nRow ~= -1 and nColumn ~= - 1 then
    local selectedItem = guiGridListGetItemText (  SHOP.gridlist[1], guiGridListGetSelectedItem (  SHOP.gridlist[1] ), 1 )
    local price =  guiGridListGetItemText (  SHOP.gridlist[1], guiGridListGetSelectedItem (  SHOP.gridlist[1] ), 2 )
    local money = getPlayerMoney(thePlayer)
        

      



 if (money) >= tonumber(price) then
            guiLabelSetColor( SHOP.label[1],255,255,255)
            --  guiSetText( SHOP.label[1],"pietiek nauda")
             setPlayerMoney(money -tonumber(price))
             setElementData(getLocalPlayer(),"PDW",getElementData(getLocalPlayer(),"PDW")+1)
             setElementData(getLocalPlayer(),"Winchester 1866",getElementData(getLocalPlayer(),"Winchester 1866")+1)
             setElementData(getLocalPlayer(),"M1911",getElementData(getLocalPlayer(),"M1911")+1)
             setElementData(getLocalPlayer(),"AK-107",getElementData(getLocalPlayer(),"AK-107")+1)
             setElementData(getLocalPlayer(),"M4A1 Holo",getElementData(getLocalPlayer(),"M4A1 Holo")+1)
             setElementData(getLocalPlayer(),"DMR",getElementData(getLocalPlayer(),"DMR")+1)
             setElementData(getLocalPlayer(),"CZ550",getElementData(getLocalPlayer(),"CZ550")+1)
             setElementData(getLocalPlayer(),"MK 48 Mod 0",getElementData(getLocalPlayer(),"MK 48 Mod 0")+1)
             setElementData(getLocalPlayer(),"M4A1 Holo Mag",getElementData(getLocalPlayer(),"M4A1 Holo Mag")+20)
             setElementData(getLocalPlayer(),"DMR Mag",getElementData(getLocalPlayer(),"DMR Mag")+5)
             setElementData(getLocalPlayer(),"CZ550 Mag",getElementData(getLocalPlayer(),"CZ550 Mag")+10)
             setElementData(getLocalPlayer(),"M1911 Mag",getElementData(getLocalPlayer(),"M1911 Mag")+100)
             setElementData(getLocalPlayer(),"PDW Mag",getElementData(getLocalPlayer(),"PDW Mag")+10)
             setElementData(getLocalPlayer(),"1866 Slug",getElementData(getLocalPlayer(),"1866 Slug")+7)
             setElementData(getLocalPlayer(),"MK 48 Mod 0 Mag",getElementData(getLocalPlayer(),"MK 48 Mod 0 Mag")+100)
             setElementData(getLocalPlayer(),"Medic Kit",getElementData(getLocalPlayer(),"Medic Kit")+1)
             setElementData(getLocalPlayer(),"Painkiller",getElementData(getLocalPlayer(),"Painkiller")+1)
             setElementData(getLocalPlayer(),"Morphine",getElementData(getLocalPlayer(),"Morphine")+1)
             setElementData(getLocalPlayer(),"Bandage",getElementData(getLocalPlayer(),"Bandage")+1)
               setElementData(getLocalPlayer(),"Water Bottle",getElementData(getLocalPlayer(),"Water Bottle")+1)
             setElementData(getLocalPlayer(),"Burger",getElementData(getLocalPlayer(),"Burger")+1)
             setElementData(getLocalPlayer(),"Tire",getElementData(getLocalPlayer(),"Tire")+1)
             setElementData(getLocalPlayer(),"Engine",getElementData(getLocalPlayer(),"Engine")+1)
             setElementData(getLocalPlayer(),"Tank Parts",getElementData(getLocalPlayer(),"Tank Parts")+1)
             setElementData(getLocalPlayer(),"Camouflage Clothing",getElementData(getLocalPlayer(),"Camouflage Clothing")+1)
             setElementData(getLocalPlayer(),"Army Clothing",getElementData(getLocalPlayer(),"Army Clothing")+1)
             setElementData(getLocalPlayer(),"Ghost Clothing",getElementData(getLocalPlayer(),"Ghost Clothing")+1)
             setElementData(getLocalPlayer(),"K.B.K Backpack",getElementData(getLocalPlayer(),"K.B.K Backpack")+1)
             setElementData(getLocalPlayer(),"Ghillie Suit",getElementData(getLocalPlayer(),"Ghillie Suit")+1)
             setElementData(getLocalPlayer(),"Civilian Clothing",getElementData(getLocalPlayer(),"Civilian Clothing")+1)
             setElementData(getLocalPlayer(),"GPS",getElementData(getLocalPlayer(),"GPS")+1)
             setElementData(getLocalPlayer(),"Map",getElementData(getLocalPlayer(),"Map")+1)
             setElementData(getLocalPlayer(),"Toolbox",getElementData(getLocalPlayer(),"Toolbox")+1)


              
                              
              end


            guiLabelSetColor( SHOP.label[1],10,255,10)
            guiSetText( SHOP.label[1],"You succesfully bought "..selectedItem.." and you still have "..(money -tonumber(price)).." K.B.K Points")
          else
            guiLabelSetColor( SHOP.label[1],255,10,10)
            guiSetText( SHOP.label[1],"You are missing "..(price -tonumber(money)).." K.B.K Points")
        end
    else
       guiSetText( SHOP.label[1],"Select something first")
       guiLabelSetColor( SHOP.label[1],255,255,255) 
   end
end
end

function click () 
       local selectedItem = guiGridListGetItemText (  SHOP.gridlist[1], guiGridListGetSelectedItem (  SHOP.gridlist[1] ), 1 )
        local price =  guiGridListGetItemText (  SHOP.gridlist[1], guiGridListGetSelectedItem (  SHOP.gridlist[1] ), 2 )
       guiSetText( SHOP.label[1],"To buy "..selectedItem.." for "..price.." K.B.K Points press button below")
       guiLabelSetColor( SHOP.label[1],255,255,255)
end

 

Edited by Quenix
Made the code lua style so its more understandable
Link to comment

Hi @Quenix !! :D

           I examined the code that you have provided. And I should tell you that, when you use 'setElementData' to store a numeric value, you should first set it '0' or some numeric value because it's value is a boolean [ true / false ( may be nil ) ] in initial. So, I prepared a server Side code for this.

Server Side :-

addEventHandler("onPlayerLogin",root,
function ()
    setElementData(source,"PDW",0)
    setElementData(source,"Winchester 1866",0)
    setElementData(source,"M1911",0)
    setElementData(source,"AK-107",0)
    setElementData(source,"M4A1 Holo",0)
    setElementData(source,"DMR",0)
    setElementData(source,"CZ550",0)
    setElementData(source,"MK 48 Mod 0",0)
    setElementData(source,"M4A1 Holo Mag",0)
    setElementData(source,"DMR Mag",0)
    setElementData(source,"CZ550 Mag",0)
    setElementData(source,"M1911 Mag",0)
    setElementData(source,"PDW Mag",0)
    setElementData(source,"1866 Slug",0)
    setElementData(source,"MK 48 Mod 0 Mag",0)
    setElementData(source,"Medic Kit",0)
    setElementData(source,"Painkiller",0)
    setElementData(source,"Morphine",0)
    setElementData(source,"Bandage",0)
    setElementData(source,"Water Bottle",0)
    setElementData(source,"Burger",0)
    setElementData(source,"Tire",0)
    setElementData(source,"Engine",0)
    setElementData(source,"Tank Parts",0)
    setElementData(source,"Camouflage Clothing",0)
    setElementData(source,"Army Clothing",0)
    setElementData(source,"Ghost Clothing",0)
    setElementData(source,"K.B.K Backpack",0)
    setElementData(source,"Ghillie Suit",0)
    setElementData(source,"Civilian Clothing",0)
    setElementData(source,"GPS",0)
    setElementData(source,"Map",0)
    setElementData(source,"Toolbox",0)
end
)addEventHandler("onPlayerLogin",root,
function ()
    setElementData(source,"PDW",0)
    setElementData(source,"Winchester 1866",0)
    setElementData(source,"M1911",0)
    setElementData(source,"AK-107",0)
    setElementData(source,"M4A1 Holo",0)
    setElementData(source,"DMR",0)
    setElementData(source,"CZ550",0)
    setElementData(source,"MK 48 Mod 0",0)
    setElementData(source,"M4A1 Holo Mag",0)
    setElementData(source,"DMR Mag",0)
    setElementData(source,"CZ550 Mag",0)
    setElementData(source,"M1911 Mag",0)
    setElementData(source,"PDW Mag",0)
    setElementData(source,"1866 Slug",0)
    setElementData(source,"MK 48 Mod 0 Mag",0)
    setElementData(source,"Medic Kit",0)
    setElementData(source,"Painkiller",0)
    setElementData(source,"Morphine",0)
    setElementData(source,"Bandage",0)
    setElementData(source,"Water Bottle",0)
    setElementData(source,"Burger",0)
    setElementData(source,"Tire",0)
    setElementData(source,"Engine",0)
    setElementData(source,"Tank Parts",0)
    setElementData(source,"Camouflage Clothing",0)
    setElementData(source,"Army Clothing",0)
    setElementData(source,"Ghost Clothing",0)
    setElementData(source,"K.B.K Backpack",0)
    setElementData(source,"Ghillie Suit",0)
    setElementData(source,"Civilian Clothing",0)
    setElementData(source,"GPS",0)
    setElementData(source,"Map",0)
    setElementData(source,"Toolbox",0)
end
)

Also done simple changes to client side code;

Client Side :-

local items = {
--items,cena(K.B.K Points)
{"M1911",50},
{"PDW",150},
{"Winchester 1866",150},
{"AK-107",300},
{"M4A1 Holo",300},
{"MK 48 Mod 0",450},
{"CZ550",300},
{"DMR",400},
{"M1911 Mag",50},
{"PDW Mag",100},
{"1866 Slug",125},
{"AK-107 Mag",100},
{"M4A1 Holo Mag",50},
{"MK 48 Mod 0 Mag",200},
{"CZ550 Mag",50},
{"DMR Mag",25},
{"Medic Kit",50},
{"Painkiller",10},
{"Morphine",10},
{"Bandage",5},
{"Water Bottle",15},
{"Burger",15},
{"Tire",75},
{"Engine",125},
{"Tank Parts",50},
{"Camouflage Clothing",100},
{"Army Clothing",150},
{"Ghost Clothing",200},
{"K.B.K Backpack",150},
{"Ghillie Suit",200},
{"Civilian Clothing",30},
{"GPS",15},
{"Map",15},
{"Toolbox",25}, 
}

SHOP = {
    button = {},
    window = {},
    gridlist = {},
    label = {}
}
addEventHandler("onClientResourceStart", resourceRoot,
    function()
        
        SHOP.window[1]  = guiCreateWindow(0.17, 0.23, 0.65, 0.55, "Kill Or Be Killed Shop", true)
        guiWindowSetMovable(SHOP.window[1], false)
        guiWindowSetSizable(SHOP.window[1], false)
        guiSetProperty(SHOP.window[1], "CaptionColour", "FF075205")

        SHOP.gridlist[1] = guiCreateGridList(0.01, 0.06, 0.97, 0.63, true, SHOP.window[1])
        column = guiGridListAddColumn(SHOP.gridlist[1], "Item", 0.5)
        column2 =guiGridListAddColumn(SHOP.gridlist[1], "K.B.K Points", 0.5)
       for _, v in ipairs(items) do
            local row = guiGridListAddRow ( SHOP.gridlist[1] )
            guiGridListSetItemText ( SHOP.gridlist[1], row, column, v[1], false, false )
            guiGridListSetItemText ( SHOP.gridlist[1], row, column2, v[2].."", false, false )
        end
        guiSetProperty(SHOP.gridlist[1], "SortSettingEnabled", "False")
        SHOP.label[1] = guiCreateLabel(0.02, 0.69, 0.97, 0.08, "Select item which you want to buy! \nThe shop value is K.B.K Points", true, SHOP.window[1])
        guiLabelSetColor( SHOP.label[1],255,255,255)
        guiSetFont(SHOP.label[1], "default-bold-small")
        guiLabelSetHorizontalAlign(SHOP.label[1], "center", true)
        guiLabelSetVerticalAlign(SHOP.label[1], "center")
        SHOP.button[1] = guiCreateButton(0.35, 0.79, 0.30, 0.12, "BUY", true, SHOP.window[1])
        guiSetFont(SHOP.button[1], "default-bold-small") 
        guiSetVisible ( SHOP.window[1], false )  
        addEventHandler ( "onClientGUIClick", SHOP.gridlist[1], click ) 
        addEventHandler ( "onClientGUIClick", SHOP.button[1], buttonClick ) 
    end
)

bindKey ( "f4", "down", function ( )
    if getElementData(localPlayer, "logedin") then
       -- if getElementData   (getLocalPlayer(),"playerlevel") >= 3 then
        local state = ( not guiGetVisible (SHOP.window[1]) )
        guiSetVisible ( SHOP.window[1], state )
        showCursor ( state )
 --   else
       -- outputChatBox   (" 3!")
  --  end
end
    end
)
function buttonClick(button)
    if getElementData(localPlayer, "logedin") then
        if button == "left" then
          local nRow, nColumn = guiGridListGetSelectedItem( SHOP.gridlist[1] ) 
            if nRow ~= -1 and nColumn ~= - 1 then
              local selectedItem = guiGridListGetItemText (  SHOP.gridlist[1], guiGridListGetSelectedItem (  SHOP.gridlist[1] ), 1 )
              local price =  guiGridListGetItemText (  SHOP.gridlist[1], guiGridListGetSelectedItem (  SHOP.gridlist[1] ), 2 )
              local money = getPlayerMoney(thePlayer)
                if (money) >= tonumber(price) then
                    guiLabelSetColor( SHOP.label[1],255,255,255)
                    --  guiSetText( SHOP.label[1],"pietiek nauda")
                    setPlayerMoney(money -tonumber(price))
                    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
                    guiLabelSetColor( SHOP.label[1],10,255,10)
                    guiSetText( SHOP.label[1],"You succesfully bought "..selectedItem.." and you still have "..(money -tonumber(price)).." K.B.K Points")
                else
				    outputChatBox("no enough money !",255,0,0)
				end
			else
                guiLabelSetColor( SHOP.label[1],255,10,10)
                guiSetText( SHOP.label[1],"You are missing "..(price -tonumber(money)).." K.B.K Points")
            end
        else
            guiSetText( SHOP.label[1],"Select something first")
            guiLabelSetColor( SHOP.label[1],255,255,255) 
        end
    end
end

function click () 
       local selectedItem = guiGridListGetItemText (  SHOP.gridlist[1], guiGridListGetSelectedItem (  SHOP.gridlist[1] ), 1 )
        local price =  guiGridListGetItemText (  SHOP.gridlist[1], guiGridListGetSelectedItem (  SHOP.gridlist[1] ), 2 )
       guiSetText( SHOP.label[1],"To buy "..selectedItem.." for "..price.." K.B.K Points press button below")
       guiLabelSetColor( SHOP.label[1],255,255,255)
end

Just check it out ! ;)

  • Like 1
Link to comment

In line 99 of Client Side, you can see;

setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)

You can change '+1' in the argument to any number you wish.

And if you want to up the value of  'MK 48 Mod 0 Mag' only, you had to check it like below;

if selectedItem == "MK 48 Mod 0 Mag" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+100)
else
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
end

 

Edited by DeadthStrock
  • Like 1
Link to comment

Hey @DeadthStrock one more qeustion, sorry for bothering you tough, I did what you said with this.

On 02/12/2018 at 03:50, DeadthStrock said:

In line 99 of Client Side, you can see;


setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)

You can change '+1' in the argument to any number you wish.

And if you want to up the value of  'MK 48 Mod 0 Mag' only, you had to check it like below;


if selectedItem == "MK 48 Mod 0 Mag" then    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+100)else    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)end

 

 

But it started getting weird and all items give wrong numbers, for example the mk 48 mod mag gives you 101 rounds. Any way to fix it? This is the code im using right now on client side is

 

local items = {
--items,cena(K.B.K Points)
{"M1911",50},
{"PDW",150},
{"Winchester 1866",150},
{"AK-107",300},
{"Lee Enfield",400},
{"M4A1 Holo",300},
{"MK 48 Mod 0",450},
{"CZ550",300},
{"DMR",400},
{"M1911 Mag",50},
{"PDW Mag",100},
{"1866 Slug",125},
{"AK-107 Mag",100},
{"M4A1 Holo Mag",50},
{"MK 48 Mod 0 Mag",200},
{"Lee Enfield Mag",70},
{"CZ550 Mag",50},
{"DMR Mag",25},
{"Medic Kit",50},
{"Painkiller",10},
{"Morphine",10},
{"Bandage",5},
{"Water Bottle",15},
{"Burger",15},
{"Tire",75},
{"Engine",125},
{"Tank Parts",50},
{"Camouflage Clothing",100},
{"Army Clothing",150},
{"Ghost Clothing",200},
{"K.B.K Backpack",150},
{"Ghillie Suit",200},
{"Civilian Clothing",30},
{"GPS",15},
{"Map",15},
{"Toolbox",25}, 
}

SHOP = {
    button = {},
    window = {},
    gridlist = {},
    label = {}
}
addEventHandler("onClientResourceStart", resourceRoot,
    function()
        
        SHOP.window[1]  = guiCreateWindow(0.17, 0.23, 0.65, 0.55, "Kill Or Be Killed Shop", true)
        guiWindowSetMovable(SHOP.window[1], false)
        guiWindowSetSizable(SHOP.window[1], false)
        guiSetProperty(SHOP.window[1], "CaptionColour", "FF075205")

        SHOP.gridlist[1] = guiCreateGridList(0.01, 0.06, 0.97, 0.63, true, SHOP.window[1])
        column = guiGridListAddColumn(SHOP.gridlist[1], "Item", 0.5)
        column2 =guiGridListAddColumn(SHOP.gridlist[1], "K.B.K Points", 0.5)
       for _, v in ipairs(items) do
            local row = guiGridListAddRow ( SHOP.gridlist[1] )
            guiGridListSetItemText ( SHOP.gridlist[1], row, column, v[1], false, false )
            guiGridListSetItemText ( SHOP.gridlist[1], row, column2, v[2].."", false, false )
        end
        guiSetProperty(SHOP.gridlist[1], "SortSettingEnabled", "False")
        SHOP.label[1] = guiCreateLabel(0.02, 0.69, 0.97, 0.08, "Select item which you want to buy! \nThe shop value is K.B.K Points", true, SHOP.window[1])
        guiLabelSetColor( SHOP.label[1],255,255,255)
        guiSetFont(SHOP.label[1], "default-bold-small")
        guiLabelSetHorizontalAlign(SHOP.label[1], "center", true)
        guiLabelSetVerticalAlign(SHOP.label[1], "center")
        SHOP.button[1] = guiCreateButton(0.35, 0.79, 0.30, 0.12, "BUY", true, SHOP.window[1])
        guiSetFont(SHOP.button[1], "default-bold-small") 
        guiSetVisible ( SHOP.window[1], false )  
        addEventHandler ( "onClientGUIClick", SHOP.gridlist[1], click ) 
        addEventHandler ( "onClientGUIClick", SHOP.button[1], buttonClick ) 
    end
)

bindKey ( "f4", "down", function ( )
    if getElementData(localPlayer, "logedin") then
       -- if getElementData   (getLocalPlayer(),"playerlevel") >= 3 then
        local state = ( not guiGetVisible (SHOP.window[1]) )
        guiSetVisible ( SHOP.window[1], state )
        showCursor ( state )
 --   else
       -- outputChatBox   (" 3!")
  --  end
end
    end
)
function buttonClick(button)
    if getElementData(localPlayer, "logedin") then
        if button == "left" then
          local nRow, nColumn = guiGridListGetSelectedItem( SHOP.gridlist[1] ) 
            if nRow ~= -1 and nColumn ~= - 1 then
              local selectedItem = guiGridListGetItemText (  SHOP.gridlist[1], guiGridListGetSelectedItem (  SHOP.gridlist[1] ), 1 )
              local price =  guiGridListGetItemText (  SHOP.gridlist[1], guiGridListGetSelectedItem (  SHOP.gridlist[1] ), 2 )
              local money = getPlayerMoney(thePlayer)
                if (money) >= tonumber(price) then
                
                
                
                    guiLabelSetColor( SHOP.label[1],255,255,255)
                    --  guiSetText( SHOP.label[1],"pietiek nauda")
                    setPlayerMoney(money -tonumber(price))
    if selectedItem == selectedItem then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    else
    end
                    
    if selectedItem == "MK 48 Mod 0 Mag" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+100)
    else
    end
    
    if selectedItem == "M4A1 Holo Mag" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+20)
    end
    
    if selectedItem == "AK-107 Mag" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+30)
    end
    
    if selectedItem == "DMR Mag" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+5)
    end
    
    if selectedItem == "CZ550 Mag" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+10)
    end
    
    if selectedItem == "PDW Mag" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+30)
    end
    
    if selectedItem == "M1911 Mag" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+10)
    end
    
    if selectedItem == "1866 slug" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+7)
    end
    
    if selectedItem == "Lee Enfield Mag" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+10)
    end
    
                    guiLabelSetColor( SHOP.label[1],10,255,10)
                    guiSetText( SHOP.label[1],"You succesfully bought "..selectedItem.." and you still have "..(money -tonumber(price)).." K.B.K Points")
                else
                    outputChatBox("no enough money !",255,0,0)
                end
            else
                guiLabelSetColor( SHOP.label[1],255,10,10)
                guiSetText( SHOP.label[1],"You are missing "..(price -tonumber(money)).." K.B.K Points")
            end
        else
            guiSetText( SHOP.label[1],"Select something first")
            guiLabelSetColor( SHOP.label[1],255,255,255) 
        end
    end
end

function click () 
       local selectedItem = guiGridListGetItemText (  SHOP.gridlist[1], guiGridListGetSelectedItem (  SHOP.gridlist[1] ), 1 )
        local price =  guiGridListGetItemText (  SHOP.gridlist[1], guiGridListGetSelectedItem (  SHOP.gridlist[1] ), 2 )
       guiSetText( SHOP.label[1],"To buy "..selectedItem.." for "..price.." K.B.K Points press button below")
       guiLabelSetColor( SHOP.label[1],255,255,255)
end





What im thinking is it first checks that selecteditems should give you +1, and then it also checks the mk mod 48 mag that gives you +100 and therefore it gives the player 101bullets, how do i make only check the selcteditems, and if it checks the mk mod it shoulnt check the other stuff.

Link to comment

Nevermind, i fixed it by adding +1 for all the other items instead of else +1 as you can see below ive added a bit of the code i edited. Is there a way to group these into tabs? Like weapons, mags, car parts and etc... ??

 

 

                    guiLabelSetColor( SHOP.label[1],255,255,255)
                    --  guiSetText( SHOP.label[1],"pietiek nauda")
                    setPlayerMoney(money -tonumber(price))
                    
    if selectedItem == "M1911" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
                    
    if selectedItem == "PDW" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
                    
    if selectedItem == "Winchester 1866" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "AK-107" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "Lee Enfield" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "M4A1 Holo" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "MK 48 Mod 0" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "CZ550" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "DMR" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
    if selectedItem == "MK 48 Mod 0 Mag" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+100)
    end
    
    if selectedItem == "M4A1 Holo Mag" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+20)
    end
    
    if selectedItem == "AK-107 Mag" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+30)
    end
    
    if selectedItem == "DMR Mag" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+5)
    end
    
    if selectedItem == "CZ550 Mag" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+10)
    end
    
    if selectedItem == "PDW Mag" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+30)
    end
    
    if selectedItem == "M1911 Mag" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+10)
    end
    
    if selectedItem == "1866 slug" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+7)
    end
    
    if selectedItem == "Lee Enfield Mag" then
    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+10)
    end
    
        if selectedItem == "Medic Kit" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "Painkiller" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "Morphine" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "Bandage" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "Water Bottle" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "Burger" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "Tire" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "Engine" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "Tank Parts" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "Camouflage Clothing" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "Army Clothing" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "Ghost Clothing" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "K.B.K Backpack" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "Ghillie Suit" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
    
        if selectedItem == "Civilian Clothing" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
            if selectedItem == "GPS" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
            if selectedItem == "Map" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end
            if selectedItem == "Toolbox" then
        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
    end

 

This is how the gui looks now, but i want to add tabs as mentioned in my above comment.

https://imgur.com/a/pvwX0tX

Link to comment
14 hours ago, Quenix said:

What im thinking is it first checks that selecteditems should give you +1, and then it also checks the mk mod 48 mag that gives you +100 and therefore it gives the player 101bullets, how do i make only check the selcteditems, and if it checks the mk mod it shoulnt check the other stuff.

 

14 hours ago, Quenix said:

Nevermind, i fixed it by adding +1 for all the other items instead of else +1

or you can do the code like following;

this only the 'buttonClick' function.

function buttonClick(button,state)
    if getElementData(localPlayer, "logedin") then
        if button == "left" and state == "up" then
          local nRow, nColumn = guiGridListGetSelectedItem( SHOP.gridlist[1] ) 
            if nRow ~= -1 and nColumn ~= - 1 then
              local selectedItem = guiGridListGetItemText (  SHOP.gridlist[1], guiGridListGetSelectedItem (  SHOP.gridlist[1] ), 1 )
              local price =  guiGridListGetItemText (  SHOP.gridlist[1], guiGridListGetSelectedItem (  SHOP.gridlist[1] ), 2 )
              local money = getPlayerMoney(thePlayer)
                if (money) >= tonumber(price) then
                    guiLabelSetColor( SHOP.label[1],255,255,255)
                    --  guiSetText( SHOP.label[1],"pietiek nauda")
                    setPlayerMoney(money -tonumber(price))
					if selectedItem == "MK 48 Mod 0 Mag" then
					    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+100)
					elseif selectedItem == "M4A1 Holo Mag" then
					    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+20)
					elseif selectedItem == "AK-107 Mag" then
					    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+30)
					elseif selectedItem == "DMR Mag" then
					    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+5)
					elseif selectedItem == "CZ550 Mag" then
					    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+10)
					elseif selectedItem == "PDW Mag" then
					    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+30)
					elseif selectedItem == "M1911 Mag" then
					    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+10)
					elseif selectedItem == "1866 slug" then
					    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+7)
					elseif selectedItem == "Lee Enfield Mag" then
					    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+10)
					else
					    setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
					end
                    guiLabelSetColor( SHOP.label[1],10,255,10)
                    guiSetText( SHOP.label[1],"You succesfully bought "..selectedItem.." and you still have "..(money -tonumber(price)).." K.B.K Points")
                else
                    outputChatBox("no enough money !",255,0,0)
                end
            else
                guiLabelSetColor( SHOP.label[1],255,10,10)
                guiSetText( SHOP.label[1],"You are missing "..(price -tonumber(money)).." K.B.K Points")
            end
        else
            guiSetText( SHOP.label[1],"Select something first")
            guiLabelSetColor( SHOP.label[1],255,255,255) 
        end
    end
end

 

  • Thanks 1
Link to comment

First of all sorry for late !

I just edit some of code in client side. The item table also divided into 3 parts. I just divided them to show you the method. They are not divided correctly. You should fix them. You can understand below code. Examine it well. Server code remains same.


local items = {
--items,cena(K.B.K Points)

    porsion1List = {
        {"M1911",50},
        {"PDW",150},
        {"Winchester 1866",150},
        {"AK-107",300},
        {"Lee Enfield",400},
        {"M4A1 Holo",300},
        {"MK 48 Mod 0",450},
        {"CZ550",300},
        {"DMR",400}
    },
	
	porsion2List = {
        {"M1911 Mag",50},
        {"PDW Mag",100},
        {"1866 Slug",125},
        {"AK-107 Mag",100},
        {"M4A1 Holo Mag",50},
        {"MK 48 Mod 0 Mag",200},
        {"Lee Enfield Mag",70},
        {"CZ550 Mag",50},
        {"DMR Mag",25},
        {"Medic Kit",50},
        {"Painkiller",10},
        {"Morphine",10},
        {"Bandage",5},
        {"Water Bottle",15},
        {"Burger",15}
	},
	
	porsion3List = {
        {"Tire",75},
        {"Engine",125},
        {"Tank Parts",50},
        {"Camouflage Clothing",100},
        {"Army Clothing",150},
        {"Ghost Clothing",200},
        {"K.B.K Backpack",150},
        {"Ghillie Suit",200},
        {"Civilian Clothing",30},
        {"GPS",15},
        {"Map",15},
        {"Toolbox",25}
	}
}

SHOP = {
    button = {},
    window = {},
    label = {},
	tabpanel = {},
    tab = {},
	panel = {}
}

addEventHandler("onClientResourceStart", resourceRoot,
    function()
        SHOP.window[1] = guiCreateWindow(0.16, 0.26, 0.65, 0.55, "Kill Or Be Killed Shop", true)
        guiWindowSetMovable(SHOP.window[1], false)
        guiWindowSetSizable(SHOP.window[1], false)
        guiSetProperty(SHOP.window[1], "CaptionColour", "FFFF0000")
        SHOP.label[1] = guiCreateLabel(0.02, 0.69, 0.97, 0.08, "Select item which you want to buy! \nThe shop value is K.B.K Points", true, SHOP.window[1])
        guiSetFont(SHOP.label[1], "default-bold-small")
        guiLabelSetHorizontalAlign(SHOP.label[1], "center", true)
        guiLabelSetVerticalAlign(SHOP.label[1], "center")
        SHOP.button[1] = guiCreateButton(0.35, 0.79, 0.30, 0.12, "BUY", true, SHOP.window[1])
        guiSetFont(SHOP.button[1], "default-bold-small")
        SHOP.tabpanel[1] = guiCreateTabPanel(40, 33, 587, 240, false, SHOP.window[1])
		
        SHOP.tab[1] = guiCreateTab("Porsion 1", SHOP.tabpanel[1])
        SHOP.panel[1] = guiCreateGridList(0.01, 0.03, 0.98, 0.92, true, SHOP.tab[1])
        guiGridListAddColumn(SHOP.panel[1], "Item", 0.5)
        guiGridListAddColumn(SHOP.panel[1], "Price", 0.5)
        for i,v in pairs ( items.porsion1List ) do
            local row = guiGridListAddRow ( SHOP.panel[1] )
            guiGridListSetItemText ( SHOP.panel[1], row, 1, v[1], false, false )
            guiGridListSetItemText ( SHOP.panel[1], row, 2, v[2].."", false, false )
        end
		
        SHOP.tab[2] = guiCreateTab("Porsion 2", SHOP.tabpanel[1])
        SHOP.panel[2] = guiCreateGridList(0.01, 0.03, 0.97, 0.92, true, SHOP.tab[2])
        guiGridListAddColumn(SHOP.panel[2], "Item", 0.5)
        guiGridListAddColumn(SHOP.panel[2], "Price", 0.5)
        for i,v in pairs ( items.porsion2List ) do
            local row = guiGridListAddRow ( SHOP.panel[2] )
            guiGridListSetItemText ( SHOP.panel[2], row, 1, v[1], false, false )
            guiGridListSetItemText ( SHOP.panel[2], row, 2, v[2].."", false, false )
        end

        SHOP.tab[3] = guiCreateTab("Porsion 3", SHOP.tabpanel[1])
        SHOP.panel[3] = guiCreateGridList(0.01, 0.03, 0.97, 0.92, true, SHOP.tab[3])
        guiGridListAddColumn(SHOP.panel[3], "Item", 0.5)
        guiGridListAddColumn(SHOP.panel[3], "Price", 0.5)
        for i,v in pairs ( items.porsion3List ) do
            local row = guiGridListAddRow ( SHOP.panel[3] )
            guiGridListSetItemText ( SHOP.panel[3], row, 1, v[1], false, false )
            guiGridListSetItemText ( SHOP.panel[3], row, 2, v[2].."", false, false )
        end
		guiSetVisible(SHOP.window[1],false)
		addEventHandler ( "onClientGUIClick", SHOP.panel[1], click )
		addEventHandler ( "onClientGUIClick", SHOP.panel[2], click )
		addEventHandler ( "onClientGUIClick", SHOP.panel[3], click ) 
        addEventHandler ( "onClientGUIClick", SHOP.button[1], buttonClick ) 
    end
)
bindKey ( "f4", "down", function ( )
    if getElementData(localPlayer, "logedin") then
       -- if getElementData   (getLocalPlayer(),"playerlevel") >= 3 then
      local state = ( not guiGetVisible (SHOP.window[1]) )
		if not getElementData(localPlayer,"shop.viewing") then setElementData(localPlayer,"shop.viewing",1) end
        guiSetVisible ( SHOP.window[1], state )
        showCursor ( state )
		if guiGetVisible(SHOP.window[1]) == false then
		    removeEventHandler ( "onClientGUIClick", root, onSwitch )
		else
		    addEventHandler ( "onClientGUIClick", root, onSwitch )
		end
 --   else
       -- outputChatBox   (" 3!")
  --  end
end
    end
)
function buttonClick(button,state)
    if getElementData(localPlayer, "logedin") then
        if button == "left" and state == "up" then
		    if getElementData(localPlayer,"shop.viewing") then
			    o = getElementData(localPlayer,"shop.viewing")
              local nRow, nColumn = guiGridListGetSelectedItem( SHOP.panel[o] ) 
                if nRow ~= -1 and nColumn ~= - 1 then
                  local selectedItem = guiGridListGetItemText (  SHOP.panel[o], guiGridListGetSelectedItem (  SHOP.panel[o] ), 1 )
                  local price =  guiGridListGetItemText (  SHOP.panel[o], guiGridListGetSelectedItem (  SHOP.panel[o] ), 2 )
                  local money = getPlayerMoney(thePlayer)
                    if (money) >= tonumber(price) then
                        guiLabelSetColor( SHOP.label[1],255,255,255)
                        --  guiSetText( SHOP.label[1],"pietiek nauda")
                        setPlayerMoney(money -tonumber(price))
					    if selectedItem == "MK 48 Mod 0 Mag" then
					        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+100)
					    elseif selectedItem == "M4A1 Holo Mag" then
					        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+20)
					    elseif selectedItem == "AK-107 Mag" then
					        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+30)
					    elseif selectedItem == "DMR Mag" then
					        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+5)
					    elseif selectedItem == "CZ550 Mag" then
					        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+10)
					    elseif selectedItem == "PDW Mag" then
					        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+30)
					    elseif selectedItem == "M1911 Mag" then
					        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+10)
					    elseif selectedItem == "1866 slug" then
					        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+7)
					    elseif selectedItem == "Lee Enfield Mag" then
					        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+10)
					    else
					        setElementData(getLocalPlayer(),selectedItem,getElementData(getLocalPlayer(),selectedItem)+1)
					    end
                        guiLabelSetColor( SHOP.label[1],10,255,10)
                        guiSetText( SHOP.label[1],"You succesfully bought "..selectedItem.." and you still have "..(money -tonumber(price)).." K.B.K Points")
                    else
                        outputChatBox("no enough money !",255,0,0)
					end
                end
            else
                guiLabelSetColor( SHOP.label[1],255,10,10)
                guiSetText( SHOP.label[1],"You are missing "..(price -tonumber(money)).." K.B.K Points")
            end
        else
            guiSetText( SHOP.label[1],"Select something first")
            guiLabelSetColor( SHOP.label[1],255,255,255) 
        end
    end
end

function onSwitch()
    if source == SHOP.panel[1] then
	    setElementData(localPlayer,"shop.viewing",1)
	elseif source == SHOP.panel[2] then
	    setElementData(localPlayer,"shop.viewing",2)
	elseif source == SHOP.panel[3] then
	    setElementData(localPlayer,"shop.viewing",3)
	end
end

function click ()
    if source == SHOP.panel[1] or source == SHOP.panel[2] or source == SHOP.panel[3] then
      local selectedItem = guiGridListGetItemText (  source, guiGridListGetSelectedItem (  source ), 1 )
	  local price =  guiGridListGetItemText (  source, guiGridListGetSelectedItem (  source ), 2 )
        guiSetText( SHOP.label[1],"To buy "..selectedItem.." for "..price.." K.B.K Points press button below")
        guiLabelSetColor( SHOP.label[1],255,255,255)
	end
end

 

  • Like 2
Link to comment

@DeadthStrock Yes i understand correctly, the porsionlists are different tabs, ill categories the items correct. THank you so much for all this help!!!

@DeadthStrock, if i want to dxDrawImage on the right when you click an item, for example you click ak and it draws an ak picture on the right so you can see what you are buying, how do i do this together with the click button code?

  • Like 1
Link to comment

I was thinking about using this function which is already in the client sided code. But i think i need to make a table for each item, and their picture name. is that correcT?

function click ()
    if source == SHOP.panel[1] or source == SHOP.panel[2] or source == SHOP.panel[3] then
      local selectedItem = guiGridListGetItemText (  source, guiGridListGetSelectedItem (  source ), 1 )
    end
end

 

Link to comment

Quick Hint :-

If you want to draw a DX image with the item click, you can use this trick. Rename the images how it appears in the gridlist's first column. Then, when customer click on one of our 3 gridlists, take the selected text of gridlist as a variable and draw image according to it.

  • Like 2
Link to comment

Ok so this is what i came to after you gave me the tips, its working when i click on mk mod or ak it shows those pictures, but the pictures overlap eachother and dont dissapear after i close the gui, how do i check if the customer is clicking another item so the first picture gets destroyed and when gui closes the image also destroys/gets removed?

 

 

function click ()
    if source == SHOP.panel[1] or source == SHOP.panel[2] or source == SHOP.panel[3] or source == SHOP.panel[4] or source == SHOP.panel[5] then
      local selectedItem = guiGridListGetItemText (  source, guiGridListGetSelectedItem (  source ), 1 )
	  local price =  guiGridListGetItemText (  source, guiGridListGetSelectedItem (  source ), 2 )
        guiSetText( SHOP.label[1],"To buy "..selectedItem.." for "..price.." K.B.K Points press button below")
        guiLabelSetColor( SHOP.label[1],255,255,255)
		guiCreateStaticImage( 500, 500, 400, 400, selectedItem..".png", false )
		

end
end

 

Edited by Quenix
Link to comment

Test this;

function click ()
    if source == SHOP.panel[1] or source == SHOP.panel[2] or source == SHOP.panel[3] or source == SHOP.panel[4] or source == SHOP.panel[5] then
      local selectedItem = guiGridListGetItemText (  source, guiGridListGetSelectedItem (  source ), 1 )
	  local price =  guiGridListGetItemText (  source, guiGridListGetSelectedItem (  source ), 2 )
        guiSetText( SHOP.label[1],"To buy "..selectedItem.." for "..price.." K.B.K Points press button below")
        guiLabelSetColor( SHOP.label[1],255,255,255)
		if isElement(itemImage) then
		    destroyElement(itemImage)
			itemImage = guiCreateStaticImage( 500, 500, 400, 400, selectedItem..".png", false )
		else
		    itemImage = guiCreateStaticImage( 500, 500, 400, 400, selectedItem..".png", false )
		end
	end
end

 

  • Like 1
  • Thanks 1
Link to comment

Works Like a charm. This is exactly what i did earlier, but the files with space between them, for example MK 48 Mod 0 has alot of spaces in its name, but i cant put spaces in the png names because it doesnt detect them somehow :/ @DeadthStrock  And when you choose the weapons and press f4 to close the gui. the picture is still drawn hmm

Edited by Quenix
Link to comment

I test a png image file with spaces in it's name. That png file is finding by the resource and work perfectly. And if you want to remove the image when player close the window, simply use;

bindKey ( "f4", "down", function ( )
    if getElementData(localPlayer, "logedin") then
      local state = ( not guiGetVisible (SHOP.window[1]) )
		if not getElementData(localPlayer,"shop.viewing") then setElementData(localPlayer,"shop.viewing",1) end
        guiSetVisible ( SHOP.window[1], state )
        showCursor ( state )
		if guiGetVisible(SHOP.window[1]) == false then
		    removeEventHandler ( "onClientGUIClick", root, onSwitch )
			if isElement(itemImage) then
			    destroyElement(itemImage)
			end
		else
		    addEventHandler ( "onClientGUIClick", root, onSwitch )
	    end
	end
end
)

 

  • Like 2
Link to comment
Just now, DeadthStrock said:

@Quenix

        It's my practice. Always think about your script. Every time try yourself to solve your LUA problem. Then you'll also become a god automatically ! :lol:

yes true! I always try sometimes i succed, but most of the times i dont. but when i do succed or get help i actually learn how to use those stuff so next time i know better ;)

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