Lachuks Posted October 28, 2017 Share Posted October 28, 2017 (edited) Hello there! Recently I made level system for my server and I wanted to add more features to it but I don't know how to make it done. I wanted to make notification when level up. I made code but when I level up it shows only for ~0.5 seconds. I wanted to make it show for ~5 seconds. I don't understand how timers work that's why it's hard for me. Hope you can help me and maybe explain how does it works. Server: addEventHandler("onElementDataChange", getRootElement(), function (dataName) if (getElementType(source) == "player") and (dataName == "experience") then local theAccount = getPlayerAccount(source) if (theAccount) and not (isGuestAccount(theAccount)) then local level = getElementData(source, "level") local experience = getElementData(source, "experience") local experience_r = getElementData(source, "experience_r") if (experience >= experience_r) then local newLvl = level+1 local experience_rnl = exprequired[newLvl] if (experience_rnl) then local amountbonus = experience-experience_r setElementData(source, "level", newLvl) setElementData(source, "experience", 0) setElementData(source, "experience_r", experience_rnl) triggerClientEvent(source, "onClientLevelUp",source) else setElementData(source, "experience", experience_r) end end setAccountData(theAccount, "level", getElementData(source, "level")) setAccountData(theAccount, "experience", getElementData(source, "experience")) end end end) Client: function newLvl() newLvl = true if newLvl == true then dxDrawRectangle(screenW * 0.4083, screenH * 0.9037, screenW * 0.1839, screenH * 0.0528, tocolor(0, 0, 0, 160), false) dxDrawImage(screenW * 0.4094, screenH * 0.9046, screenW * 0.0271, screenH * 0.0491, ":DayZ/tools/images/flags/join.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) dxDrawText("Congradulations! You have reached "..getElementData(getLocalPlayer(),"level").." Level!", screenW * 0.4385, screenH * 0.9046, screenW * 0.5901, screenH * 0.9537, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) setTimer(function() newLvl = false end,5000,1) end end addEvent( "onClientLevelUp", true ) addEventHandler( "onClientLevelUp", localPlayer, newLvl) Edited October 28, 2017 by Emix Link to comment
Dimos7 Posted October 28, 2017 Share Posted October 28, 2017 You need the event onClientRender for that Link to comment
Lachuks Posted October 28, 2017 Author Share Posted October 28, 2017 5 hours ago, Dimos7 said: You need the event onClientRender for that I have added that event before. Same effect. Any help? Link to comment
Moderators IIYAMA Posted October 28, 2017 Moderators Share Posted October 28, 2017 A little bit dirty, but this might work: local newLvl = false function newLvl() newLvl = true end addEvent( "onClientLevelUp", true ) addEventHandler( "onClientLevelUp", localPlayer, newLvl) addEventHandler("onClientRender", root, function () if newLvl == true then dxDrawRectangle(screenW * 0.4083, screenH * 0.9037, screenW * 0.1839, screenH * 0.0528, tocolor(0, 0, 0, 160), false) dxDrawImage(screenW * 0.4094, screenH * 0.9046, screenW * 0.0271, screenH * 0.0491, ":DayZ/tools/images/flags/join.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) dxDrawText("Congradulations! You have reached "..getElementData(getLocalPlayer(),"level").." Level!", screenW * 0.4385, screenH * 0.9046, screenW * 0.5901, screenH * 0.9537, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) setTimer(function() newLvl = false end,5000,1) end end) 1 1 Link to comment
Lachuks Posted October 28, 2017 Author Share Posted October 28, 2017 36 minutes ago, IIYAMA said: A little bit dirty, but this might work: local newLvl = false function newLvl() newLvl = true end addEvent( "onClientLevelUp", true ) addEventHandler( "onClientLevelUp", localPlayer, newLvl) addEventHandler("onClientRender", root, function () if newLvl == true then dxDrawRectangle(screenW * 0.4083, screenH * 0.9037, screenW * 0.1839, screenH * 0.0528, tocolor(0, 0, 0, 160), false) dxDrawImage(screenW * 0.4094, screenH * 0.9046, screenW * 0.0271, screenH * 0.0491, ":DayZ/tools/images/flags/join.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) dxDrawText("Congradulations! You have reached "..getElementData(getLocalPlayer(),"level").." Level!", screenW * 0.4385, screenH * 0.9046, screenW * 0.5901, screenH * 0.9537, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) setTimer(function() newLvl = false end,5000,1) end end) Works great. Thank you! Lol. Allways when problem is solved it looks so easy. Link to comment
Moderators Popular Post IIYAMA Posted October 28, 2017 Moderators Popular Post Share Posted October 28, 2017 (edited) OH lol, waaaaaahhh!! This is NO good, hell no. =/ local newLvl = false function newLvlFunction() if not newLvl then setTimer(function() newLvl = false end,5000,1) end newLvl = true end addEvent( "onClientLevelUp", true ) addEventHandler( "onClientLevelUp", localPlayer, newLvlFunction) addEventHandler("onClientRender", root, function () if newLvl == true then dxDrawRectangle(screenW * 0.4083, screenH * 0.9037, screenW * 0.1839, screenH * 0.0528, tocolor(0, 0, 0, 160), false) dxDrawImage(screenW * 0.4094, screenH * 0.9046, screenW * 0.0271, screenH * 0.0491, ":DayZ/tools/images/flags/join.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) dxDrawText("Congradulations! You have reached "..getElementData(getLocalPlayer(),"level").." Level!", screenW * 0.4385, screenH * 0.9046, screenW * 0.5901, screenH * 0.9537, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) end end) @Emix Edited October 28, 2017 by IIYAMA 1 1 2 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