Well title says it all, check this
GUIEditor = {
gridlist = {},
window = {},
button = {}
}
GUIEditor.window[1] = guiCreateWindow(0.04, 0.22, 0.40, 0.71, "My Inventory", true)
guiWindowSetSizable(GUIEditor.window[1], false)
GUIEditor.gridlist[1] = guiCreateGridList(0.03, 0.07, 0.93, 0.82, true, GUIEditor.window[1])
guiGridListAddColumn(GUIEditor.gridlist[1], "Item", 0.5)
guiGridListAddColumn(GUIEditor.gridlist[1], "Amount", 0.5)
GUIEditor.button[1] = guiCreateButton(0.03, 0.89, 0.31, 0.08, "Use", true, GUIEditor.window[1])
guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FFAAAAAA")
GUIEditor.button[2] = guiCreateButton(0.66, 0.89, 0.31, 0.08, "Drop", true, GUIEditor.window[1])
guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFAAAAAA")
guiSetVisible (GUIEditor.window[1], false)
PR = {
label = {},
progressbar = {}
}
PR.progressbar[1] = guiCreateProgressBar(0.18, 0.47, 0.64, 0.06, true)
PR.label[1] = guiCreateLabel((516 - 101) / 2, (34 - 16) / 2, 101, 16, "Using Repair Kit...", false, PR.progressbar[1])
guiSetFont(PR.label[1], "default-bold-small")
guiLabelSetColor(PR.label[1], 1, 126, 253)
guiProgressBarSetProgress(PR.progressbar[1], 0)
guiSetVisible (PR.progressbar[1], false)
function openGUI (result)
if guiGetVisible (GUIEditor.window[1]) == true then
guiSetVisible (GUIEditor.window[1], false)
showCursor (false)
guiGridListClear (GUIEditor.gridlist[1], true)
outputChatBox ("Bag closed successfully !", 255,0,0)
else
guiSetVisible (GUIEditor.window[1], true)
showCursor (true)
guiGridListClear (GUIEditor.gridlist[1], true)
outputChatBox ("Bag opened successfully !", 255,255,0)
for k,v in ipairs (result) do
local row1 = guiGridListAddRow(GUIEditor.gridlist[1])
guiGridListSetItemText(GUIEditor.gridlist[1], row1, 1, v["itemname"] , false, false)
guiGridListSetItemText(GUIEditor.gridlist[1], row1, 2, v["amoun"] , false, false)
end
end
end
addEvent ("onOpenGUI", true)
addEventHandler ("onOpenGUI", root, openGUI)
function useObject ()
local item = guiGridListGetItemText(GUIEditor.gridlist[1], guiGridListGetSelectedItem(GUIEditor.gridlist[1]), 1)
local amount = guiGridListGetItemText(GUIEditor.gridlist[1], guiGridListGetSelectedItem(GUIEditor.gridlist[1]), 2)
if (source == GUIEditor.button[1]) then
if item == "Medic Kits" then
if tonumber(amount) > 0 then
local pHp = getElementHealth (localPlayer)
if tonumber (pHp) < 100 then
guiSetVisible (PR.progressbar[1], true)
guiSetText (PR.label[1], "Using Medic Kit...")
guiProgressBarSetProgress(PR.progressbar[1], 0)
setTimer (function () guiProgressBarSetProgress(PR.progressbar[1], 20)end,500,1)
setTimer (function () guiProgressBarSetProgress(PR.progressbar[1], 40)end,1000,1)
setTimer (function () guiProgressBarSetProgress(PR.progressbar[1], 60)end,1500,1)
setTimer (function () guiProgressBarSetProgress(PR.progressbar[1], 80)end,2000,1)
setTimer (function ()setElementHealth (localPlayer, pHp+30) guiProgressBarSetProgress (PR.progressbar[1],100) guiSetVisible (PR.progressbar[1], false)end,2500,1)
triggerServerEvent ("onUse", localPlayer, item)
outputChatBox ("You have taken 1 Medic Kit It will take effect in 5 seconds.", 255,255,255)
guiSetVisible (GUIEditor.window[1], false)
showCursor (false)
else
outputChatBox ("Your HP is full!", 255,0,0)
end
end
elseif item == "Food" then
if tonumber(amount) > 0 then
local pHp = getElementHealth (localPlayer)
if tonumber (getElementHealth (localPlayer)) < 100 then
guiSetVisible (PR.progressbar[1], true)
guiSetText (PR.label[1], "Eating some food...")
guiProgressBarSetProgress(PR.progressbar[1], 0)
setTimer (function () guiProgressBarSetProgress(PR.progressbar[1], 20)end,500,1)
setTimer (function () guiProgressBarSetProgress(PR.progressbar[1], 40)end,1000,1)
setTimer (function () guiProgressBarSetProgress(PR.progressbar[1], 60)end,1500,1)
setTimer (function () guiProgressBarSetProgress(PR.progressbar[1], 80)end,2000,1)
setTimer (function ()setElementHealth (localPlayer, pHp+10) guiProgressBarSetProgress (PR.progressbar[1],100) guiSetVisible (PR.progressbar[1], false)end,2500,1)
triggerServerEvent ("onUse", localPlayer, item)
outputChatBox ("You have taken some Food It will take effect in 5 seconds.", 255,255,255)
guiSetVisible (GUIEditor.window[1], false)
showCursor (false)
else
outputChatBox ("Your HP is full!", 255,0,0)
end
end
elseif item == "Repair Kits" then
if tonumber(amount) > 0 then
local vehicle = getPedOccupiedVehicle (localPlayer)
local vehHP = getElementHealth (vehicle)
if (vehicle) then
if tonumber (vehHP) < 1000 then
guiSetVisible (PR.progressbar[1], true)
setElementFrozen (localPlayer, true)
guiProgressBarSetProgress(PR.progressbar[1], 0)
setTimer (function () guiProgressBarSetProgress(PR.progressbar[1], 20)end,500,1)
setTimer (function () guiProgressBarSetProgress(PR.progressbar[1], 40)end,1000,1)
setTimer (function () guiProgressBarSetProgress(PR.progressbar[1], 60)end,1500,1)
setTimer (function () guiProgressBarSetProgress(PR.progressbar[1], 80)end,2000,1)
setTimer (function () setElementHealth (vehicle, vehHP+250) guiProgressBarSetProgress (PR.progressbar[1],100) guiSetVisible (PR.progressbar[1], false) setElementFrozen (localPlayer, false)end,2500,1)
triggerServerEvent ("onUse", localPlayer, item)
outputChatBox ("You have taken 1 Repair Kit It will take effect in 5 seconds.", 255,255,255)
guiSetVisible (GUIEditor.window[1], false)
showCursor (false)
else
outputChatBox ("Your Vehicle's HP is full!", 255,0,0)
end
else
outputChatBox ("You're not in a vehicle!",255,0,0)
end
end
else
outputChatBox ("You either can't use this item or you have 0 units of this item !" ,255,0,0)
end
end
end
addEventHandler ("onClientGUIClick", root, useObject)
function dropItem ()
local item = guiGridListGetItemText(GUIEditor.gridlist[1], guiGridListGetSelectedItem(GUIEditor.gridlist[1]), 1)
local x,y,z = getElementPosition (localPlayer)
if (source == GUIEditor.button[2]) then
if (item) then
if item == "Medic Kits" then
pickUp = createPickup ( x, y, z, 3, 1240 )
outputChatBox ("You have dropped a Medic Kit !",255,255,255)
guiSetVisible(GUIEditor.window[1], false)
showCursor(false)
dropped = "Medic Kits"
triggerServerEvent ("onUse", localPlayer, item)
elseif item == "Repair Kits" then
pickUp = createPickup ( x, y, z, 3, 1277 )
outputChatBox ("You have dropped a Repair Kit !",255,255,255)
guiSetVisible(GUIEditor.window[1], false)
showCursor(false)
dropped = "Repair Kits"
triggerServerEvent ("onUse", localPlayer, item)
elseif item == "Food" then
pickUp = createPickup ( x, y, z, 3, 2212 )
outputChatBox ("You have dropped some food !",255,255,255)
guiSetVisible(GUIEditor.window[1], false)
showCursor(false)
dropped = "Food"
triggerServerEvent ("onUse", localPlayer, item)
elseif item == "Wood" then
pickUp = createPickup ( x, y, z, 3, 1448 )
outputChatBox ("You have dropped wood !",255,255,255)
guiSetVisible(GUIEditor.window[1], false)
showCursor(false)
dropped = "Wood"
triggerServerEvent ("onUse", localPlayer, item)
elseif item == "Oil" then
pickUp = createPickup ( x, y, z, 3, 1217 )
outputChatBox ("You have dropped some Oil !",255,255,255)
guiSetVisible(GUIEditor.window[1], false)
showCursor(false)
dropped = "Oil"
triggerServerEvent ("onUse", localPlayer, item)
else
pickUp = createPickup ( x, y, z, 3, 1279 )
outputChatBox ("You have dropped a ".. item .." !",255,255,255)
guiSetVisible(GUIEditor.window[1], false)
showCursor(false)
dropped = item
triggerServerEvent ("onUse", localPlayer, item)
end
end
end
end
addEventHandler ("onClientGUIClick", root, dropItem)
function takeObject ()
triggerServerEvent ("onTakeObject", localPlayer, dropped)
end
addEventHandler ("onClientPickupHit", pickUp, takeObject)