Advertisement
Guest User

boxes

a guest
Sep 19th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. local bx,by = wx/2, hy/2
  2. selectedBox = 0
  3. onBoxItem = false
  4. boxesItems = {{},{},{},{},{},{},{},{},{},{}}
  5. stillDrawing = false
  6.  
  7. function createBoxesLabels ()
  8. local start = -5*75
  9. for i = 1, 10 do
  10. local createdLabel = guiCreateLabel ( bx+start, hy-75, 70, 70, '', false )
  11. setElementData ( createdLabel, 'boxLabel', true )
  12. setElementData ( createdLabel, 'boxLabelID', i )
  13. addEventHandler( "onClientMouseLeave", createdLabel, boxLabelLeaved, false )
  14. addEventHandler( "onClientMouseEnter", createdLabel, boxLabelEntered, false )
  15. addEventHandler( "onClientGUIClick", createdLabel, boxLabelClicked, false )
  16. table.insert ( boxesLabels, createdLabel )
  17. start = start+75
  18. end
  19. end
  20.  
  21. function boxLabelEntered ()
  22. if getElementData ( source, "boxLabel" ) then
  23. local id = getElementData ( source, "boxLabelID" )
  24. selectedBox = id
  25. onBoxItem = source
  26. end
  27. end
  28.  
  29. function boxLabelClicked ()
  30. if getElementData ( source, "boxLabel" ) then
  31. local id = getElementData ( source, "boxLabelID" )
  32. boxesItems[id] = {}
  33. setElementData ( getLocalPlayer(), "fb"..id, "" )
  34. end
  35. end
  36.  
  37. function boxLabelLeaved ()
  38. if getElementData ( source, "boxLabel" ) then
  39. --local id = getElementData ( source, "boxLabelID" )
  40. selectedBox = 0
  41. onBoxItem = false
  42. end
  43. end
  44.  
  45. function drawFastBoxes ()
  46. local start = -5*75
  47. for i = 1, 10 do
  48. if i == selectedBox and #boxesItems[i] > 0 and stillDrawing then -- занято и выделено
  49. dxDrawLine(bx+start,hy-75,bx+start+70,hy-75,tocolor (200,200,200,100),1)
  50. dxDrawLine(bx+start+70,hy-75,bx+start+70,hy-5,tocolor (200,200,200,100),1)
  51. dxDrawLine(bx+start,hy-5,bx+start+70,hy-5,tocolor (200,200,200,100),1)
  52. dxDrawLine(bx+start,hy-75,bx+start,hy-5,tocolor (200,200,200,100),1)
  53. dxDrawRectangle ( bx+start, hy-75, 70, 70, tocolor ( 200, 200, 200, 150 ))
  54. elseif #boxesItems[i] > 0 and stillDrawing then -- занято
  55. dxDrawLine(bx+start,hy-75,bx+start+70,hy-75,tocolor (200,200,200,100),1)
  56. dxDrawLine(bx+start+70,hy-75,bx+start+70,hy-5,tocolor (200,200,200,100),1)
  57. dxDrawLine(bx+start,hy-5,bx+start+70,hy-5,tocolor (200,200,200,100),1)
  58. dxDrawLine(bx+start,hy-75,bx+start,hy-5,tocolor (200,200,200,100),1)
  59. dxDrawRectangle ( bx+start, hy-75, 70, 70, tocolor ( fbur, fbub, fbug, fbua ))
  60. elseif inventoryShowing then -- не занято
  61. dxDrawLine(bx+start,hy-75,bx+start+70,hy-75,tocolor (200,200,200,100),1)
  62. dxDrawLine(bx+start+70,hy-75,bx+start+70,hy-5,tocolor (200,200,200,100),1)
  63. dxDrawLine(bx+start,hy-5,bx+start+70,hy-5,tocolor (200,200,200,100),1)
  64. dxDrawLine(bx+start,hy-75,bx+start,hy-5,tocolor (200,200,200,100),1)
  65. dxDrawRectangle ( bx+start, hy-75, 70, 70, tocolor ( 0, 0, 0, 70 ))
  66. end
  67. if #boxesItems[i] > 0 and stillDrawing then
  68. drawBoxItemInSlot ( i, start )
  69. end
  70. start = start+75
  71. end
  72. end
  73.  
  74. function drawBoxItemInSlot ( num, coord )
  75. local quant = getElementData ( getLocalPlayer(), boxesItems[num][1] ) or 0
  76. if quant <= 0 then
  77. boxesItems[num] = {}
  78. setElementData ( getLocalPlayer(), "fb"..num, "" )
  79. return true
  80. end
  81. local xs, ys = boxesItems[num][3], boxesItems[num][4]
  82. local xsize, ysize = 64, 64
  83. local ystart, xstart = 0, 0
  84. if xs > ys then
  85. ysize = 32
  86. ystart = 22
  87. elseif ys > xs then
  88. xsize = 32
  89. xstart = 22
  90. ystart = 0
  91. end
  92. dxDrawImage ( bx+coord+3+xstart,hy-67+ystart, xsize,ysize, "icons/"..boxesItems[num][2] )
  93. dxDrawText(boxesItems[num][1], bx+coord+3,hy-20, bx+coord+55, hy, tocolor(255,255,255,255), 0.8, "arial", "left", "top", true, false, false, false, false )
  94. dxDrawText(quant, bx+coord+58,hy-20, bx+coord+70, hy, tocolor(255,255,255,255), 0.8, "arial", "left", "top", true, false, false, false, false )
  95. if num == 10 then num = 0 end
  96. dxDrawText(num, bx+coord+3,hy-68, bx+coord+3, hy, tocolor(255,255,255,255), 0.8, "arial", "left", "top", false, false, false, false, false )
  97. end
  98.  
  99. addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()),
  100. function ( startedRes )
  101. bindKey ( "1", "down", useBoxesItem, 1 )
  102. bindKey ( "2", "down", useBoxesItem, 2 )
  103. bindKey ( "3", "down", useBoxesItem, 3 )
  104. bindKey ( "4", "down", useBoxesItem, 4 )
  105. bindKey ( "5", "down", useBoxesItem, 5 )
  106. bindKey ( "6", "down", useBoxesItem, 6 )
  107. bindKey ( "7", "down", useBoxesItem, 7 )
  108. bindKey ( "8", "down", useBoxesItem, 8 )
  109. bindKey ( "9", "down", useBoxesItem, 9 )
  110. bindKey ( "0", "down", useBoxesItem, 10 )
  111. end
  112. )
  113.  
  114. function useBoxesItem ( key, state, num )
  115. stillDrawing = true
  116. cancelStillDrawing = setTimer(function()
  117. stillDrawing = false
  118. end,panelBD,1)
  119. if #boxesItems[num] > 0 then
  120. local quant = getElementData ( getLocalPlayer(), boxesItems[num][1] ) or 0
  121. if quant <= 0 then
  122. boxesItems[num] = {}
  123. setElementData ( getLocalPlayer(), "fb"..i, "" )
  124. return true
  125. end
  126. local itemName,itemInfo = getInventoryInfosForRightClickMenu(boxesItems[num][1])
  127. if itemName and itemInfo then
  128. useBoxes(itemName,itemInfo)
  129. end
  130. end
  131. end
  132.  
  133. function loadPlayerBoxesItems ()
  134. addEventHandler("onClientRender", root,drawFastBoxes)
  135. for i = 1, 10 do
  136. local item = getElementData ( getLocalPlayer(), "fb"..i )
  137. if item then
  138. if ( getElementData ( getLocalPlayer(), item ) or 0 ) > 0 then
  139. local itemData = getItemData( item )
  140. if itemData then
  141. boxesItems[i] = {itemData[1], itemData[6], itemData[2], itemData[3]}
  142. end
  143. end
  144. end
  145. end
  146. calculateSlotsStats ()
  147. if placeItemsInInventory() then
  148. calculateItemsPositions ()
  149. end
  150. end
  151. addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()),loadPlayerBoxesItems)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement