Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.21 KB | None | 0 0
  1. local sx, sy = guiGetScreenSize()
  2. local rX, rY, rZ = 0, 0, 0
  3. local preview = true
  4. local element
  5. local canUseMenu = false
  6. local current = 1
  7. local alpha = 0
  8. local lastTick = 0
  9.  
  10. hasObject = false
  11.  
  12. local pushData = {x = 0, y = 0}
  13. local moveData = {0, 0}
  14.  
  15. function loadCoreAssets()
  16.     fonts = {}
  17.     engine = getCore()
  18.     fonts['BentonSansRegural_8'] = getFont('BentonSansRegural', 8)
  19. end
  20.  
  21. addEventHandler('onClientColShapeHit', root, function(p)
  22.     if p ~= localPlayer then return end
  23.     if source then
  24.         if getElementData(source, 'col -> furnitureCol') then
  25.             preview = true
  26.             alpha = 0
  27.             current = 1
  28.             rX, rY, rZ = 0, 0, 0
  29.             pushData = {x = 0, y = 0}
  30.             moveData = {0, 0}
  31.             element = createObject(furnituresData['furnitures'][current]['objectID'], furnituresData['previewPosition'][1], furnituresData['previewPosition'][2], furnituresData['previewPosition'][3])
  32.             setElementDoubleSided(element, true)
  33.             setObjectBreakable(element, true)
  34.  
  35.             setElementFrozen(localPlayer, true)
  36.             fadeCamera(false)
  37.             setTimer( function()
  38.                 showCursor(true)
  39.                 setElementData(localPlayer, 'game -> isKeysBlocked', 1)
  40.                 exports['_cCustomChat']:modifyChatState(0)
  41.                 setElementData(localPlayer, 'interface -> showWidgets', 0)
  42.  
  43.                 setCameraMatrix(unpack(furnituresData['previewCameraMatrix']))
  44.                 addEventHandler('onClientRender', root, drawFurniture)
  45.                 addEventHandler('onClientClick', root, clickFurniture)
  46.  
  47.                 setTimer( function()
  48.                     canUseMenu = true
  49.                     fadeCamera(true)
  50.  
  51.                     bindKey('backspace', 'down', leaveFurniturePanel)
  52.                 end, 500, 1)
  53.             end, 1500, 1)
  54.         end
  55.     end
  56. end)
  57.  
  58. function leaveFurniturePanel()
  59.     if not canUseMenu then return end
  60.     canUseMenu = false
  61.     unbindKey('backspace', 'down', leaveFurniturePanel)
  62.     fadeCamera(false)
  63.     setTimer( function()
  64.         setCameraTarget(localPlayer)
  65.         removeEventHandler('onClientRender', root, drawFurniture)
  66.         removeEventHandler('onClientClick', root, clickFurniture)
  67.  
  68.         if isElement(element) then destroyElement(element) end
  69.         setElementFrozen(localPlayer, false)
  70.  
  71.         setTimer( function()
  72.             fadeCamera(true)
  73.             setElementData(localPlayer, 'game -> isKeysBlocked', 0)
  74.             exports['_cCustomChat']:modifyChatState(1)
  75.             setElementData(localPlayer, 'interface -> showWidgets', 1)
  76.             showCursor(false)
  77.         end, 500, 1)
  78.     end, 1500, 1)
  79. end
  80.  
  81. function clickFurniture(b, s, _x, _y, _aX, _aY, _aZ, clickedElement)
  82.     if b == 'left' and s == 'down' and not engine:isRectangle(0, sy/2 - 500/2, 240, 500, _x, _y) then
  83.         if not canUseMenu then return end
  84.         pushData = {x = _x - moveData[1], y = _y - moveData[2]}
  85.         return
  86.     elseif b == 'left' and s == 'up' then
  87.         if not canUseMenu then return end
  88.         pushData = {x = 0, y = 0}
  89.         return
  90.     elseif b == 'left' and s == 'down' then
  91.         if preview and canUseMenu then
  92.             if lastTick > getTickCount() - 500 then exports['_cPopup']:createNotification('error', 'Várj egy kicsit!') return end
  93.             for i = 1, 5 do
  94.                 if engine:isCursorInRectangle(57, sy/2 - 196/2 + 30*i, 192, 28) then
  95.                     if i == 1 then
  96.                         lastTick = getTickCount()
  97.                         moveData = {0, 0}
  98.                         return
  99.                     elseif i == 2 then
  100.                         lastTick = getTickCount()
  101.                         canUseMenu = false
  102.                         fadeCamera(false)
  103.                         setTimer( function()
  104.                             moveData = {0, 0}
  105.                             current = current - 1
  106.                             if current < 1 then
  107.                                 current = #furnituresData['furnitures']
  108.                             end
  109.    
  110.                             if isElement(element) then destroyElement(element) end
  111.                            
  112.                             element = createObject(furnituresData['furnitures'][current]['objectID'], furnituresData['previewPosition'][1], furnituresData['previewPosition'][2], furnituresData['previewPosition'][3])
  113.                             setElementDoubleSided(element, true)
  114.                             setObjectBreakable(element, true)
  115.    
  116.                             setTimer( function()
  117.                                 fadeCamera(true)
  118.                                 canUseMenu = true
  119.                             end, 1000, 1)
  120.                         end, 1500, 1)
  121.                     elseif i == 3 then
  122.                         lastTick = getTickCount()
  123.                         canUseMenu = false
  124.                         fadeCamera(false)
  125.                         setTimer( function()
  126.                             moveData = {0, 0}
  127.                             current = current + 1
  128.                             if current > #furnituresData['furnitures'] then
  129.                                 current = 1
  130.                             end
  131.    
  132.                             if isElement(element) then destroyElement(element) end
  133.    
  134.                             element = createObject(furnituresData['furnitures'][current]['objectID'], furnituresData['previewPosition'][1], furnituresData['previewPosition'][2], furnituresData['previewPosition'][3])
  135.                             setElementDoubleSided(element, true)
  136.                             setObjectBreakable(element, true)
  137.    
  138.                             setTimer( function()
  139.                                 fadeCamera(true)
  140.                                 canUseMenu = true
  141.                             end, 1000, 1)
  142.                         end, 1500, 1)
  143.                     elseif i == 4 then
  144.                         lastTick = getTickCount()
  145.                         leaveFurniturePanel()
  146.                     elseif i == 5 then
  147.                         lastTick = getTickCount()
  148.                         if tonumber(getElementData(localPlayer, 'char -> money')) >= tonumber(furnituresData['furnitures'][current]['cost']) then
  149.                             local furnituresTable = getElementData(localPlayer, 'char -> furnitures')
  150.                             if #furnituresTable < 8 then
  151.                                 table.insert(furnituresTable, current)
  152.                                 setElementData(localPlayer, 'char -> furnitures', furnituresTable)
  153.                                 exports['_cPopup']:createNotification('success', 'Sikeresen megvásároltál egy bútort! ('.. furnituresData['furnitures'][current]['furnitureName'] ..')')
  154.                                 engine:setElementData(localPlayer, 'char -> money', getElementData(localPlayer, 'char -> money') - tonumber(furnituresData['furnitures'][current]['cost']))
  155.                             else
  156.                                 exports['_cPopup']:createNotification('error', 'Max 8 bútort tudsz megvenni egyszerre!')
  157.                                 exports['_cPopup']:createNotification('error', 'Szükséges minimum egy darabot leraknod!')
  158.                             end
  159.                         else
  160.                             exports['_cPopup']:createNotification('error', 'Nincs elég pénzed a vásárláshoz!')
  161.                         end
  162.                     end
  163.                 end
  164.             end
  165.         end
  166.     end
  167. end
  168.  
  169. function drawFurniture()
  170.     if canUseMenu then
  171.         if alpha <= 235 then
  172.             alpha = alpha + 20
  173.         end
  174.     else
  175.         if alpha >= 20 then
  176.             alpha = alpha - 20
  177.         end
  178.     end
  179.  
  180.     if preview and isElement(element) then
  181.         local cursorX, cursorY = -500, -500
  182.         if isCursorShowing() then
  183.             cursorX, cursorY = getCursorPosition()
  184.             cursorX, cursorY = sx*cursorX, sy*cursorY
  185.            
  186.             if (cursorX and cursorY) and pushData['x'] ~= 0 and pushData['y'] ~= 0 then
  187.                 moveData = {cursorX - pushData['x'], cursorY - pushData['y']}
  188.             end
  189.         end
  190.  
  191.         setElementRotation(element, rX - moveData[2], rY, rZ + moveData[1])
  192.  
  193.         dxDrawImage(30, sy/2 - 326/2, 246, 327, '/files/images/bg_furniture.png', 0, 0, 0, tocolor(255, 255, 255, alpha))
  194.         dxDrawText(furnituresData['furnitures'][current]['furnitureName'], 70, sy/2 - 222/2, 70, sy/2 - 222/2, tocolor(255, 255, 255, alpha), 1, fonts['BentonSansRegural_8'], 'left', 'top')
  195.         dxDrawText('$'.. furnituresData['furnitures'][current]['cost'], 70, sy/2 + 238/2, 70, sy/2 + 238/2, tocolor(255, 255, 255, alpha), 1, fonts['BentonSansRegural_8'], 'left', 'top')
  196.  
  197.         for i = 1, 5 do
  198.             if engine:isCursorInRectangle(57, sy/2 - 196/2 + 30*i, 192, 28) then
  199.                 dxDrawImage(57, sy/2 - 196/2 + 30*i, 192, 28, '/files/images/bg_furniture_button_'.. i ..'_hover.png', 0, 0, 0, tocolor(255, 255, 255, alpha))
  200.             else
  201.                 dxDrawImage(57, sy/2 - 196/2 + 30*i, 192, 28, '/files/images/bg_furniture_button_'.. i ..'.png', 0, 0, 0, tocolor(255, 255, 255, alpha))
  202.             end
  203.         end
  204.     end
  205. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement