lima Posted November 29, 2023 Share Posted November 29, 2023 I'm trying to put this dxDrawImageSection to work according to the speedometer but it's giving an error when loading the image. Could someone help me put the image to interact with the speedometer? local screen = {guiGetScreenSize ()} local resolution = {1366, 768} local scale = math.min (0.75, math.max ((screen[2] / resolution[2]), 2)) addEventHandler("onClientResourceStart", resourceRoot, function() loadSVG() end) local bollX, bollY = (screen[1] - (scale * 152)), (screen[2] - (scale * 254)) local bollTX, bollTY = (screen[1] - (scale * 183)), (screen[2] - (scale * 183)) local fuelX, fuelY = (screen[1] - (scale * 67)), (screen[2] - (scale * 67)) local textX, textY = (screen[1] - (scale * 35)), (screen[2] - (scale * 105)) local bollTTX, bollTTY = (screen[1] - (scale * 70)), (screen[2] - (scale * 60)) local font = dxCreateFont("assets/fonts/Medium.ttf", 17) addEventHandler ("onClientRender", root, function () local vehicle = getPedOccupiedVehicle(localPlayer) if not vehicle then return end local kmh = getElementSpeed(vehicle, 2) local maxVelocity = (getVehicleHandling(vehicle)["maxVelocity"]) local fuel = (getElementData(vehicle, "fuel") or 100) local motor = (getElementHealth(vehicle)) dxDrawImage(bollX - 108, bollY - 30, 280 * scale, 255 * scale, "assets/img/base.png") dxDrawImage(bollX - 10, bollY + 132 , 17 * scale, 17 * scale, "assets/img/dano.png") dxDrawImage(bollX - 39, bollY + 130 , 20 * scale, 19 * scale, "assets/img/fuel1.png") dxDrawImage(bollX + 12, bollY + 124 , 35 * scale, 35 * scale, "assets/img/lock.png") --setSVGOffset(1, -281) --createCircleStroke(1, 393 * scale, 393 * scale, 21) --drawItem(1, bollTX - 160, bollTY - 195, 200, tocolor(0, 224, 255, 255), false) --setSVGOffset(1, -281 +( maxVelocity*kmh)) dxDrawImageSection(bollTX + 72, bollTY + 120, 60 * ((getElementSpeed(vehicle,2,maxVelocity*kmh) or 100) / 100), 11, 0, 0, 60 * ((getElementSpeed(vehicle,2,maxVelocity*kmh) or 100) / 100), 11, 'assets/img/base2.png', 0, 0, 0, tocolor(255, 255, 255, alpha)) createCircleStroke(4, 50 * scale, 50 * scale, 2) drawItem(4, bollTTX - 115, bollTTY - 34, 200, tocolor(0, 224, 255, 255), false) setSVGOffset(4, (80/100*fuel)) createCircleStroke(6, 50 * scale, 50 * scale, 2) drawItem(6, bollTTX - 80, bollTTY - 34, 250, tocolor(0, 224, 255, 255), false) setSVGOffset(6, motor <= 100 and 0 or (7/150*motor)) kmh = math.floor(kmh) if (kmh == 0) then kmh = '00'..kmh elseif (kmh < 10) then kmh = '00'..kmh elseif (kmh < 100) then kmh = '0'..kmh end dxDrawText(kmh, textX - 143, textY - (90), ((textX - 143)+108), ((textY - (90))+72), tocolor(255, 255, 255, 75), 1.00, font, "center", "center", false, false, false, false, false) end) function getElementSpeed(theElement, unit) assert(isElement(theElement), "Bad argument 1 @ getElementSpeed (element expected, got " .. type(theElement) .. ")") local elementType = getElementType(theElement) assert(elementType == "player" or elementType == "ped" or elementType == "object" or elementType == "vehicle" or elementType == "projectile", "Invalid element type @ getElementSpeed (player/ped/object/vehicle/projectile expected, got " .. elementType .. ")") assert((unit == nil or type(unit) == "string" or type(unit) == "number") and (unit == nil or (tonumber(unit) and (tonumber(unit) == 0 or tonumber(unit) == 1 or tonumber(unit) == 2)) or unit == "m/s" or unit == "km/h" or unit == "mph"), "Bad argument 2 @ getElementSpeed (invalid speed unit)") unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit)) local mult = (unit == 0 or unit == "m/s") and 50 or ((unit == 1 or unit == "km/h") and 180 or 111.84681456) return (Vector3(getElementVelocity(theElement)) * mult).length end Link to comment
LujuTuJu Posted December 31, 2023 Share Posted December 31, 2023 Hello lima, I would love to help you, but you didn't show the error itself. Can't help without it! Link to comment
lima Posted January 3, 2024 Author Share Posted January 3, 2024 On 31/12/2023 at 18:55, LujuTuJu said: Olá lima, Eu adoraria ajudá-lo, mas você não mostrou o erro em si. Não posso ajudar sem isso! Hello, I'm sorry, I already solved this issue. I would actually like you to help me solve this code. the error itself is this one: (Bad argument @ 'getPlayerName' [Expected element at argument 1, got boolean] Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got nil] ) On 12/31/2023 at 6:55 PM, LujuTuJu said: Hello lima, I would love to help you, but you didn't show the error itself. Can't help without it! clienntside local rx, ry = 229, 225 local render = dxCreateRenderTarget(rx,ry,true) local sx, sy = guiGetScreenSize(); local cx,cy = 599, 354 local rx,ry = 234, 226 -- Renomeie essas variáveis para rx2, ry2 para evitar conflitos local font = dxCreateFont("assets/fonts/regular.ttf", local color = tocolor(24, 30, 40, 155) --local posSlot = {x - 2, y - 4} function isMouseInPosition(x,y,w,h) if isCursorShowing() then local sx,sy = guiGetScreenSize() local cx,cy = getCursorPosition() local cx,cy = (cx*sx),(cy*sy) if (cx >= x and cx <= x+w) and (cy >= y and cy <= y+h) then return true end end end local slotAction = { {552, 819, 50, 50, item = false, categoria = false}, {625, 819, 50, 50, item = false, categoria = false}, {703, 819, 50, 50, item = false, categoria = false}, {778, 819, 50, 50, item = false, categoria = false}, {852, 819, 50, 50, item = false, categoria = false}, } function Inv() local pesoAtual = math.floor((getElementData(localPlayer, "pesoInv") or 0)) local pesoMax = (getElementData(localPlayer, "pesoMax") or 30) dxDrawImage(458, 276, 423, 384, "assets/img/base.png") dxDrawImageSection(553, 557, (270 / pesoMax * pesoAtual), 74, 0, 0, (280 / pesoMax * pesoAtual), 78, "assets/img/pesoBar.png") dxDrawText(pesoAtual .. "/" .. pesoMax .. "", 825, 508, 820, 692, tocolor(255, 255, 255, 255), 1.00, font, "center", "center", false, false, false, false, false) dxDrawText("Quantidade", 435, 509, 820, 690, tocolor(255, 255, 255, 255), 1.00, font, "center", "center", false, false, false, false, false) if isMouseInPosition(550, 374, 25, 30) or aba == 1 then dxDrawImage(550, 374, 25, 30, "assets/img/privado.png", 0, 0, 0, tocolor(0, 191, 255, 255)) else dxDrawImage(550, 374, 25, 30, "assets/img/privado.png", 0, 0, 0, tocolor(255, 255, 255, 255)) end if isMouseInPosition(546, 429, 30, 32) or aba == 2 then dxDrawImage(546, 429, 30, 32, "assets/img/food.png", 0, 0, 0, tocolor(0, 191, 255, 255)) else dxDrawImage(546, 429, 30, 32, "assets/img/food.png", 0, 0, 0, tocolor(255, 255, 255, 255)) end if isMouseInPosition(547, 489, 32, 25) or aba == 3 then dxDrawImage(547, 489, 32, 25, "assets/img/ilegal.png", 0, 0, 0, tocolor(0, 191, 255, 255)) else dxDrawImage(547, 489, 32, 25, "assets/img/ilegal.png", 0, 0, 0, tocolor(255, 255, 255, 255)) end if isMouseInPosition(547, 542, 30, 30) or aba == 4 then dxDrawImage(547, 542, 30, 30, "assets/img/tools.png", 0, 0, 0, tocolor(0, 191, 255, 255)) else dxDrawImage(547, 542, 30, 30, "assets/img/tools.png", 0, 0, 0, tocolor(255, 255, 255, 255)) end local x, y = 4, 4 slots = {} dxSetRenderTarget(render, true); for i, v in ipairs(Itens) do if aba == tonumber(v[4]) then if i == selected then dxDrawImage(x - 3, y - 4, 56, 56, "assets/img/slot-effect.png") else dxDrawRectangle(x - 2, y - 4, 54, 54, color) end table.insert(slots, i, {x - 2, y - 4, 54, 54, v.itemID, v[4]}) print('v.itemID') dxDrawImage(x + 2, y + 2, 48, 45, "assets/itens/" .. v[1] .. ".png") dxDrawText("x" .. formatNumber(v[3]), x * 2 - 40, y * 2 + 32, 52, 53, tocolor(255, 255, 255, 255), 1.00, font, "center", "center", false, false, false, false, false) x = x + 54 + 3; if x >= 229 then x = 4; y = y + 54 + 4; end end end dxSetRenderTarget(); dxDrawImage(cx, cy, rx, ry, render); end --addEventHandler('onClientRender',root,Inv) function hotBar() if not getElementData(localPlayer, "BloqHud") then dxDrawImage(506, 780, 430, 125, "assets/img/base2.png") for i, v in ipairs(slotAction) do if (i <= 6 and getKeyState(i)) then dxDrawImage(v[1], v[2], v[3], v[4], "assets/slot-effect.png") end if v.item then dxDrawImage(v[1] + 3, v[2] + 50, v[3], v[4], "assets/itens/" .. (v.item) .. ".png") end end end end function pressedAction(button, press) if (press and tonumber(button)) then if not (getElementData(localPlayer, "BloqHud") or false) then if (tonumber(button) <= 6) and (tonumber(button) >= 1) then local i = tonumber(button) if isTimer(TimerAC) then local timerSeconds = getTimerDetails(TimerAC) notifyC("Aguarde " .. math.floor(timerSeconds / 1000) .. "s para usar novamente!", "error") else if slotAction.item and slotAction.categoria then toggleControl("next_weapon", false) toggleControl("previous_weapon", false) triggerServerEvent("LINCE.useItem", localPlayer, localPlayer, slotAction.item, tonumber(1), slotAction.categoria, slotAction.dataItem) if not config["Hotbar"][slotAction.item] then updateAction(slotAction.item) bloqueado = true TimerAC = setTimer(function() bloqueado = false end, 2000, 1) end end end end end end end addEventHandler("onClientRender", root, hotBar) addEventHandler("onClientClick", root, function(b, s) if s == "down" and b == "left" then if isEventHandlerAdded("onClientRender", root, Inv) then selected = {} if (isMouseInPosition(552, 372, 25, 30) and not page) then aba = 1 return end if (isMouseInPosition(546, 428, 30, 32) and not page) then aba = 2 return end if (isMouseInPosition(547, 488, 32, 25) and not page) then aba = 3 return end if (isMouseInPosition(548, 540, 30, 30) and not page) then aba = 4 return end if isMouseInPosition(cx, cy, rx, ry)then for i, v in pairs(slots) do if isMouseInPosition(v[1] + cx, v[2] + cy, v[3], v[4]) then selected = i playSound("assets/sfx/release.mp3") return end end end end end end) function onClientClickUseItem(id, item, quantia) triggerServerEvent("useItem", localPlayer, id, item, quantia) end function click2(b,player, _, id, item, quantia,...) if b == "left" then for i, v in pairs(slots) do if isMouseInPosition(v[1] + cx, v[2] + cy, v[3], v[4]) and not (getElementData(localPlayer, "usandoItem") or false) then local id = slots[5] local item = slots[6] local quantia = 1 onClientClickUseItem(id, item, quantia) selected = i end end end end addEventHandler("onClientDoubleClick", root, click2) addEvent("attActionBar", true) addEventHandler("attActionBar", root, function() ItensAction = {} for i,v in ipairs(slotAction) do v.item = false v.qnt = false v.categoria = false end end) function setItemSlot(newslot) for i,v in ipairs(Itens) do if aba == tonumber(v[4]) and itemSelect == i and select ~= newslot then v[5] = newslot triggerServerEvent("UpdateSlot", localPlayer, localPlayer, v[2], newslot) select = 0 itemSelect = nil break elseif aba == tonumber(v[4]) and itemSelect == i and select == newslot then select = 0 itemSelect = nil break end end end addEvent("inserirItem", true) addEventHandler("inserirItem", root, function(tabela) Itens = {} for i, v in ipairs(tabela) do Itens = {v.itemID, v.nameItem, v.qnt, v.category, tonumber(v.slot), v.dataItem} end end) addEvent("soundItem", true) addEventHandler("soundItem", root, function(action, duration) if action == "eat" then playSound("assets/sfx/eat.mp3") elseif action == "drink" then playSound("assets/sfx/drink.mp3") end end ) function openInv() if not isEventHandlerAdded("onClientRender", root, Inv) then addEventHandler("onClientRender", root, Inv) showCursor(true) selectSlot = false quantitySelect = 1 manageEdits = false select = false itemSelect = false subWindow = false aba = 1 else removeEventHandler("onClientRender", root, Inv) showCursor(false) end end addEvent("openInv", true) addEventHandler("openInv", root, openInv) bindKey("b", "down", openInv) function isEventHandlerAdded( sEventName, pElementAttachedTo, func ) if type( sEventName ) == "string" and isElement( pElementAttachedTo ) and type( func ) == "function" then local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo ) if type( aAttachedFunctions ) == "table" and #aAttachedFunctions > 0 then for i, v in ipairs( aAttachedFunctions ) do if v == func then return true end end end end return false end serverside Inventario = {} weaponStates = {} ArmaEquipada = {} comProposta = {} UsouPicareta = {} mochilinha = {} UsouFacao = {} UsouPa = {} object = {} UsouBastao = {} mascara = {} Skate = {} Usando = {} local MuniIDS = { --ID arma jogo, ID munição [30] = 40, [25] = 42, [22] = 41, [31] = 39, [34] = 39, [29] = 41, [32] = 39, [24] = 41, } local weaponMuni = { --ID arma jogo, elementdata munição [30] = "AK-47", [25] = "DOZE", [22] = "SUBANDPISTOL", [31] = "MUNIM4ANDSNIPER", [34] = "MUNIM4ANDSNIPER", [29] = "SUBANDPISTOL", [32] = "SUBANDPISTOL", [24] = "SUBANDPISTOL", } local itemGiveMuni = { --elementdata munição, id munição ["AK-47"] = 40, ["DOZE"] = 42, ["SUBANDPISTOL"] = 41, ["MUNIM4ANDSNIPER"] = 39, } taserEquip = {} addEventHandler("onResourceStart", resourceRoot, function() db = dbConnect("sqlite", "data.sqlite") dbExec(db, "CREATE TABLE IF NOT EXISTS Itens (account, itemID, nameItem, qnt, category, slot, dataItem)") if config["Mensagem Start"] then outputDebugString("["..getResourceName(getThisResource()).."] Startado com sucesso!") end setTimer(function() for i, v in ipairs(getElementsByType("player")) do attInv(v) attPeso(v) setElementData(v, "pesoMax", 30) if (getElementData(v, "usandoItem") or false) then setElementData(v, "usandoItem", false) end end end, 1000, 1) end) function giveItem1(player, _, id, item, quantia) if aclGetGroup("Console") and isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Console")) then if not tonumber(id) and tonumber(item) and tonumber(quantia) then notifyS(player, "Digite corretamente. /item [ID] [Item] [Quantia]", "error") else local receiver = getPlayerFromID(tonumber(id)) if not isElement(receiver) then notifyS(player, "Este jogador está ausente!", "info") else iditem = tonumber(item) quantiaitem = tonumber(quantia) if quantiaitem == nil then notifyS(player, "Quantia de item invalida!", "error") else if (tonumber(iditem) == nil) then notifyS(player, "Ocorreu algum erro!", "error") else if (tonumber(iditem) > tonumber(#config["Itens"])) then notifyS(player, "Este item não existe!", "error") else local peso = math.floor(getElementData(receiver, "pesoInv")) or 0 if ((config["Itens"][iditem][3] * tonumber(quantiaitem)) + peso > (getElementData(player, "pesoMax") or 30)) then notifyS(player, "A mochila do jogador está cheia.", "error") else local NameItem = tostring(config["Itens"][iditem][1]) notifyS(player, "Você adicionou "..formatNumber(quantia).."x do item ("..NameItem..") para "..getPlayerName(receiver).."!", "info") giveItem(receiver, tonumber(item), tonumber(quantia)) ---exports["i9_util"]:messageDiscord("O jogador(a) "..(exports["i9_util"]:puxarNome(player)).." ("..(exports["i9_util"]:puxarID(player))..") adicionou "..formatNumber(quantia).."x do item ("..NameItem..") para "..getPlayerName(receiver).."!", "https://discord.com/api/webhooks/1121640792671395931/W4yq5lm7WBNVcaES-27Ef5-75VBc7MWZ29A8S4rA-iP5Cpr6u7QQiN1PSnNLQpaFEZo7") end end end end end end end end addCommandHandler("item", giveItem1) function giveItem(target, item, quantia, dataItem) if target and isElement(target) and getElementType(target) == "player" and tonumber(item) and tonumber(quantia) then local NomeItem = tostring(config["Itens"][tonumber(item)][1]) local Categoria = tonumber(config["Itens"][tonumber(item)][2]) local peso = math.floor(getElementData(target, "pesoInv")) or 0 if not isElement(target) then notifyS(player, "O jogador não está online!", "error") else if (tonumber(quantia) == nil) then notifyS(target, "Ocorreu algum erro a receber algum item!", "error") else if (tonumber(item) == nil) then notifyS(player, "Ocorreu algum erro a receber algum item!", "error") else if ((config["Itens"][tonumber(item)][3] * tonumber(quantia)) + peso > (getElementData(target, "pesoMax") or 30)) then notifyS(target, "A sua mochila está cheia.", "error") else local result = dbPoll(dbQuery(db, "SELECT * FROM Itens WHERE itemID = ? AND account = ?", tonumber(item), getAccountName(getPlayerAccount(target))), -1) if config["Não agrupar"][item] then dbExec(db, "INSERT INTO Itens (account, itemID, nameItem, qnt, category, slot, dataItem) VALUES(?, ?, ?, ?, ?, ?, ?)", getAccountName(getPlayerAccount(target)), tonumber(item), item == 110 and "CNH "..dataItem.typeCategory or NomeItem, tonumber(quantia), tonumber(Categoria), getFreeSlot(getAccountName(getPlayerAccount(target)), tonumber(Categoria)), dataItem and toJSON(dataItem) or {}) else if (#result ~= 0) then dbExec(db, "UPDATE Itens SET qnt = ? WHERE itemID = ? AND account = ?", result[1]["qnt"] + tonumber(quantia), tonumber(item), getAccountName(getPlayerAccount(target))) else dbExec(db, "INSERT INTO Itens (account, itemID, nameItem, qnt, category, slot, dataItem) VALUES(?, ?, ?, ?, ?, ?, ?)", getAccountName(getPlayerAccount(target)), tonumber(item), NomeItem, tonumber(quantia), tonumber(Categoria), getFreeSlot(getAccountName(getPlayerAccount(target)), tonumber(Categoria)), dataItem and toJSON(dataItem) or {}) end end attInv(target) attPeso(target) return true end end end end end return false end addEvent("giveItem", true) addEventHandler("giveItem", root, giveItem) function takeItem1(player, _, id, item, quantia) if aclGetGroup("Console") and isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Console")) then if not tonumber(id) and tonumber(item) and tonumber(quantia) then notifyS(player, "Digite corretamente. /takeitem [ID] [Item] [Quantia]", "error") else local target = getPlayerFromID(tonumber(id)) if not isElement(target) then notifyS(player, "Este jogador está ausente!", "info") else iditem = tonumber(item) quantiaitem = tonumber(quantia) if quantiaitem == nil then notifyS(player, "Quantia de item inválida!", "error") else if (tonumber(iditem) == nil) then notifyS(player, "Ocorreu algum erro!", "error") else if (tonumber(iditem) > tonumber(#config["Itens"])) then notifyS(player, "Este item não existe!", "error") else local result = dbPoll(dbQuery(db, "SELECT * FROM Itens WHERE itemID = ? AND account = ?", tonumber(item), getAccountName(getPlayerAccount(target))), -1) if #result ~= 0 and result[1]["qnt"] >= tonumber(quantia) then local NomeItem = tostring(config["Itens"][tonumber(item)][1]) notifyS(player, "Você retirou "..formatNumber(quantia).."x do item ("..NomeItem..") de "..getPlayerName(target).."!", "info") takeItem(target, tonumber(item), tonumber(quantia)) else notifyS(player, "O jogador não possui a quantidade necessária desse item!", "error") end end end end end end end end addCommandHandler("take", takeItem1) function takeItem(target, item, quantia) if target and isElement(target) and getElementType(target) == "player" and tonumber(item) and tonumber(quantia) then local result = dbPoll(dbQuery(db, "SELECT * FROM Itens WHERE itemID = ? AND account = ?", tonumber(item), getAccountName(getPlayerAccount(target))), -1) if #result ~= 0 and result[1]["qnt"] >= tonumber(quantia) then local newQuantity = result[1]["qnt"] - tonumber(quantia) if newQuantity > 0 then dbExec(db, "UPDATE Itens SET qnt = ? WHERE itemID = ? AND account = ?", newQuantity, tonumber(item), getAccountName(getPlayerAccount(target))) else dbExec(db, "DELETE FROM Itens WHERE itemID = ? AND account = ?", tonumber(item), getAccountName(getPlayerAccount(target))) end attInv(target) attPeso(target) return true else return false end end return false end addEvent("takeItem", true) addEventHandler("takeItem", root, takeItem) function useItem(player, _, id, item, quantia) if aclGetGroup("Console") and isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Console")) then if not tonumber(id) or not tonumber(item) or not tonumber(quantia) then notifyS(player, "Digite corretamente. /useitem [ID] [Item] [Quantia]", "error") else local target = getPlayerFromID(tonumber(id)) if not isElement(target) then notifyS(player, "Este jogador está ausente!", "info") else iditem = tonumber(item) quantiaitem = tonumber(quantia) if quantiaitem == nil then notifyS(player, "Quantia de item inválida!", "error") else if (tonumber(iditem) == nil) then notifyS(player, "Ocorreu algum erro!", "error") else if (tonumber(iditem) > tonumber(#config["Itens"])) then notifyS(player, "Este item não existe!", "error") else local result = dbPoll(dbQuery(db, "SELECT * FROM Itens WHERE itemID = ? AND account = ?", tonumber(item), getAccountName(getPlayerAccount(target))), -1) if #result ~= 0 and result[1]["qnt"] >= tonumber(quantia) then local NomeItem = tostring(config["Itens"][tonumber(item)][1]) notifyS(player, "Você usou "..formatNumber(quantia).."x do item ("..NomeItem..") em "..getPlayerName(target).."!", "info") useItemAction(target, tonumber(item), tonumber(quantia)) else notifyS(player, "O jogador não possui a quantidade necessária desse item!", "error") end end end end end end end end addCommandHandler("use", useItem) addEvent("useItem", true) addEventHandler("useItem", root, useItem) function useItemAction(player, item, quantia) -- Adicione aqui a lógica para ação de usar o item no servidor -- Exemplo: removerVisualDoItem(player, item) takeItem(player, item, quantia) attInv(player) attPeso(player) end function onFireWeapon(weapon) if not (getElementData(source, "LINCE.podeAtirarSem") or false) then if weapon == 34 or weapon == 30 or weapon == 25 or weapon == 22 or weapon == 31 or weapon == 29 or weapon == 32 or weapon == 24 then --ID da arma do jogo local QuantiaMun = getElementData(source, weaponMuni[weapon]) or 0 if (QuantiaMun >= 2) then setElementData(source, weaponMuni[weapon], QuantiaMun - 1) else setElementData(source, weaponMuni[weapon], 0) if ArmaEquipada[source] then ArmaEquipada[source][weapon] = false end weaponStates[source] = false takeAllWeapons(source) notifyS(source, "Sua munição acabou.", "info") end end end end addEventHandler("onPlayerWeaponFire", root, onFireWeapon) function attInv(player) local result = dbPoll(dbQuery(db, "SELECT * FROM Itens WHERE account = ?", getAccountName(getPlayerAccount(player))), -1) Inventario[player] = result triggerClientEvent(player, "inserirItem", player, Inventario[player]) end function attPeso(player) setElementData(player, "pesoInv", getPesoInv(player)) end addEvent("attPeso", true) addEventHandler("attPeso", root, attPeso) addEventHandler("onPlayerLogin", root, function() attInv(source) attPeso(source) end) function getPesoInv(player) pesoTotal = 0 local itens = Inventario[player] if type(itens) == "table" then if #itens ~= 0 then for i, v in ipairs(itens) do local quantia = tonumber(v["qnt"]) local iditem = tonumber(v["itemID"]) pesoTotal = pesoTotal + (quantia * config["Itens"][iditem][3]) end end end return pesoTotal end function getItemNameFromID(id) if config["Itens"][id] then return config["Itens"][id][1] end return "" end function getPlayerFromID(id) if (id) then for i, v in ipairs(getElementsByType("player")) do if not isGuestAccount(getPlayerAccount(v)) then if (getElementData(v, "ID") == tonumber(id)) then return v end end end end return false end function getAgrupar(item) if config["Não agrupar"][item] then return true end return false end On 12/31/2023 at 6:55 PM, LujuTuJu said: Hello lima, I would love to help you, but you didn't show the error itself. Can't help without it! the error occurs in the onClientDoubleClick function Link to comment
LujuTuJu Posted January 4, 2024 Share Posted January 4, 2024 On 03/01/2024 at 08:08, lima said: Hello, I'm sorry, I already solved this issue. I would actually like you to help me solve this code. the error itself is this one: (Bad argument @ 'getPlayerName' [Expected element at argument 1, got boolean] Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got nil] ) clienntside local rx, ry = 229, 225 local render = dxCreateRenderTarget(rx,ry,true) local sx, sy = guiGetScreenSize(); local cx,cy = 599, 354 local rx,ry = 234, 226 -- Renomeie essas variáveis para rx2, ry2 para evitar conflitos local font = dxCreateFont("assets/fonts/regular.ttf", local color = tocolor(24, 30, 40, 155) --local posSlot = {x - 2, y - 4} function isMouseInPosition(x,y,w,h) if isCursorShowing() then local sx,sy = guiGetScreenSize() local cx,cy = getCursorPosition() local cx,cy = (cx*sx),(cy*sy) if (cx >= x and cx <= x+w) and (cy >= y and cy <= y+h) then return true end end end local slotAction = { {552, 819, 50, 50, item = false, categoria = false}, {625, 819, 50, 50, item = false, categoria = false}, {703, 819, 50, 50, item = false, categoria = false}, {778, 819, 50, 50, item = false, categoria = false}, {852, 819, 50, 50, item = false, categoria = false}, } function Inv() local pesoAtual = math.floor((getElementData(localPlayer, "pesoInv") or 0)) local pesoMax = (getElementData(localPlayer, "pesoMax") or 30) dxDrawImage(458, 276, 423, 384, "assets/img/base.png") dxDrawImageSection(553, 557, (270 / pesoMax * pesoAtual), 74, 0, 0, (280 / pesoMax * pesoAtual), 78, "assets/img/pesoBar.png") dxDrawText(pesoAtual .. "/" .. pesoMax .. "", 825, 508, 820, 692, tocolor(255, 255, 255, 255), 1.00, font, "center", "center", false, false, false, false, false) dxDrawText("Quantidade", 435, 509, 820, 690, tocolor(255, 255, 255, 255), 1.00, font, "center", "center", false, false, false, false, false) if isMouseInPosition(550, 374, 25, 30) or aba == 1 then dxDrawImage(550, 374, 25, 30, "assets/img/privado.png", 0, 0, 0, tocolor(0, 191, 255, 255)) else dxDrawImage(550, 374, 25, 30, "assets/img/privado.png", 0, 0, 0, tocolor(255, 255, 255, 255)) end if isMouseInPosition(546, 429, 30, 32) or aba == 2 then dxDrawImage(546, 429, 30, 32, "assets/img/food.png", 0, 0, 0, tocolor(0, 191, 255, 255)) else dxDrawImage(546, 429, 30, 32, "assets/img/food.png", 0, 0, 0, tocolor(255, 255, 255, 255)) end if isMouseInPosition(547, 489, 32, 25) or aba == 3 then dxDrawImage(547, 489, 32, 25, "assets/img/ilegal.png", 0, 0, 0, tocolor(0, 191, 255, 255)) else dxDrawImage(547, 489, 32, 25, "assets/img/ilegal.png", 0, 0, 0, tocolor(255, 255, 255, 255)) end if isMouseInPosition(547, 542, 30, 30) or aba == 4 then dxDrawImage(547, 542, 30, 30, "assets/img/tools.png", 0, 0, 0, tocolor(0, 191, 255, 255)) else dxDrawImage(547, 542, 30, 30, "assets/img/tools.png", 0, 0, 0, tocolor(255, 255, 255, 255)) end local x, y = 4, 4 slots = {} dxSetRenderTarget(render, true); for i, v in ipairs(Itens) do if aba == tonumber(v[4]) then if i == selected then dxDrawImage(x - 3, y - 4, 56, 56, "assets/img/slot-effect.png") else dxDrawRectangle(x - 2, y - 4, 54, 54, color) end table.insert(slots, i, {x - 2, y - 4, 54, 54, v.itemID, v[4]}) print('v.itemID') dxDrawImage(x + 2, y + 2, 48, 45, "assets/itens/" .. v[1] .. ".png") dxDrawText("x" .. formatNumber(v[3]), x * 2 - 40, y * 2 + 32, 52, 53, tocolor(255, 255, 255, 255), 1.00, font, "center", "center", false, false, false, false, false) x = x + 54 + 3; if x >= 229 then x = 4; y = y + 54 + 4; end end end dxSetRenderTarget(); dxDrawImage(cx, cy, rx, ry, render); end --addEventHandler('onClientRender',root,Inv) function hotBar() if not getElementData(localPlayer, "BloqHud") then dxDrawImage(506, 780, 430, 125, "assets/img/base2.png") for i, v in ipairs(slotAction) do if (i <= 6 and getKeyState(i)) then dxDrawImage(v[1], v[2], v[3], v[4], "assets/slot-effect.png") end if v.item then dxDrawImage(v[1] + 3, v[2] + 50, v[3], v[4], "assets/itens/" .. (v.item) .. ".png") end end end end function pressedAction(button, press) if (press and tonumber(button)) then if not (getElementData(localPlayer, "BloqHud") or false) then if (tonumber(button) <= 6) and (tonumber(button) >= 1) then local i = tonumber(button) if isTimer(TimerAC) then local timerSeconds = getTimerDetails(TimerAC) notifyC("Aguarde " .. math.floor(timerSeconds / 1000) .. "s para usar novamente!", "error") else if slotAction.item and slotAction.categoria then toggleControl("next_weapon", false) toggleControl("previous_weapon", false) triggerServerEvent("LINCE.useItem", localPlayer, localPlayer, slotAction.item, tonumber(1), slotAction.categoria, slotAction.dataItem) if not config["Hotbar"][slotAction.item] then updateAction(slotAction.item) bloqueado = true TimerAC = setTimer(function() bloqueado = false end, 2000, 1) end end end end end end end addEventHandler("onClientRender", root, hotBar) addEventHandler("onClientClick", root, function(b, s) if s == "down" and b == "left" then if isEventHandlerAdded("onClientRender", root, Inv) then selected = {} if (isMouseInPosition(552, 372, 25, 30) and not page) then aba = 1 return end if (isMouseInPosition(546, 428, 30, 32) and not page) then aba = 2 return end if (isMouseInPosition(547, 488, 32, 25) and not page) then aba = 3 return end if (isMouseInPosition(548, 540, 30, 30) and not page) then aba = 4 return end if isMouseInPosition(cx, cy, rx, ry)then for i, v in pairs(slots) do if isMouseInPosition(v[1] + cx, v[2] + cy, v[3], v[4]) then selected = i playSound("assets/sfx/release.mp3") return end end end end end end) function onClientClickUseItem(id, item, quantia) triggerServerEvent("useItem", localPlayer, id, item, quantia) end function click2(b,player, _, id, item, quantia,...) if b == "left" then for i, v in pairs(slots) do if isMouseInPosition(v[1] + cx, v[2] + cy, v[3], v[4]) and not (getElementData(localPlayer, "usandoItem") or false) then local id = slots[5] local item = slots[6] local quantia = 1 onClientClickUseItem(id, item, quantia) selected = i end end end end addEventHandler("onClientDoubleClick", root, click2) addEvent("attActionBar", true) addEventHandler("attActionBar", root, function() ItensAction = {} for i,v in ipairs(slotAction) do v.item = false v.qnt = false v.categoria = false end end) function setItemSlot(newslot) for i,v in ipairs(Itens) do if aba == tonumber(v[4]) and itemSelect == i and select ~= newslot then v[5] = newslot triggerServerEvent("UpdateSlot", localPlayer, localPlayer, v[2], newslot) select = 0 itemSelect = nil break elseif aba == tonumber(v[4]) and itemSelect == i and select == newslot then select = 0 itemSelect = nil break end end end addEvent("inserirItem", true) addEventHandler("inserirItem", root, function(tabela) Itens = {} for i, v in ipairs(tabela) do Itens = {v.itemID, v.nameItem, v.qnt, v.category, tonumber(v.slot), v.dataItem} end end) addEvent("soundItem", true) addEventHandler("soundItem", root, function(action, duration) if action == "eat" then playSound("assets/sfx/eat.mp3") elseif action == "drink" then playSound("assets/sfx/drink.mp3") end end ) function openInv() if not isEventHandlerAdded("onClientRender", root, Inv) then addEventHandler("onClientRender", root, Inv) showCursor(true) selectSlot = false quantitySelect = 1 manageEdits = false select = false itemSelect = false subWindow = false aba = 1 else removeEventHandler("onClientRender", root, Inv) showCursor(false) end end addEvent("openInv", true) addEventHandler("openInv", root, openInv) bindKey("b", "down", openInv) function isEventHandlerAdded( sEventName, pElementAttachedTo, func ) if type( sEventName ) == "string" and isElement( pElementAttachedTo ) and type( func ) == "function" then local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo ) if type( aAttachedFunctions ) == "table" and #aAttachedFunctions > 0 then for i, v in ipairs( aAttachedFunctions ) do if v == func then return true end end end end return false end serverside Inventario = {} weaponStates = {} ArmaEquipada = {} comProposta = {} UsouPicareta = {} mochilinha = {} UsouFacao = {} UsouPa = {} object = {} UsouBastao = {} mascara = {} Skate = {} Usando = {} local MuniIDS = { --ID arma jogo, ID munição [30] = 40, [25] = 42, [22] = 41, [31] = 39, [34] = 39, [29] = 41, [32] = 39, [24] = 41, } local weaponMuni = { --ID arma jogo, elementdata munição [30] = "AK-47", [25] = "DOZE", [22] = "SUBANDPISTOL", [31] = "MUNIM4ANDSNIPER", [34] = "MUNIM4ANDSNIPER", [29] = "SUBANDPISTOL", [32] = "SUBANDPISTOL", [24] = "SUBANDPISTOL", } local itemGiveMuni = { --elementdata munição, id munição ["AK-47"] = 40, ["DOZE"] = 42, ["SUBANDPISTOL"] = 41, ["MUNIM4ANDSNIPER"] = 39, } taserEquip = {} addEventHandler("onResourceStart", resourceRoot, function() db = dbConnect("sqlite", "data.sqlite") dbExec(db, "CREATE TABLE IF NOT EXISTS Itens (account, itemID, nameItem, qnt, category, slot, dataItem)") if config["Mensagem Start"] then outputDebugString("["..getResourceName(getThisResource()).."] Startado com sucesso!") end setTimer(function() for i, v in ipairs(getElementsByType("player")) do attInv(v) attPeso(v) setElementData(v, "pesoMax", 30) if (getElementData(v, "usandoItem") or false) then setElementData(v, "usandoItem", false) end end end, 1000, 1) end) function giveItem1(player, _, id, item, quantia) if aclGetGroup("Console") and isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Console")) then if not tonumber(id) and tonumber(item) and tonumber(quantia) then notifyS(player, "Digite corretamente. /item [ID] [Item] [Quantia]", "error") else local receiver = getPlayerFromID(tonumber(id)) if not isElement(receiver) then notifyS(player, "Este jogador está ausente!", "info") else iditem = tonumber(item) quantiaitem = tonumber(quantia) if quantiaitem == nil then notifyS(player, "Quantia de item invalida!", "error") else if (tonumber(iditem) == nil) then notifyS(player, "Ocorreu algum erro!", "error") else if (tonumber(iditem) > tonumber(#config["Itens"])) then notifyS(player, "Este item não existe!", "error") else local peso = math.floor(getElementData(receiver, "pesoInv")) or 0 if ((config["Itens"][iditem][3] * tonumber(quantiaitem)) + peso > (getElementData(player, "pesoMax") or 30)) then notifyS(player, "A mochila do jogador está cheia.", "error") else local NameItem = tostring(config["Itens"][iditem][1]) notifyS(player, "Você adicionou "..formatNumber(quantia).."x do item ("..NameItem..") para "..getPlayerName(receiver).."!", "info") giveItem(receiver, tonumber(item), tonumber(quantia)) ---exports["i9_util"]:messageDiscord("O jogador(a) "..(exports["i9_util"]:puxarNome(player)).." ("..(exports["i9_util"]:puxarID(player))..") adicionou "..formatNumber(quantia).."x do item ("..NameItem..") para "..getPlayerName(receiver).."!", "https://discord.com/api/webhooks/1121640792671395931/W4yq5lm7WBNVcaES-27Ef5-75VBc7MWZ29A8S4rA-iP5Cpr6u7QQiN1PSnNLQpaFEZo7") end end end end end end end end addCommandHandler("item", giveItem1) function giveItem(target, item, quantia, dataItem) if target and isElement(target) and getElementType(target) == "player" and tonumber(item) and tonumber(quantia) then local NomeItem = tostring(config["Itens"][tonumber(item)][1]) local Categoria = tonumber(config["Itens"][tonumber(item)][2]) local peso = math.floor(getElementData(target, "pesoInv")) or 0 if not isElement(target) then notifyS(player, "O jogador não está online!", "error") else if (tonumber(quantia) == nil) then notifyS(target, "Ocorreu algum erro a receber algum item!", "error") else if (tonumber(item) == nil) then notifyS(player, "Ocorreu algum erro a receber algum item!", "error") else if ((config["Itens"][tonumber(item)][3] * tonumber(quantia)) + peso > (getElementData(target, "pesoMax") or 30)) then notifyS(target, "A sua mochila está cheia.", "error") else local result = dbPoll(dbQuery(db, "SELECT * FROM Itens WHERE itemID = ? AND account = ?", tonumber(item), getAccountName(getPlayerAccount(target))), -1) if config["Não agrupar"][item] then dbExec(db, "INSERT INTO Itens (account, itemID, nameItem, qnt, category, slot, dataItem) VALUES(?, ?, ?, ?, ?, ?, ?)", getAccountName(getPlayerAccount(target)), tonumber(item), item == 110 and "CNH "..dataItem.typeCategory or NomeItem, tonumber(quantia), tonumber(Categoria), getFreeSlot(getAccountName(getPlayerAccount(target)), tonumber(Categoria)), dataItem and toJSON(dataItem) or {}) else if (#result ~= 0) then dbExec(db, "UPDATE Itens SET qnt = ? WHERE itemID = ? AND account = ?", result[1]["qnt"] + tonumber(quantia), tonumber(item), getAccountName(getPlayerAccount(target))) else dbExec(db, "INSERT INTO Itens (account, itemID, nameItem, qnt, category, slot, dataItem) VALUES(?, ?, ?, ?, ?, ?, ?)", getAccountName(getPlayerAccount(target)), tonumber(item), NomeItem, tonumber(quantia), tonumber(Categoria), getFreeSlot(getAccountName(getPlayerAccount(target)), tonumber(Categoria)), dataItem and toJSON(dataItem) or {}) end end attInv(target) attPeso(target) return true end end end end end return false end addEvent("giveItem", true) addEventHandler("giveItem", root, giveItem) function takeItem1(player, _, id, item, quantia) if aclGetGroup("Console") and isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Console")) then if not tonumber(id) and tonumber(item) and tonumber(quantia) then notifyS(player, "Digite corretamente. /takeitem [ID] [Item] [Quantia]", "error") else local target = getPlayerFromID(tonumber(id)) if not isElement(target) then notifyS(player, "Este jogador está ausente!", "info") else iditem = tonumber(item) quantiaitem = tonumber(quantia) if quantiaitem == nil then notifyS(player, "Quantia de item inválida!", "error") else if (tonumber(iditem) == nil) then notifyS(player, "Ocorreu algum erro!", "error") else if (tonumber(iditem) > tonumber(#config["Itens"])) then notifyS(player, "Este item não existe!", "error") else local result = dbPoll(dbQuery(db, "SELECT * FROM Itens WHERE itemID = ? AND account = ?", tonumber(item), getAccountName(getPlayerAccount(target))), -1) if #result ~= 0 and result[1]["qnt"] >= tonumber(quantia) then local NomeItem = tostring(config["Itens"][tonumber(item)][1]) notifyS(player, "Você retirou "..formatNumber(quantia).."x do item ("..NomeItem..") de "..getPlayerName(target).."!", "info") takeItem(target, tonumber(item), tonumber(quantia)) else notifyS(player, "O jogador não possui a quantidade necessária desse item!", "error") end end end end end end end end addCommandHandler("take", takeItem1) function takeItem(target, item, quantia) if target and isElement(target) and getElementType(target) == "player" and tonumber(item) and tonumber(quantia) then local result = dbPoll(dbQuery(db, "SELECT * FROM Itens WHERE itemID = ? AND account = ?", tonumber(item), getAccountName(getPlayerAccount(target))), -1) if #result ~= 0 and result[1]["qnt"] >= tonumber(quantia) then local newQuantity = result[1]["qnt"] - tonumber(quantia) if newQuantity > 0 then dbExec(db, "UPDATE Itens SET qnt = ? WHERE itemID = ? AND account = ?", newQuantity, tonumber(item), getAccountName(getPlayerAccount(target))) else dbExec(db, "DELETE FROM Itens WHERE itemID = ? AND account = ?", tonumber(item), getAccountName(getPlayerAccount(target))) end attInv(target) attPeso(target) return true else return false end end return false end addEvent("takeItem", true) addEventHandler("takeItem", root, takeItem) function useItem(player, _, id, item, quantia) if aclGetGroup("Console") and isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Console")) then if not tonumber(id) or not tonumber(item) or not tonumber(quantia) then notifyS(player, "Digite corretamente. /useitem [ID] [Item] [Quantia]", "error") else local target = getPlayerFromID(tonumber(id)) if not isElement(target) then notifyS(player, "Este jogador está ausente!", "info") else iditem = tonumber(item) quantiaitem = tonumber(quantia) if quantiaitem == nil then notifyS(player, "Quantia de item inválida!", "error") else if (tonumber(iditem) == nil) then notifyS(player, "Ocorreu algum erro!", "error") else if (tonumber(iditem) > tonumber(#config["Itens"])) then notifyS(player, "Este item não existe!", "error") else local result = dbPoll(dbQuery(db, "SELECT * FROM Itens WHERE itemID = ? AND account = ?", tonumber(item), getAccountName(getPlayerAccount(target))), -1) if #result ~= 0 and result[1]["qnt"] >= tonumber(quantia) then local NomeItem = tostring(config["Itens"][tonumber(item)][1]) notifyS(player, "Você usou "..formatNumber(quantia).."x do item ("..NomeItem..") em "..getPlayerName(target).."!", "info") useItemAction(target, tonumber(item), tonumber(quantia)) else notifyS(player, "O jogador não possui a quantidade necessária desse item!", "error") end end end end end end end end addCommandHandler("use", useItem) addEvent("useItem", true) addEventHandler("useItem", root, useItem) function useItemAction(player, item, quantia) -- Adicione aqui a lógica para ação de usar o item no servidor -- Exemplo: removerVisualDoItem(player, item) takeItem(player, item, quantia) attInv(player) attPeso(player) end function onFireWeapon(weapon) if not (getElementData(source, "LINCE.podeAtirarSem") or false) then if weapon == 34 or weapon == 30 or weapon == 25 or weapon == 22 or weapon == 31 or weapon == 29 or weapon == 32 or weapon == 24 then --ID da arma do jogo local QuantiaMun = getElementData(source, weaponMuni[weapon]) or 0 if (QuantiaMun >= 2) then setElementData(source, weaponMuni[weapon], QuantiaMun - 1) else setElementData(source, weaponMuni[weapon], 0) if ArmaEquipada[source] then ArmaEquipada[source][weapon] = false end weaponStates[source] = false takeAllWeapons(source) notifyS(source, "Sua munição acabou.", "info") end end end end addEventHandler("onPlayerWeaponFire", root, onFireWeapon) function attInv(player) local result = dbPoll(dbQuery(db, "SELECT * FROM Itens WHERE account = ?", getAccountName(getPlayerAccount(player))), -1) Inventario[player] = result triggerClientEvent(player, "inserirItem", player, Inventario[player]) end function attPeso(player) setElementData(player, "pesoInv", getPesoInv(player)) end addEvent("attPeso", true) addEventHandler("attPeso", root, attPeso) addEventHandler("onPlayerLogin", root, function() attInv(source) attPeso(source) end) function getPesoInv(player) pesoTotal = 0 local itens = Inventario[player] if type(itens) == "table" then if #itens ~= 0 then for i, v in ipairs(itens) do local quantia = tonumber(v["qnt"]) local iditem = tonumber(v["itemID"]) pesoTotal = pesoTotal + (quantia * config["Itens"][iditem][3]) end end end return pesoTotal end function getItemNameFromID(id) if config["Itens"][id] then return config["Itens"][id][1] end return "" end function getPlayerFromID(id) if (id) then for i, v in ipairs(getElementsByType("player")) do if not isGuestAccount(getPlayerAccount(v)) then if (getElementData(v, "ID") == tonumber(id)) then return v end end end end return false end function getAgrupar(item) if config["Não agrupar"][item] then return true end return false end the error occurs in the onClientDoubleClick function Would love to see the full error, which line is the one that containts the error. Link to comment
lima Posted January 4, 2024 Author Share Posted January 4, 2024 6 hours ago, LujuTuJu said: Would love to see the full error, which line is the one that containts the error. The error was actually on the line " table.insert(slots, i, {x - 2, y - 4, 54, 54, v.itemID, v[4]})" but it has already been resolved. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now