Jump to content

Help needed with script Shop panel


Quenix

Recommended Posts

So @DeadthStrock i tried triggering the shop with a marker, when the player goes in the marker, the shop gui pops up for the player. I tried with hitmark but in debugscript it says that server triggered clientside event, but event is not marked as remotly triggerable. So my guess is it cant start an event from the client script becuse we are using serverside or?

This is a bit of the serverside code where i added the lines below, havnt touched anything else.

marker1 = createMarker(182.59259033203, 2821.6428222656, 67.378341674805, "cylinder", 1.5, 4, 156, 14 )

function HitMark(hitPlayer)
  triggerClientEvent (hitPlayer,"onClientGUIClick",getRootElement(),hitPlayer)
end
addEventHandler("onMarkerHit", marker1, HitMark)

Or maybe the defined "onClientGUIClick" is wrong?

Edited by Quenix
Link to comment

Well with some working around i fixed this

 

this is what I added to Client script:

function Windows()
guiSetVisible(SHOP.panel[1], true)
guiSetVisible(SHOP.window[1],true)
showCursor(true)
setElementData(localPlayer,"shop.viewing",1)
end
addEvent("openWindow1",true)
addEventHandler("openWindow1", getRootElement(), Windows)

And into server side:

marker1 = createMarker ( 177.13320922852, 2818.298828125, 68.174095153809, "cylinder", 1.5, 30, 212, 5 )
function HitMark(hitPlayer)
  triggerClientEvent (hitPlayer,"openWindow1",getRootElement(),hitPlayer)
end
addEventHandler("onMarkerHit", marker1, HitMark)

 

Link to comment

but im having problems, i added a close button to the gui, when ever i press it the gui closes but the active image at that moment is not getting destroyed? Here is the scripts with the close button added

 

Client side:

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},
        {"Water Bottle",15},
        {"Burger",15}
    },
    
    porsion3List = {
        {"Tire",75},
        {"Engine",125},
        {"Tank Parts",50}

    },
        porsion4List = {
        {"Medic Kit",50},
        {"Painkiller",10},
        {"Morphine",10},
        {"Bandage",5}
    },
        porsion5List = {
        {"Camouflage Clothing",100},
        {"Army Clothing",150},
        {"Ghost Clothing",200},
        {"K.B.K Backpack",150},
        {"Ghillie Suit",200},
        {"Civilian Clothing",30},
        {"GPS",15},
        {"Tent",60},
        {"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])
        SHOP.button[2] = guiCreateButton(0.98, 0.07, 0.02, 0.03, "X", 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("Weapons", 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("Mags", 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("Car Parts", 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
        SHOP.tab[4] = guiCreateTab("Medics", SHOP.tabpanel[1])
        SHOP.panel[4] = guiCreateGridList(0.01, 0.03, 0.97, 0.92, true, SHOP.tab[4])
        guiGridListAddColumn(SHOP.panel[4], "Item", 0.5)
        guiGridListAddColumn(SHOP.panel[4], "Price", 0.5)
        for i,v in pairs ( items.porsion4List ) do
            local row = guiGridListAddRow ( SHOP.panel[4] )
            guiGridListSetItemText ( SHOP.panel[4], row, 1, v[1], false, false )
            guiGridListSetItemText ( SHOP.panel[4], row, 2, v[2].."", false, false )
        end
        SHOP.tab[5] = guiCreateTab("Items", SHOP.tabpanel[1])
        SHOP.panel[5] = guiCreateGridList(0.01, 0.03, 0.97, 0.92, true, SHOP.tab[5])
        guiGridListAddColumn(SHOP.panel[5], "Item", 0.5)
        guiGridListAddColumn(SHOP.panel[5], "Price", 0.5)
        for i,v in pairs ( items.porsion5List ) do
            local row = guiGridListAddRow ( SHOP.panel[5] )
            guiGridListSetItemText ( SHOP.panel[5], row, 1, v[1], false, false )
            guiGridListSetItemText ( SHOP.panel[5], 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.panel[4], click ) 
        addEventHandler ( "onClientGUIClick", SHOP.panel[5], click ) 
        addEventHandler ( "onClientGUIClick", SHOP.button[1], buttonClick ) 
        addEventHandler ( "onClientGUIClick", SHOP.button[2], buttonClick )
        end
        )
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
        addEvent( "onClientGUIClick", true )
            addEventHandler ( "onClientGUIClick", root, onSwitch )
        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
    
    addEventHandler ( "onClientGUIClick", SHOP.button[1], false )
    addEventHandler ( "onClientGUIClick", SHOP.button[2],
    function()
        
        guiSetVisible(SHOP.window[1], false)
        showCursor(false)
    end, false )
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)
    elseif source == SHOP.panel[4] then
        setElementData(localPlayer,"shop.viewing",4)
            elseif source == SHOP.panel[5] then
        setElementData(localPlayer,"shop.viewing",5)
    end
end
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( 1050, 350, 450, 250, selectedItem..".png", false )
            elseif isElement () then 
             destroyElement(itemImage)
    
        else
            itemImage = guiCreateStaticImage( 1050, 350, 450, 250, selectedItem..".png", false )
        end


    end
end

function Windows()
guiSetVisible(SHOP.panel[1], true)
guiSetVisible(SHOP.window[1],true)
showCursor(true)
setElementData(localPlayer,"shop.viewing",1)
end
addEvent("openWindow1",true)
addEventHandler("openWindow1", getRootElement(), Windows)

 

 

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
)
marker1 = createMarker ( 177.13320922852, 2818.298828125, 68.174095153809, "cylinder", 1.5, 30, 212, 5 )
function HitMark(hitPlayer)
  triggerClientEvent (hitPlayer,"openWindow1",getRootElement(),hitPlayer)
end
addEventHandler("onMarkerHit", marker1, HitMark)



 

Link to comment
12 hours ago, Quenix said:

Well with some working around i fixed this

 

this is what I added to Client script:


function Windows()
guiSetVisible(SHOP.panel[1], true)
guiSetVisible(SHOP.window[1],true)
showCursor(true)
setElementData(localPlayer,"shop.viewing",1)
end
addEvent("openWindow1",true)
addEventHandler("openWindow1", getRootElement(), Windows)



And into server side:


marker1 = createMarker ( 177.13320922852, 2818.298828125, 68.174095153809, "cylinder", 1.5, 30, 212, 5 )
function HitMark(hitPlayer)
  triggerClientEvent (hitPlayer,"openWindow1",getRootElement(),hitPlayer)
end
addEventHandler("onMarkerHit", marker1, HitMark)


 

You are almost correct. Try some modifications if you want.

Client Side :-

addEvent("openWindow1",true)
function Windows()
    if guiGetVisible(SHOP.panel[1]) ~= true then
	    setElementData(localPlayer,"shop.viewing",1)
	    guiSetVisible(SHOP.window[1],true)
		showCursor(true)
	end
end
addEventHandler("openWindow1", getRootElement(), Windows)

Server Side :-

local marker1 = createMarker ( 177.13320922852, 2818.298828125, 68.174095153809, "cylinder", 1.5, 30, 212, 5 )

function HitMark(hitPlayer)
    triggerClientEvent (hitPlayer,"openWindow1",resourceRoot)
end
addEventHandler("onMarkerHit", marker1, HitMark)

 

 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

 

11 hours ago, Quenix said:

but im having problems, i added a close button to the gui, when ever i press it the gui closes but the active image at that moment is not getting destroyed? Here is the scripts with the close button added

Try below.

Client Side :-

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},
        {"Water Bottle",15},
        {"Burger",15}
    },
    
    porsion3List = {
        {"Tire",75},
        {"Engine",125},
        {"Tank Parts",50}

    },
        porsion4List = {
        {"Medic Kit",50},
        {"Painkiller",10},
        {"Morphine",10},
        {"Bandage",5}
    },
        porsion5List = {
        {"Camouflage Clothing",100},
        {"Army Clothing",150},
        {"Ghost Clothing",200},
        {"K.B.K Backpack",150},
		{"Ghillie Suit",200},
		{"Civilian Clothing",30},
        {"GPS",15},
        {"Tent",60},
        {"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])
        SHOP.button[2] = guiCreateButton(0.98, 0.07, 0.02, 0.03, "X", 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("Weapons", 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("Mags", 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("Car Parts", 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
        SHOP.tab[4] = guiCreateTab("Medics", SHOP.tabpanel[1])
        SHOP.panel[4] = guiCreateGridList(0.01, 0.03, 0.97, 0.92, true, SHOP.tab[4])
        guiGridListAddColumn(SHOP.panel[4], "Item", 0.5)
        guiGridListAddColumn(SHOP.panel[4], "Price", 0.5)
        for i,v in pairs ( items.porsion4List ) do
            local row = guiGridListAddRow ( SHOP.panel[4] )
            guiGridListSetItemText ( SHOP.panel[4], row, 1, v[1], false, false )
            guiGridListSetItemText ( SHOP.panel[4], row, 2, v[2].."", false, false )
        end
        SHOP.tab[5] = guiCreateTab("Items", SHOP.tabpanel[1])
        SHOP.panel[5] = guiCreateGridList(0.01, 0.03, 0.97, 0.92, true, SHOP.tab[5])
        guiGridListAddColumn(SHOP.panel[5], "Item", 0.5)
        guiGridListAddColumn(SHOP.panel[5], "Price", 0.5)
        for i,v in pairs ( items.porsion5List ) do
            local row = guiGridListAddRow ( SHOP.panel[5] )
            guiGridListSetItemText ( SHOP.panel[5], row, 1, v[1], false, false )
            guiGridListSetItemText ( SHOP.panel[5], row, 2, v[2].."", false, false )
        end
        guiSetVisible(SHOP.window[1],false)
        addEventHandler ( "onClientGUIClick", root, click )
        addEventHandler ( "onClientGUIClick", root, buttonClick ) 
        end
)

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
        end
    end
end
)

function buttonClick(button,state)
    if getElementData(localPlayer, "logedin") then
        if source == SHOP.button[1] and 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
        elseif source == SHOP.button[2] then
		    guiSetVisible ( SHOP.window[1], false )
			showCursor ( false )
            removeEventHandler ( "onClientGUIClick", root, onSwitch )
            if isElement(itemImage) then
                destroyElement(itemImage)
            end
        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)
    elseif source == SHOP.panel[4] then
        setElementData(localPlayer,"shop.viewing",4)
    elseif source == SHOP.panel[5] then
        setElementData(localPlayer,"shop.viewing",5)
    end
end

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( 1050, 350, 450, 250, selectedItem..".png", false )
        else
            itemImage = guiCreateStaticImage( 1050, 350, 450, 250, selectedItem..".png", false )
        end
    end
end

addEvent("openWindow1",true)
function Windows()
    if guiGetVisible(SHOP.panel[1]) ~= true then
	    if not getElementData(localPlayer,"shop.viewing") then setElementData(localPlayer,"shop.viewing",1) end
	    guiSetVisible(SHOP.window[1],true)
		showCursor(true)
	end
end
addEventHandler("openWindow1", getRootElement(), Windows)

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
)

local marker1 = createMarker ( 177.13320922852, 2818.298828125, 68.174095153809, "cylinder", 1.5, 30, 212, 5 )

function HitMark(hitPlayer)
    triggerClientEvent (hitPlayer,"openWindow1",resourceRoot)
end
addEventHandler("onMarkerHit", marker1, HitMark)

WOOH ...!! Editing is not that easy ! A little like would be very appreciate.:P

Edited by DeadthStrock
  • Like 1
Link to comment

I made a fixed resource zip for you. Check that out. And note that there are no .png images of shop items. Also, in server side code, you have not added all shop stuff's amount to "0" when player login. Thing like 'tent' are missing. add them, else they can't buy.

Click Here to redirect to the resource zip download page.

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