SRmasazuka Posted May 15, 2021 Share Posted May 15, 2021 Hello everybody. I have a level code and a HUD. However, the HUD always returns level 0, even with the correct code and getElementData pulling saved level information. I really don't understand why it doesn't work. Even after hours of reading documentation about. Does anyone have light? Script LEVEL Cod -- -- -_-_-_-_- SCRIPT LEVE POR HORA -_-_-_-_- -- -_-_-_-_- EDITADO POR FAIK_MORNINGSTAR -_-_-_-_- -- exports [ "scoreboard" ]:addScoreboardColumn ( "Level") function upLevel (thePlayer) for i,player in ipairs(getElementsByType("player")) do if ( player ) then if ( getPlayerAccount(player) ) and not ( isGuestAccount(getPlayerAccount(player)) ) then setElementData(player,"minutes",(getElementData(player,"minutes") or 0) +1) if ( getElementData(player,"minutes") > 59 ) then setElementData(player,"minutes",0) setElementData(player,"Level",(getElementData(player,"Level") or 0) +1) local bonus = math.random(25,950) local interest = math.random(25,150) local value = (bonus-interest) givePlayerMoney(player,value) exports.Scripts_Dxmessages:outputDx(player,'#1E90FF[LEVEL]#ffffffVocê jogou durante 1hora e Obteve +1 level.',player,255,255,255,true) outputChatBox("#FFFFFFPagamento : R$ #00FF00"..value, player, 255, 255, 255, true ) local accName = getAccountName ( getPlayerAccount ( player ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Everyone" ) ) then end end end end end end setTimer(upLevel,60000,0) -- Comandos by Faik addCommandHandler ("setlevel", function (thePlayer, cmd, account, level) local theJogador = getPlayerFromName (account) if (not theJogador) or (not level) then return end if (isObjectInACLGroup ("user."..getAccountName (getPlayerAccount (thePlayer)), aclGetGroup ("Console"))) then setElementData (theJogador, "Level", tonumber(level)) exports.Scripts_Dxmessages:outputDx(thePlayer,'#1E90FF[LEVEL]#ffffffLevel setado com sucesso.',thePlayer,255,255,255,true) end end) addCommandHandler ("setxp", function (thePlayer, cmd, account, minutes) local theJogador = getPlayerFromName (account) if (not theJogador) or (not minutes) then return end if (isObjectInACLGroup ("user."..getAccountName (getPlayerAccount (thePlayer)), aclGetGroup ("Console"))) then setElementData (theJogador, "minutes", tonumber(minutes)) exports.Scripts_Dxmessages:outputDx(thePlayer,'#1E90FF[EXPERIENCIA]#ffffffNível de experiencia setado com sucesso.',thePlayer,255,255,255,true) end end) -- Fim Comandos by Faik function setLevelLogin () local account = getPlayerAccount(source) if ( account ) then local Level = (getAccountData(account,"Level") or 0) local minutes = (getAccountData(account,"minutes") or 0) setElementData(source,"Level",Level) setElementData(source,"minutes",minutes) end end addEventHandler("onPlayerLogin",getRootElement(),setLevelLogin) function setLevelJoin () setElementData(source,"Level",0) setElementData(source,"minutes",0) end addEventHandler("onPlayerJoin",getRootElement(),setLevelJoin) function setLevelQuit () local account = getPlayerAccount(source) if ( account ) then local minutes = (getElementData(source,"minutes") or 0) local Level = (getElementData(source,"Level") or 0) setAccountData(account,"minutes",minutes) setAccountData(account,"Level",Level) end end addEventHandler("onPlayerQuit",getRootElement(),setLevelQuit) Script HUD (Client) local screenW,screenH = guiGetScreenSize() local px,py = 1600,900 local x,y = (screenW/px), (screenH/py) local font1 = dxCreateFont("files/Gilroy-Light.ttf", 20) local font2 = dxCreateFont("files/Gilroy-Medium.ttf", 20) local font3 = dxCreateFont("files/Gilroy-Regular.ttf", 40) function enableCustomHUD() customHUDEnabled = not customHUDEnabled setPlayerHudComponentVisible("ammo", not customHUDEnabled) setPlayerHudComponentVisible("health", not customHUDEnabled) setPlayerHudComponentVisible("armour", not customHUDEnabled) setPlayerHudComponentVisible("breath", not customHUDEnabled) setPlayerHudComponentVisible("clock", not customHUDEnabled) setPlayerHudComponentVisible("money", not customHUDEnabled) setPlayerHudComponentVisible("weapon", not customHUDEnabled) setPlayerHudComponentVisible("vehicle_name", not customHUDEnabled) setPlayerHudComponentVisible("area_name", not customHUDEnabled) setPlayerHudComponentVisible("radio", not customHUDEnabled) setPlayerHudComponentVisible("wanted", not customHUDEnabled) --setPlayerHudComponentVisible("radar", not customHUDEnabled) end addCommandHandler("customhud", enableCustomHUD) enableCustomHUD() -------------------------------------------------- function dxHud() local name = getPlayerName (localPlayer) local money = string.gsub(getPlayerMoney(), "^(-?%d+),(%d%d%d)", "%1 %2") local money = string.gsub(money, "^(-?%d+)(%d%d%d)", "%1 %2") local money = string.gsub(money, "^(-?%d+)(%d%d%d)", "%1 %2") local level = getElementData(localPlayer, "player:level") or 1 local xp = getElementData(localPlayer, "player:xp") or 0 local time = getRealTime() local hours = time.hour local minutes = time.minute if minutes <= 9 then minutes = "0"..minutes end local dia = ("%02d"):format(time.monthday) local mes = ("%02d"):format(time.month+1) dxDrawText(name, x*1245, y*35, x*1670, y*25, tocolor(255, 255, 255, 255), 0.5, font2, "left", "center", false, false, true, true, false) dxDrawText(money.." $", x*1295, y*245, x*1670, y*25, tocolor(255, 255, 255, 255), 0.75, font1, "left", "center", false, false, true, true, false) dxDrawText("Nível: "..level, 1250*x, 77*y, 1670*x, 25*y, tocolor(255, 255, 255, 255), 0.4, font2, "left", "center", false, false, true, true, false) dxDrawText("EXP: "..math.floor(xp).."/"..(level*400), 1355*x, 77*y, 1670*x, 25*y, tocolor(255, 255, 255, 255), 0.4, font2, "left", "center", false, false, true, true, false) dxDrawText(hours..":"..minutes, x*1415, y*240, x*1670, y*25, tocolor(255,255,255, 255), 0.5, font3, "center", "center", false, false, true, true, false) dxDrawText(dia, x*1290, y*220, x*1670, y*25, tocolor(255, 255, 255, 255), 0.55, font1, "center", "center", false, false, true, true, false) dxDrawText(mes, x*1290, y*260, x*1670, y*25, tocolor(255, 255, 255, 255), 0.55, font1, "center", "center", false, false, true, true, false) Health = math.floor(getElementHealth(localPlayer)) armor = math.floor(getPedArmor(localPlayer)) dxDrawRectangle(1270*x, 70*y, 2.04*x*Health, (12/y)*y, tocolor(220,37,72,255), false) -- Здоровье dxDrawRectangle(1270*x, 93*y, 2.04*x*armor, (12/y)*y, tocolor(255,255,255,255), false) -- Голод dxDrawImage(1235*x, 15*y, 355*x, 140*y,"files/hud.png",0.0,0.0,0.0,tocolor(255,255,255,255), false) end function renderDxHud() addEventHandler("onClientRender", getRootElement(), dxHud) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), renderDxHud) function toggleHud() if isVisible then addEventHandler("onClientRender", root, dxHud) else removeEventHandler("onClientRender", root, dxHud) end isVisible = not isVisible end addCommandHandler("hud", toggleHud) local playerMoney = getPlayerMoney ( localPlayer ) local messages = { } addEventHandler ( "onClientRender", root, function ( ) local tick = getTickCount ( ) if ( playerMoney ~= getPlayerMoney ( localPlayer ) ) then local pM = getPlayerMoney ( localPlayer ) if ( pM > playerMoney ) then local diff = pM - playerMoney table.insert ( messages, { diff, true, tick + 2500, 180 } ) else local diff = playerMoney - pM table.insert ( messages, { diff, false, tick + 2500, 180 } ) end playerMoney = pM end if ( #messages > 7 ) then table.remove ( messages, 1 ) end for index, data in ipairs ( messages ) do local v1 = data[1] local v2 = data[2] local v3 = data[3] local v4 = data[4] if ( v2 ) then dxDrawText ( "+ "..convertNumber(v1).." $", 1275*x, 350*y -(index*25), 50*x, 20*y, tocolor(0, 255, 0, v4+75), 0.75, font1, "left", "center", false, false, true, true, false) else dxDrawText ( "- "..convertNumber(v1).." $", 1275*x, 350*y -(index*25), 50*x, 20*y, tocolor(255, 0, 0, v4+75), 0.75, font1, "left", "center", false, false, true, true, false) end if (tick >= v3) then messages[index][4] = v4-2 if (v4 <= 25) then table.remove (messages, index) end end end end ) function convertNumber(number) local formatted = number while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1 %2') if (k==0) then break end end return formatted end Link to comment
Moderators IIYAMA Posted May 15, 2021 Moderators Share Posted May 15, 2021 Server 6 hours ago, SRmasazuka said: setElementData(source,"Level",Level) Client 6 hours ago, SRmasazuka said: local level = getElementData(localPlayer, "player:level") or 1 The key (server) "Level" is not the same as (client) "player:level". So there is your mismatch. Link to comment
SRmasazuka Posted May 16, 2021 Author Share Posted May 16, 2021 On 15/05/2021 at 05:43, IIYAMA said: Server Client The key (server) "Level" is not the same as (client) "player:level". So there is your mismatch. I understood what I said but I haven't been able to make it work yet. I'm a beginner and some functions are tangled in my mind. 1 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