Advertisement
Guest User

Item client side.

a guest
Apr 16th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 37.94 KB | None | 0 0
  1.     wItems, gItems, gKeys, colSlot, colName, colValue, items, lDescription, bDropItem, bUseItem, bShowItem, bDestroyItem, tabPanel, tabItems, tabWeapons = nil
  2.     gWeapons, colWSlot, colWName, colWValue = nil
  3.     toggleLabel, chkFood, chkKeys, chkDrugs, chkOther, chkBooks, chkClothes, chkElectronics, chkEmpty = nil
  4.      
  5.     wRightClick = nil
  6.     bPickup, bToggle, bPreviousTrack, bNextTrack, bCloseMenu = nil
  7.     ax, ay = nil
  8.     item = nil
  9.     showinvPlayer = nil
  10.     setElementData( getLocalPlayer(), "exclusiveGUI", false, false ) -- setting this to false prevents possible problems with fridge/shelf inv.
  11.      
  12.     showFood = true
  13.     showKeys = true
  14.     showDrugs = true
  15.     showOther = true
  16.     showBooks = true
  17.     showClothes = true
  18.     showElectronics = true
  19.     showEmpty = true
  20.     activeTab = 0
  21.      
  22.     -- PLEASE WAIT window
  23.     local sx, sy = guiGetScreenSize( )
  24.     wWait = guiCreateButton( ( sx - 200 ) / 2, ( sy - 60 ) / 2, 200, 60, "Please wait a moment...", false )
  25.     guiSetEnabled( wWait, false )
  26.     guiSetVisible( wWait, false )
  27.     guiSetProperty( wWait, "AlwaysOnTop", "True" )
  28.     function clickItem(button, state, absX, absY, x, y, z, element)
  29.         if (button == "right") and (state=="down") then
  30.             if getElementData(getLocalPlayer(), "exclusiveGUI") then
  31.                 return
  32.             end
  33.            
  34.             local px, py, pz = getElementPosition(getLocalPlayer())
  35.             if element and (getElementParent(getElementParent(element)) == getResourceRootElement(getResourceFromName("map-system")) or getElementParent(getElementParent(element)) == getResourceRootElement(getResourceFromName("interior-system"))) then
  36.                 element = nil
  37.             end
  38.            
  39.             if not element then
  40.                 local wx, wy, wz = x, y, z
  41.                 local x, y, z = nil
  42.                 for key, value in ipairs(getElementsByType("object",getResourceRootElement())) do
  43.                     if isElementStreamedIn(value) then
  44.                         x, y, z = getElementPosition(value)
  45.                         local minx, miny, minz, maxx, maxy, maxz = getElementBoundingBox(value)
  46.                        
  47.                         local offset = 0.34
  48.                        
  49.                         minx = x + minx - offset
  50.                         miny = y + miny - offset
  51.                         minz = z + minz - offset
  52.                        
  53.                         maxx = x + maxx + offset
  54.                         maxy = y + maxy + offset
  55.                         maxz = z + maxz + offset
  56.                        
  57.                         local dist = getDistanceBetweenPoints3D(x, y, z, px, py, pz)
  58.                        
  59.                         if (wx >= minx and wx <=maxx) and (wy >= miny and wy <=maxy) and (wz >= minz and wz <=maxz) then
  60.                             element = value
  61.                             break
  62.                         end
  63.                     end
  64.                 end
  65.             end
  66.                
  67.             if element and getElementParent(getElementParent(element)) == getResourceRootElement() then
  68.                 if getDistanceBetweenPoints3D(x, y, z, px, py, pz) < 3 then
  69.                     if (wRightClick) then
  70.                         hideItemMenu()
  71.                     end
  72.                     ax = absX
  73.                     ay = absY
  74.                     item = element
  75.                     showItemMenu()
  76.                 else
  77.                     outputChatBox("You are too far away from that item.", 255, 0, 0)
  78.                 end
  79.             else
  80.                 if (wRightClick) then
  81.                     hideItemMenu()
  82.                 end
  83.             end
  84.         end
  85.     end
  86.     addEventHandler("onClientClick", getRootElement(), clickItem, true)
  87.      
  88.     function showItemMenu()
  89.         local itemID = getElementData(item, "itemID")
  90.         local itemValue = getElementData(item, "itemValue")
  91.         local itemName = getItemName( itemID, itemValue )
  92.        
  93.         if itemID ~= 80 then
  94.             itemName = itemName .. " (" .. getItemValue( itemID, itemValue ) .. ")"
  95.         end
  96.         wRightClick = guiCreateWindow(ax, ay, 150, 200, itemName, false)
  97.        
  98.         local y = 0.13
  99.         if itemID == 81 or itemID == 103 then
  100.             bPickup = guiCreateButton(0.05, y, 0.9, 0.1, "Open", true, wRightClick)
  101.             addEventHandler("onClientGUIClick", bPickup,
  102.                 function(button)
  103.                     if button=="left" and not getElementData(localPlayer, "exclusiveGUI") then
  104.                         triggerServerEvent( "openFreakinInventory", getLocalPlayer(), item, ax, ay )
  105.                         hideItemMenu()
  106.                     end
  107.                 end,
  108.                 false
  109.             )
  110.         else
  111.             bPickup = guiCreateButton(0.05, y, 0.9, 0.1, "Pick Item Up", true, wRightClick)
  112.             addEventHandler("onClientGUIClick", bPickup, pickupItem, false)
  113.         end
  114.         y = y + 0.14
  115.        
  116.         if itemID == 54 then
  117.             -- Ghettoblaster
  118.             if getElementData(item, "itemValue") > 0 then
  119.                 bToggle = guiCreateButton(0.05, y, 0.9, 0.1, "Turn Off", true, wRightClick)
  120.                
  121.                 y = y + 0.14
  122.                
  123.                 bPreviousTrack = guiCreateButton(0.05, y, 0.42, 0.1, "Previous", true, wRightClick)
  124.                 addEventHandler("onClientGUIClick", bPreviousTrack, function() triggerServerEvent("changeGhettoblasterTrack", getLocalPlayer(), item, -1) end, false)
  125.                
  126.                 bNextTrack = guiCreateButton(0.53, y, 0.42, 0.1, "Next", true, wRightClick)
  127.                 addEventHandler("onClientGUIClick", bNextTrack, function() triggerServerEvent("changeGhettoblasterTrack", getLocalPlayer(), item, 1) end, false)
  128.             else
  129.                 bToggle = guiCreateButton(0.05, y, 0.9, 0.1, "Turn On", true, wRightClick)
  130.             end
  131.             addEventHandler("onClientGUIClick", bToggle, toggleGhettoblaster, false)
  132.        
  133.             y = y + 0.14
  134.         end
  135.        
  136.         bCloseMenu = guiCreateButton(0.05, y, 0.9, 0.1, "Close Menu", true, wRightClick)
  137.         addEventHandler("onClientGUIClick", bCloseMenu, hideItemMenu, false)
  138.     end
  139.      
  140.     function hideItemMenu()
  141.         if (isElement(bPickup)) then
  142.             destroyElement(bPickup)
  143.         end
  144.         bPickup = nil
  145.      
  146.         if (isElement(bToggle)) then
  147.             destroyElement(bToggle)
  148.         end
  149.         bToggle = nil
  150.      
  151.         if (isElement(bPreviousTrack)) then
  152.             destroyElement(bPreviousTrack)
  153.         end
  154.         bPreviousTrack = nil
  155.      
  156.         if (isElement(bNextTrack)) then
  157.             destroyElement(bNextTrack)
  158.         end
  159.         bNextTrack = nil
  160.      
  161.         if (isElement(bCloseMenu)) then
  162.             destroyElement(bCloseMenu)
  163.         end
  164.         bCloseMenu = nil
  165.      
  166.         if (isElement(wRightClick)) then
  167.             destroyElement(wRightClick)
  168.         end
  169.         wRightClick = nil
  170.        
  171.         ax = nil
  172.         ay = nil
  173.      
  174.         item = nil
  175.      
  176.         showCursor(false)
  177.         triggerEvent("cursorHide", getLocalPlayer())
  178.     end
  179.      
  180.     function updateMenu(dataname)
  181.         if source == item and dataname == "itemValue" and getElementData(source, "itemID") == 54 then -- update the track while you're in menu
  182.             guiSetText(wRightClick, "GHETTOBLASTER (" .. getElementData(source, "itemValue") .. ")")
  183.         end
  184.     end
  185.     addEventHandler("onClientElementDataChange", getRootElement(), updateMenu)
  186.      
  187.     function toggleGhettoblaster(button, state, absX, absY, step)
  188.         triggerServerEvent("toggleGhettoblaster", getLocalPlayer(), item)
  189.         hideItemMenu()
  190.     end
  191.      
  192.     function pickupItem(button, state, item)
  193.         if (button=="left") then
  194.             local restrain = getElementData(getLocalPlayer(), "restrain")
  195.            
  196.             if (restrain) and (restrain==1) then
  197.                 outputChatBox("You are cuffed.", 255, 0, 0)
  198.             elseif getElementData(item, "itemID") > 0 and not hasSpaceForItem(getLocalPlayer(), getElementData(item, "itemID")) then
  199.                 outputChatBox("Your Inventory is full.", 255, 0, 0)
  200.             elseif isElement(item) then
  201.                 if wRightClick then
  202.                     showCursor(false)
  203.                     triggerEvent("cursorHide", getLocalPlayer())
  204.                 end
  205.                
  206.                 local itemID = tonumber(getElementData(item, "itemID")) or 0
  207.                 local itemValue = tonumber(getElementData(item, "itemValue")) or 0
  208.                 if itemID < 0 and itemID ~= -100 then
  209.                     local free, totalfree = exports.weaponcap:getFreeAmmo( -itemID )
  210.                     local cap = exports.weaponcap:getAmmoCap( -itemID )
  211.                     if totalfree == 0 then
  212.                         outputChatBox( "You've got all weapons you can carry.", 255, 0, 0 )
  213.                     elseif free == 0 and cap == 0 then
  214.                         local weaponName = "other weapon"
  215.                         local slot = getSlotFromWeapon( -itemID )
  216.                         if slot and slot ~= 0 and getPedTotalAmmo( getLocalPlayer(), slot ) > 0 then
  217.                             local weapon = getPedWeapon( getLocalPlayer(), slot )
  218.                             weaponName = getItemName( -weapon )
  219.                         end
  220.                         outputChatBox( "You don't carry that weapon, please drop your " .. weaponName .. " first.", 255, 0, 0 )
  221.                     elseif free == 0 then
  222.                         outputChatBox( "You can't carry any more of that weapon.", 255, 0, 0 )
  223.                     else
  224.                         triggerServerEvent("pickupItem", getLocalPlayer(), item, free )
  225.                     end
  226.                 else
  227.                     triggerServerEvent("pickupItem", getLocalPlayer(), item)
  228.                 end
  229.                 if wRightClick then
  230.                     hideItemMenu()
  231.                 end
  232.             end
  233.         end
  234.     end
  235.        
  236.     function toggleCategory()
  237.         if (source==chkFood) then
  238.             showFood = not showFood
  239.         elseif (source==chkKeys) then
  240.             showKeys = not showKeys
  241.         elseif (source==chkDrugs) then
  242.             showDrugs = not showDrugs
  243.         elseif (source==chkBooks) then
  244.             showBooks = not showBooks
  245.         elseif (source==chkClothes) then
  246.             showClothes = not showClothes
  247.         elseif (source==chkElectronics) then
  248.             showElectronics = not showElectronics
  249.         elseif (source==chkOther) then
  250.             showOther = not showOther
  251.         elseif (source==chkEmpty) then
  252.             showEmpty = not showEmpty
  253.         end
  254.        
  255.         -- let's add the items again
  256.         if (isElement(gItems)) then
  257.             guiGridListClear(gItems)
  258.         end
  259.        
  260.         if (isElement(gKeys)) then
  261.             guiGridListClear(gKeys)
  262.         end
  263.        
  264.         local items, slots = getItems( showinvPlayer ), getInventorySlots( showinvPlayer )
  265.        
  266.         for i = 1, 3 * slots do
  267.             if not items[i] then
  268.                 if showEmpty and i <= slots then
  269.                     local row = guiGridListAddRow(gItems)
  270.                     guiGridListSetItemText(gItems, row, colSlot, tostring(row+1), false, true)
  271.                     guiGridListSetItemText(gItems, row, colName, "Empty", false, false)
  272.                     guiGridListSetItemText(gItems, row, colValue, "None", false, false)
  273.                 end
  274.             else
  275.                 local itemid = items[i][1]
  276.                 local itemvalue = items[i][2]
  277.                 local itemtype = getItemType(itemid)
  278.        
  279.                 if not (itemtype) then
  280.                     return
  281.                 else
  282.                     local add = true
  283.                    
  284.                     if (itemtype==1) and not (showFood) then
  285.                         add = false
  286.                     elseif (itemtype==2) and not (showKeys) then
  287.                         add = false
  288.                     elseif (itemtype==3) and not (showDrugs) then
  289.                         add = false
  290.                     elseif (itemtype==4) and not (showOther) then
  291.                         add = false
  292.                     elseif (itemtype==5) and not (showBooks) then
  293.                         add = false
  294.                     elseif (itemtype==6) and not (showClothes) then
  295.                         add = false
  296.                     elseif (itemtype==7) and not (showElectronics) then
  297.                         add = false
  298.                     elseif (itemtype==false) then
  299.                         add = false
  300.                     end
  301.                    
  302.                     if (add) then
  303.                         local row = guiGridListAddRow(itemtype == 2 and gKeys or gItems)
  304.                         guiGridListSetItemText(itemtype == 2 and gKeys or gItems, row, colSlot, tostring(row+1), false, true)
  305.                         guiGridListSetItemData(itemtype == 2 and gKeys or gItems, row, colSlot, tostring(i))
  306.                         guiGridListSetItemText(itemtype == 2 and gKeys or gItems, row, colName, tostring(getItemName(itemid, itemvalue)), false, false)
  307.                         guiGridListSetItemText(itemtype == 2 and gKeys or gItems, row, colValue, tostring(getItemValue(itemid, itemvalue)), false, false)
  308.                     end
  309.                 end
  310.             end
  311.         end
  312.        
  313.         while showEmpty and guiGridListGetRowCount( gItems ) < slots do
  314.             local row = guiGridListAddRow(gItems)
  315.             guiGridListSetItemText(gItems, row, colSlot, tostring(row+1), false, true)
  316.             guiGridListSetItemText(gItems, row, colName, "Empty", false, false)
  317.             guiGridListSetItemText(gItems, row, colValue, "None", false, false)
  318.         end
  319.     end
  320.      
  321.     function toggleInventory()
  322.         if wItems then
  323.             if guiGetEnabled( wItems ) then
  324.                 hideInventory()
  325.             end
  326.         elseif not getElementData(getLocalPlayer(), "adminjailed") and not getElementData(getLocalPlayer(), "pd.jailstation") then
  327.             --showInventory(getLocalPlayer())
  328.         else
  329.             --outputChatBox("You can't access your inventory in jail", 255, 0, 0)
  330.         end
  331.     end
  332.     bindKey("i", "down", toggleInventory)
  333.      
  334.     function showInventory(player, syncw, synca)
  335.         if not (wChemistrySet) then
  336.             showinvPlayer = player
  337.             if wItems then
  338.                 hideInventory()
  339.             end
  340.             if getElementData(getLocalPlayer(), "exclusiveGUI") then
  341.                 return
  342.             end
  343.             setElementData(getLocalPlayer(), "exclusiveGUI", true, false)
  344.             local width, height = 600, 500
  345.             local scrWidth, scrHeight = guiGetScreenSize()
  346.             local x = scrWidth/2 - (width/2)
  347.             local y = scrHeight/2 - (height/2)
  348.            
  349.             local title = "Inventory"
  350.             if player ~= getLocalPlayer() then
  351.                 title = title .. " of " .. getPlayerName(player)
  352.             end
  353.             wItems = guiCreateWindow(x, y, width, height, title, false)
  354.             guiWindowSetSizable(wItems, false)
  355.            
  356.             tabPanel = guiCreateTabPanel(0.025, 0.05, 0.95, 0.7, true, wItems)
  357.             tabItems = guiCreateTab("Items", tabPanel)
  358.             tabKeys = guiCreateTab("Keys", tabPanel)
  359.             tabWeapons = guiCreateTab("Weapons", tabPanel)
  360.            
  361.             if activeTab == 0 then
  362.                 guiSetSelectedTab(tabPanel, tabItems)
  363.             elseif activeTab == 1 then
  364.                 guiSetSelectedTab(tabPanel, tabKeys)
  365.             else
  366.                 guiSetSelectedTab(tabPanel, tabWeapons)
  367.             end
  368.            
  369.             addEventHandler( "onClientGUITabSwitched", tabPanel,
  370.                 function( tab )
  371.                     if tab == tabItems then
  372.                         activeTab = 0
  373.                     elseif tab == tabKeys then
  374.                         activeTab = 1
  375.                     elseif tab == tabWeapons then
  376.                         activeTab = 2
  377.                     end
  378.                 end,
  379.                 false )
  380.            
  381.             -- ITEMS
  382.             gItems = guiCreateGridList(0.025, 0.05, 0.95, 0.9, true, tabItems)
  383.             addEventHandler("onClientGUIClick", gItems, showDescription, false)
  384.            
  385.             colSlot = guiGridListAddColumn(gItems, "Slot", 0.1)
  386.             colName = guiGridListAddColumn(gItems, "Name", 0.625)
  387.             colValue = guiGridListAddColumn(gItems, "Value", 0.225)
  388.            
  389.             -- keys
  390.             gKeys = guiCreateGridList(0.025, 0.05, 0.95, 0.9, true, tabKeys)
  391.             addEventHandler("onClientGUIClick", gKeys, showDescription, false)
  392.        
  393.             colSlot = guiGridListAddColumn(gKeys, "Slot", 0.1)
  394.             colName = guiGridListAddColumn(gKeys, "Name", 0.625)
  395.             colValue = guiGridListAddColumn(gKeys, "Value", 0.225)
  396.            
  397.             -- type checkboxes
  398.             toggleLabel = guiCreateLabel(0.025, 0.77, 0.95, 0.9, "Toggle Item Types:", true, wItems)
  399.             guiSetFont(toggleLabel, "default-bold-small")
  400.            
  401.             chkFood = guiCreateCheckBox(0.025, 0.8, 0.15, 0.05, "Food & Drink", showFood, true, wItems)
  402.             chkKeys = guiCreateCheckBox(0.2, 0.8, 0.1, 0.05, "Keys", showKeys, true, wItems)
  403.             chkDrugs = guiCreateCheckBox(0.3, 0.8, 0.1, 0.05, "Drugs", showDrugs, true, wItems)
  404.             chkBooks = guiCreateCheckBox(0.4, 0.8, 0.1, 0.05, "Books", showBooks, true, wItems)
  405.             chkClothes = guiCreateCheckBox(0.5, 0.8, 0.125, 0.05, "Clothing", showClothes, true, wItems)
  406.             chkElectronics = guiCreateCheckBox(0.625, 0.8, 0.15, 0.05, "Electronics", showElectronics, true, wItems)
  407.             chkOther = guiCreateCheckBox(0.775, 0.8, 0.1, 0.05, "Other", showOther, true, wItems)
  408.             chkEmpty = guiCreateCheckBox(0.875, 0.8, 0.1, 0.05, "Empty", showEmpty, true, wItems)
  409.            
  410.             addEventHandler("onClientGUIClick", chkFood, toggleCategory, false)
  411.             addEventHandler("onClientGUIClick", chkKeys, toggleCategory, false)
  412.             addEventHandler("onClientGUIClick", chkDrugs, toggleCategory, false)
  413.             addEventHandler("onClientGUIClick", chkBooks, toggleCategory, false)
  414.             addEventHandler("onClientGUIClick", chkClothes, toggleCategory, false)
  415.             addEventHandler("onClientGUIClick", chkElectronics, toggleCategory, false)
  416.             addEventHandler("onClientGUIClick", chkOther, toggleCategory, false)
  417.             addEventHandler("onClientGUIClick", chkEmpty, toggleCategory, false)
  418.            
  419.             source = nil
  420.             toggleCategory()
  421.              addEventHandler("onClientGUIDoubleClick", gItems, useItem, false)
  422.              addEventHandler("onClientGUIDoubleClick", gKeys, useItem, false)
  423.      
  424.             -- WEAPONS
  425.             gWeapons = guiCreateGridList(0.025, 0.05, 0.95, 0.9, true, tabWeapons)
  426.             addEventHandler("onClientGUIClick", gWeapons, showDescription, false)
  427.            
  428.            
  429.             colWSlot = guiGridListAddColumn(gWeapons, "Slot", 0.1)
  430.             colWName = guiGridListAddColumn(gWeapons, "Name", 0.625)
  431.             colWValue = guiGridListAddColumn(gWeapons, "Ammo", 0.225)
  432.            
  433.             if syncw and synca then
  434.                 for i=0, 12 do
  435.                     local tokenweapon = tonumber(gettok(syncw, i+1, 59))
  436.                     local tokenammo = tonumber(gettok(synca, i+1, 59))
  437.                    
  438.                     if (not tokenweapon) or (not tokenammo) then
  439.                         break
  440.                     else
  441.                         local row = guiGridListAddRow(gWeapons)
  442.                         local weapon = getItemName(-tokenweapon)
  443.                         guiGridListSetItemText(gWeapons, row, colWSlot, tostring(getSlotFromWeapon(tokenweapon)), false, true)
  444.                         guiGridListSetItemText(gWeapons, row, colWName, tostring(weapon), false, false)
  445.                         guiGridListSetItemText(gWeapons, row, colWValue, tostring(tokenammo), false, false)
  446.                     end
  447.                 end
  448.             elseif player == getLocalPlayer() then
  449.                 for i = 0, 12 do
  450.                     if getPedWeapon(player, i) and getPedWeapon(player, i) ~= 0 and getPedTotalAmmo(player, i) > 0 then
  451.                         local row = guiGridListAddRow(gWeapons)
  452.                         local weapon = getItemName(-getPedWeapon(player, i))
  453.                         local ammo = getPedTotalAmmo(player, i)
  454.                         guiGridListSetItemText(gWeapons, row, colWSlot, tostring(i), false, true)
  455.                         guiGridListSetItemText(gWeapons, row, colWName, tostring(weapon), false, false)
  456.                         guiGridListSetItemText(gWeapons, row, colWValue, tostring(ammo), false, false)
  457.                     end
  458.                 end
  459.             else
  460.                 local row = guiGridListAddRow(gWeapons)
  461.                 guiGridListSetItemText(gWeapons, row, colWName, "Error", false, false)
  462.             end
  463.             guiSetVisible(colWSlot, false)
  464.            
  465.             addEventHandler("onClientGUIDoubleClick", gWeapons, useItem, false)
  466.            
  467.             -- ARMOR
  468.             if getPedArmor(player) > 0 then
  469.                 local row = guiGridListAddRow(gWeapons)
  470.                 guiGridListSetItemText(gWeapons, row, colWSlot, tostring(13), false, true)
  471.                 guiGridListSetItemText(gWeapons, row, colWName, "Body Armor", false, false)
  472.                 guiGridListSetItemText(gWeapons, row, colWValue, tostring(getPedArmor(player)), false, false)
  473.             end
  474.            
  475.             -- GENERAL
  476.             lDescription = guiCreateLabel(0.025, 0.87, 0.95, 0.1, "Click an item to see it's description.", true, wItems)
  477.             guiLabelSetHorizontalAlign(lDescription, "center", true)
  478.             guiSetFont(lDescription, "default-bold-small")
  479.            
  480.             -- buttons
  481.             if player == getLocalPlayer() then
  482.                 bUseItem = guiCreateButton(0.05, 0.91, 0.2, 0.15, "Use Item", true, wItems)
  483.                 addEventHandler("onClientGUIClick", bUseItem, useItem, false)
  484.                 guiSetEnabled(bUseItem, false)
  485.                
  486.                 bDropItem = guiCreateButton(0.30, 0.91, 0.2, 0.15, "Drop Item", true, wItems)
  487.                 addEventHandler("onClientGUIClick", bDropItem, dropItem, false)
  488.                 guiSetEnabled(bDropItem, false)
  489.                
  490.                 bShowItem = guiCreateButton(0.55, 0.91, 0.2, 0.15, "Show Item", true, wItems)
  491.                 addEventHandler("onClientGUIClick", bShowItem, showItem, false)
  492.                 guiSetEnabled(bShowItem, false)
  493.                
  494.                 bDestroyItem = guiCreateButton(0.8, 0.91, 0.2, 0.15, "Destroy Item", true, wItems)
  495.                 addEventHandler("onClientGUIClick", bDestroyItem, destroyItem, false)
  496.                 guiSetEnabled(bDestroyItem, false)
  497.             else
  498.                 bClose = guiCreateButton(0.375, 0.91, 0.2, 0.15, "Close Inventory", true, wItems)
  499.                 addEventHandler("onClientGUIClick", bClose, hideInventory, false)
  500.             end
  501.             showCursor(true)
  502.         end
  503.     end
  504.     addEvent("showInventory", true)
  505.     addEventHandler("showInventory", getRootElement(), showInventory)
  506.      
  507.     function hideInventory()
  508.         colSlot = nil
  509.         colName = nil
  510.         colValue = nil
  511.        
  512.         colWSlot = nil
  513.         colWName = nil
  514.         colWValue = nil
  515.        
  516.         if wItems then
  517.             destroyElement(wItems)
  518.         end
  519.         wItems = nil
  520.        
  521.         showCursor(false)
  522.         setElementData(getLocalPlayer(), "exclusiveGUI", false, false)
  523.        
  524.         hideNewInventory()
  525.     end
  526.     addEvent("hideInventory", true)
  527.     addEventHandler("hideInventory", getRootElement(), hideInventory)
  528.      
  529.     function showDescription(button, state)
  530.         if (button=="left") then
  531.             if (guiGetSelectedTab(tabPanel)==tabItems or guiGetSelectedTab(tabPanel)==tabKeys) then -- ITEMS
  532.                 local row, col = guiGridListGetSelectedItem(guiGetSelectedTab(tabPanel) == tabKeys and gKeys or gItems)
  533.                
  534.                 if (row==-1) or (col==-1) then
  535.                     guiSetText(lDescription, "Click an item to see it's description.")
  536.                     guiSetEnabled(bUseItem, false)
  537.                     guiSetEnabled(bDropItem, false)
  538.                     guiSetEnabled(bShowItem, false)
  539.                     guiSetEnabled(bDestroyItem, false)
  540.                 else
  541.                     local slot = tonumber(guiGridListGetItemData(guiGetSelectedTab(tabPanel) == tabKeys and gKeys or gItems, row, 1))
  542.                     local items = getItems(showinvPlayer)
  543.                     if not items[slot] then
  544.                         guiSetText(lDescription, "An empty slot.")
  545.                         guiSetEnabled(bUseItem, false)
  546.                         guiSetEnabled(bDropItem, false)
  547.                         guiSetEnabled(bShowItem, false)
  548.                         guiSetEnabled(bDestroyItem, false)
  549.                     else
  550.                         local desc = tostring( getItemDescription( items[slot][1], items[slot][2] ) )
  551.                         local value = items[slot][2]
  552.                        
  553.                         -- percent operators
  554.                         desc = string.gsub((desc), "#v", tostring(value))
  555.                        
  556.                         if (desc=="A Dictionary.") then
  557.                             local res = getResourceFromName("language-system")
  558.                             local lang = call(res, "getLanguageName", tonumber(value))
  559.                             desc = "A " .. lang .. " dictionary."
  560.                         end
  561.                        
  562.                         guiSetText(lDescription, desc)
  563.                         guiSetEnabled(bUseItem, true)
  564.                         guiSetEnabled(bDropItem, true)
  565.                         guiSetEnabled(bShowItem, true)
  566.                         guiSetEnabled(bDestroyItem, true)
  567.                     end
  568.                 end
  569.             elseif (guiGetSelectedTab(tabPanel)==tabWeapons) then -- WEAPONS
  570.                 local row, col = guiGridListGetSelectedItem(gWeapons)
  571.                 if (row==-1) or (col==-1) then
  572.                     guiSetText(lDescription, "Click an item to see it's description.")
  573.                     guiSetEnabled(bUseItem, false)
  574.                     guiSetEnabled(bDropItem, false)
  575.                     guiSetEnabled(bShowItem, false)
  576.                     guiSetEnabled(bDestroyItem, false)
  577.                 else
  578.                     local name = tostring(guiGridListGetItemText(gWeapons, row, 2))
  579.                     local ammo = tostring(guiGridListGetItemText(gWeapons, row, 3))
  580.                     local desc = "A " .. name .. " with " .. ammo .. " ammunition."
  581.                        
  582.                     guiSetText(lDescription, desc)
  583.                     guiSetEnabled(bUseItem, true)
  584.                     guiSetEnabled(bDropItem, true)
  585.                     guiSetEnabled(bShowItem, true)
  586.                     guiSetEnabled(bDestroyItem, true)
  587.                 end
  588.             end
  589.         end
  590.     end
  591.      
  592.     function useItem(itemSlot)
  593.     --function useItem(button)
  594.         showinvPlayer = getLocalPlayer()
  595.         if getElementHealth(getLocalPlayer()) == 0 then return end
  596.         local x, y, z = getElementPosition(getLocalPlayer())
  597.         local groundz = getGroundPosition(x, y, z)
  598.         if itemSlot > 0 then -- ITEMS
  599.             local itemID = getItems( showinvPlayer )[itemSlot][1]
  600.             local itemName = getItemName( itemID )
  601.             local itemValue = getItems( showinvPlayer )[itemSlot][2]
  602.             local additional = nil
  603.            
  604.             if (itemID==2) then -- cellphone
  605.                 hideInventory()
  606.                 triggerEvent("showPhoneGUI", getLocalPlayer(), itemValue)
  607.                 outputChatBox("Use /call to use this item.", 255, 194, 14)
  608.                 return
  609.             elseif (itemID==6) then -- radio
  610.                 outputChatBox("Press Y to use this item. You can also use /tuneradio to tune your radio.", 255, 194, 14)
  611.                 return
  612.             elseif (itemID==7) then -- phonebook
  613.                 outputChatBox("Use /phonebook to use this item.", 255, 194, 14)
  614.                 return
  615.             elseif (itemID==18) then -- City Guide
  616.                 triggerEvent( "showCityGuide", getLocalPlayer( ) )
  617.                 return
  618.             elseif (itemID==19) then -- MP3 PLayer
  619.                 if isPedInVehicle(getLocalPlayer()) or getElementData(getLocalPlayer(), "fishing") or getElementData(getLocalPlayer(), "jammed") then
  620.                     outputChatBox("Use the - and = keys to use the MP3 Player.", 255, 194, 14)
  621.                 else
  622.                     exports['realism-system']:toggleMP3("=", "down")
  623.                 end         return
  624.             elseif (itemID==27) then -- Flashbang
  625.                 local x, y, z = getElementPosition(getLocalPlayer( ))
  626.                 local rot = getPedRotation(getLocalPlayer( ))
  627.                 x = x + math.sin(math.rad(-rot)) * 10
  628.                 y = y + math.cos(math.rad(-rot)) * 10
  629.                 z = getGroundPosition(x, y, z + 2)
  630.                 additional = { x, y, z }
  631.             elseif (itemID==28 or itemID==54) then -- Glowstick or Ghettoblaster
  632.                 local x, y, z = getElementPosition(getLocalPlayer( ))
  633.                 local rot = getPedRotation(getLocalPlayer( ))
  634.                 x = x + math.sin(math.rad(-rot)) * 2
  635.                 y = y + math.cos(math.rad(-rot)) * 2
  636.                 z = getGroundPosition(x, y, z)
  637.                 additional = { x, y, z - 0.5 }
  638.             elseif (itemID==30) or (itemID==31) or (itemID==32) or (itemID==33) then
  639.                 outputChatBox("Use the chemistry set purchasable from 24/7 to use this item.", 255, 0, 0)
  640.                 return
  641.             elseif (itemID==34) then -- COCAINE
  642.                 doDrug1Effect()
  643.             elseif (itemID==35) then
  644.                 doDrug2Effect()
  645.             elseif (itemID==36) then
  646.                 doDrug3Effect()
  647.             elseif (itemID==37) then
  648.                 doDrug4Effect()
  649.             elseif (itemID==38) then
  650.                 if not getPedOccupiedVehicle(getLocalPlayer()) then
  651.                     doDrug5Effect()
  652.                 end
  653.             elseif (itemID==39) then
  654.                 doDrug6Effect()
  655.             elseif (itemID==40) then
  656.                 doDrug3Effect()
  657.                 doDrug1Effect()
  658.             elseif (itemID==41) then
  659.                 doDrug4Effect()
  660.                 doDrug6Effect()
  661.             elseif (itemID==42) then
  662.                 if not getPedOccupiedVehicle(getLocalPlayer()) then
  663.                     doDrug5Effect()
  664.                     doDrug2Effect()
  665.                 end
  666.             elseif (itemID==43) then
  667.                 doDrug4Effect()
  668.                 doDrug1Effect()
  669.                 doDrug6Effect()
  670.             elseif (itemID==44) then
  671.                 hideInventory()
  672.                 showChemistrySet()
  673.                 return
  674.             elseif (itemID==45) or (itemID==46) or (itemID==47) or (itemID==66) then
  675.                 outputChatBox("Right click a player to use this item.", source, 255, 0, 0)
  676.                 return
  677.             elseif (itemID==48) then
  678.                 outputChatBox("Your inventory is extended.", 0, 255, 0)
  679.                 return
  680.             elseif (itemID==50) or (itemID==51) or (itemID==52) then
  681.                 hideInventory()
  682.             elseif (itemID==53) then -- Breathalizer
  683.                 outputChatBox("Use /breathtest to use this item.", 255, 194, 15)
  684.                 return
  685.             elseif (itemID==57) then -- FUEL CAN
  686.                 hideInventory()
  687.             elseif (itemID==58) then
  688.                 setTimer(
  689.                     function()
  690.                         setElementData(getLocalPlayer(), "alcohollevel", ( getElementData(getLocalPlayer(), "alcohollevel") or 0 ) + 0.1, false)
  691.                     end, 15000, 1
  692.                 )
  693.             elseif (itemID==61) then -- Emergency Light Becon
  694.                 outputChatBox("Put it in your car inventory and press 'P' to toggle it.", 255, 194, 14)
  695.                 return
  696.             elseif (itemID==62) then
  697.                 setTimer(
  698.                     function()
  699.                         setElementData(getLocalPlayer(), "alcohollevel", ( getElementData(getLocalPlayer(), "alcohollevel") or 0 ) + 0.3, false)
  700.                     end, 5000, 1
  701.                 )
  702.             elseif (itemID==63) then
  703.                 setTimer(
  704.                     function()
  705.                         setElementData(getLocalPlayer(), "alcohollevel", ( getElementData(getLocalPlayer(), "alcohollevel") or 0 ) + 0.2, false)
  706.                     end, 10000, 1
  707.                 )
  708.             elseif (itemID==67) then -- GPS
  709.                 outputChatBox("Put it in your car inventory and Press 'F5'.", 255, 194, 14)
  710.                 return
  711.             elseif (itemID==70) then -- First Aid Kit
  712.                 outputChatBox("Right click on a player who's knocked out to stabilize him.", 255, 194, 14)
  713.                 return
  714.             elseif (itemID==71) then -- Notebook
  715.                 outputChatBox("Use /writenote [text] to write a note. There are " .. itemValue .. " pages left.", 255, 194, 14)
  716.                 return
  717.             elseif (itemID==72) then -- Note
  718.                 outputChatBox("The Note reads: " .. itemValue, 255, 194, 14)
  719.             elseif (itemID==78) then
  720.                 outputChatBox("This San Andreas Pilot License was issued for " .. itemValue .. ".", 255, 194, 14)
  721.                 return
  722.             elseif (itemID==81) then
  723.                 outputChatBox("Drop this Fridge in an Interior.", 255, 194, 14)
  724.                 return
  725.             elseif (itemID==84) then
  726.                 outputChatBox("Put it in a car or carry it to know when police is around.", 255, 194, 14)
  727.                 return
  728.             elseif (itemID==85) then -- Emergency Light Becon
  729.                 outputChatBox("Put it in your car inventory and press 'N' to toggle it.", 255, 194, 14)
  730.                 return
  731.             elseif (itemID==91) then
  732.                 setTimer(
  733.                     function()
  734.                         setElementData(getLocalPlayer(), "alcohollevel", ( getElementData(getLocalPlayer(), "alcohollevel") or 0 ) + 0.35, false)
  735.                     end, 15000, 1
  736.                 )
  737.             elseif (itemID==96) then
  738.                 hideInventory()
  739.             elseif (itemID==103) then
  740.                 outputChatBox ( "Drop this shelf in an interior.", 255, 194, 14 )
  741.                 return
  742.             end
  743.      
  744.                
  745.             triggerServerEvent("useItem", getLocalPlayer(), itemSlot, additional)
  746.         else
  747.             if itemSlot == -100 then
  748.                 outputChatBox("You wear Body Armor.", 0, 255, 0)
  749.             else
  750.                 setPedWeaponSlot( getLocalPlayer(), -itemSlot )
  751.             end
  752.         end
  753.     end
  754.      
  755.     function stopGasmaskDamage(attacker, weapon)
  756.         local gasmask = getElementData(getLocalPlayer(), "gasmask")
  757.      
  758.         if (weapon==17 or weapon==41) and (gasmask==1) then
  759.             cancelEvent()
  760.         end
  761.     end
  762.     addEventHandler("onClientPlayerDamage", getLocalPlayer(), stopGasmaskDamage)
  763.      
  764.     -- /itemlist (admin command to get item IDs)
  765.     wItemList, bItemListClose = nil
  766.      
  767.     function showItemList()
  768.         if getElementData(getLocalPlayer(), "adminlevel") == 0 then
  769.             return
  770.         end
  771.         if not (wItemsList) then
  772.             wItemsList = guiCreateWindow(0.15, 0.15, 0.7, 0.7, "Items List", true)
  773.             local gridItems = guiCreateGridList(0.025, 0.1, 0.95, 0.775, true, wItemsList)
  774.            
  775.             local colID = guiGridListAddColumn(gridItems, "ID", 0.1)
  776.             local colName = guiGridListAddColumn(gridItems, "Item Name", 0.3)
  777.             local colDesc = guiGridListAddColumn(gridItems, "Description", 0.6)
  778.            
  779.             for key, value in pairs(g_items) do
  780.                 if key ~= 74 and key ~= 75 then
  781.                     local row = guiGridListAddRow(gridItems)
  782.                     guiGridListSetItemText(gridItems, row, colID, tostring(key), false, true)
  783.                     guiGridListSetItemText(gridItems, row, colName, value[1], false, false)
  784.                     guiGridListSetItemText(gridItems, row, colDesc, value[2], false, false)
  785.                 end
  786.             end
  787.      
  788.             bItemListClose = guiCreateButton(0.025, 0.9, 0.95, 0.1, "Close", true, wItemsList)
  789.             addEventHandler("onClientGUIClick", bItemListClose, closeItemsList, false)
  790.            
  791.             showCursor(true)
  792.         else
  793.             guiSetVisible(wItemsList, true)
  794.             guiBringToFront(wItemsList)
  795.             showCursor(true)
  796.         end
  797.     end
  798.     addCommandHandler("itemlist", showItemList)
  799.      
  800.     function closeItemsList(button, state)
  801.         if (source==bItemListClose) and (button=="left") and (state=="up") then
  802.             showCursor(false)
  803.             destroyElement(bItemListClose)
  804.             destroyElement(wItemsList)
  805.             bItemListClose = nil
  806.             wItemsList = nil
  807.         end
  808.     end
  809.      
  810.     addEventHandler("onClientChangeChar", getRootElement(), hideInventory)
  811.      
  812.     local function updateInv()
  813.         if wItems and source == showinvPlayer then
  814.             source = nil
  815.             setTimer(toggleCategory, 50, 1)
  816.            
  817.             if guiGetSelectedTab( tabPanel ) == tabItems then
  818.                 guiSetEnabled(bUseItem, false)
  819.                 guiSetEnabled(bDropItem, false)
  820.                 guiSetEnabled(bShowItem, false)
  821.                 guiSetEnabled(bDestroyItem, false)
  822.             end
  823.         end
  824.     end
  825.     addEventHandler("recieveItems", getRootElement(), updateInv)
  826.      
  827.     addEvent(":~", true)
  828.     addEventHandler(":~", getLocalPlayer(),
  829.         function( )
  830.             if wItems then
  831.                 guiSetVisible( wWait, false )
  832.                 guiSetEnabled( wItems, true )
  833.             end
  834.         end
  835.     )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement