Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sx, sy = guiGetScreenSize()
- local rX, rY, rZ = 0, 0, 0
- local preview = true
- local element
- local canUseMenu = false
- local current = 1
- local alpha = 0
- local lastTick = 0
- hasObject = false
- local pushData = {x = 0, y = 0}
- local moveData = {0, 0}
- function loadCoreAssets()
- fonts = {}
- engine = getCore()
- fonts['BentonSansRegural_8'] = getFont('BentonSansRegural', 8)
- end
- addEventHandler('onClientColShapeHit', root, function(p)
- if p ~= localPlayer then return end
- if source then
- if getElementData(source, 'col -> furnitureCol') then
- preview = true
- alpha = 0
- current = 1
- rX, rY, rZ = 0, 0, 0
- pushData = {x = 0, y = 0}
- moveData = {0, 0}
- element = createObject(furnituresData['furnitures'][current]['objectID'], furnituresData['previewPosition'][1], furnituresData['previewPosition'][2], furnituresData['previewPosition'][3])
- setElementDoubleSided(element, true)
- setObjectBreakable(element, true)
- setElementFrozen(localPlayer, true)
- fadeCamera(false)
- setTimer( function()
- showCursor(true)
- setElementData(localPlayer, 'game -> isKeysBlocked', 1)
- exports['_cCustomChat']:modifyChatState(0)
- setElementData(localPlayer, 'interface -> showWidgets', 0)
- setCameraMatrix(unpack(furnituresData['previewCameraMatrix']))
- addEventHandler('onClientRender', root, drawFurniture)
- addEventHandler('onClientClick', root, clickFurniture)
- setTimer( function()
- canUseMenu = true
- fadeCamera(true)
- bindKey('backspace', 'down', leaveFurniturePanel)
- end, 500, 1)
- end, 1500, 1)
- end
- end
- end)
- function leaveFurniturePanel()
- if not canUseMenu then return end
- canUseMenu = false
- unbindKey('backspace', 'down', leaveFurniturePanel)
- fadeCamera(false)
- setTimer( function()
- setCameraTarget(localPlayer)
- removeEventHandler('onClientRender', root, drawFurniture)
- removeEventHandler('onClientClick', root, clickFurniture)
- if isElement(element) then destroyElement(element) end
- setElementFrozen(localPlayer, false)
- setTimer( function()
- fadeCamera(true)
- setElementData(localPlayer, 'game -> isKeysBlocked', 0)
- exports['_cCustomChat']:modifyChatState(1)
- setElementData(localPlayer, 'interface -> showWidgets', 1)
- showCursor(false)
- end, 500, 1)
- end, 1500, 1)
- end
- function clickFurniture(b, s, _x, _y, _aX, _aY, _aZ, clickedElement)
- if b == 'left' and s == 'down' and not engine:isRectangle(0, sy/2 - 500/2, 240, 500, _x, _y) then
- if not canUseMenu then return end
- pushData = {x = _x - moveData[1], y = _y - moveData[2]}
- return
- elseif b == 'left' and s == 'up' then
- if not canUseMenu then return end
- pushData = {x = 0, y = 0}
- return
- elseif b == 'left' and s == 'down' then
- if preview and canUseMenu then
- if lastTick > getTickCount() - 500 then exports['_cPopup']:createNotification('error', 'Várj egy kicsit!') return end
- for i = 1, 5 do
- if engine:isCursorInRectangle(57, sy/2 - 196/2 + 30*i, 192, 28) then
- if i == 1 then
- lastTick = getTickCount()
- moveData = {0, 0}
- return
- elseif i == 2 then
- lastTick = getTickCount()
- canUseMenu = false
- fadeCamera(false)
- setTimer( function()
- moveData = {0, 0}
- current = current - 1
- if current < 1 then
- current = #furnituresData['furnitures']
- end
- if isElement(element) then destroyElement(element) end
- element = createObject(furnituresData['furnitures'][current]['objectID'], furnituresData['previewPosition'][1], furnituresData['previewPosition'][2], furnituresData['previewPosition'][3])
- setElementDoubleSided(element, true)
- setObjectBreakable(element, true)
- setTimer( function()
- fadeCamera(true)
- canUseMenu = true
- end, 1000, 1)
- end, 1500, 1)
- elseif i == 3 then
- lastTick = getTickCount()
- canUseMenu = false
- fadeCamera(false)
- setTimer( function()
- moveData = {0, 0}
- current = current + 1
- if current > #furnituresData['furnitures'] then
- current = 1
- end
- if isElement(element) then destroyElement(element) end
- element = createObject(furnituresData['furnitures'][current]['objectID'], furnituresData['previewPosition'][1], furnituresData['previewPosition'][2], furnituresData['previewPosition'][3])
- setElementDoubleSided(element, true)
- setObjectBreakable(element, true)
- setTimer( function()
- fadeCamera(true)
- canUseMenu = true
- end, 1000, 1)
- end, 1500, 1)
- elseif i == 4 then
- lastTick = getTickCount()
- leaveFurniturePanel()
- elseif i == 5 then
- lastTick = getTickCount()
- if tonumber(getElementData(localPlayer, 'char -> money')) >= tonumber(furnituresData['furnitures'][current]['cost']) then
- local furnituresTable = getElementData(localPlayer, 'char -> furnitures')
- if #furnituresTable < 8 then
- table.insert(furnituresTable, current)
- setElementData(localPlayer, 'char -> furnitures', furnituresTable)
- exports['_cPopup']:createNotification('success', 'Sikeresen megvásároltál egy bútort! ('.. furnituresData['furnitures'][current]['furnitureName'] ..')')
- engine:setElementData(localPlayer, 'char -> money', getElementData(localPlayer, 'char -> money') - tonumber(furnituresData['furnitures'][current]['cost']))
- else
- exports['_cPopup']:createNotification('error', 'Max 8 bútort tudsz megvenni egyszerre!')
- exports['_cPopup']:createNotification('error', 'Szükséges minimum egy darabot leraknod!')
- end
- else
- exports['_cPopup']:createNotification('error', 'Nincs elég pénzed a vásárláshoz!')
- end
- end
- end
- end
- end
- end
- end
- function drawFurniture()
- if canUseMenu then
- if alpha <= 235 then
- alpha = alpha + 20
- end
- else
- if alpha >= 20 then
- alpha = alpha - 20
- end
- end
- if preview and isElement(element) then
- local cursorX, cursorY = -500, -500
- if isCursorShowing() then
- cursorX, cursorY = getCursorPosition()
- cursorX, cursorY = sx*cursorX, sy*cursorY
- if (cursorX and cursorY) and pushData['x'] ~= 0 and pushData['y'] ~= 0 then
- moveData = {cursorX - pushData['x'], cursorY - pushData['y']}
- end
- end
- setElementRotation(element, rX - moveData[2], rY, rZ + moveData[1])
- dxDrawImage(30, sy/2 - 326/2, 246, 327, '/files/images/bg_furniture.png', 0, 0, 0, tocolor(255, 255, 255, alpha))
- 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')
- 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')
- for i = 1, 5 do
- if engine:isCursorInRectangle(57, sy/2 - 196/2 + 30*i, 192, 28) then
- 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))
- else
- 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))
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement