koragg Posted September 27, 2016 Posted September 27, 2016 Hello, I'm trying to add average map rating into a dxdraw window but I have trouble doing so. If anybody can help, would be great. Here's the code: Client drawNextText = '' _nextWidth = 0 _nextHeight = 0 local g__sW, g__sH = guiGetScreenSize() local sx, sy = g__sW/1440, g__sH/900 local visible = true function getinfo(name, oldvalue) if source == getResourceRootElement() and name == 'gamemode.nextmap' then local what = getElementData(getResourceRootElement(), 'gamemode.nextmap') drawNextText = what _nextWidth = dxGetTextWidth(what, 0.45, 'bankgothic') _nextHeight = dxGetFontHeight(0.45, 'bankgothic') * 3 end end addEventHandler('onClientElementDataChange', root, getinfo) function drawinfo() if _nextWidth == 0 then return end if visible then dxDrawRectangle((g__sW-95)-(_nextWidth+20), 12*sy, _nextWidth+20, _nextHeight+10, tocolor(0,0,0,100),false) dxDrawText(drawNextText, (g__sW-95)-(_nextWidth+20)+5, 12*sy, (g__sW-100)-(_nextWidth+20)+_nextWidth+15, 5+_nextHeight+17, tocolor(254, 254, 34, 255), 0.45, 'bankgothic', 'center', 'center', true) end end addEventHandler("onClientRender",root, drawinfo) function shownextmap() visible = true end function hidenextmap() if visible then visible = false end end Server addEvent('onNextmapSettingChange', true) function nmap(nmap) local mapName = getResourceInfo(nmap, "name") or getResourceName(nmap) local rating = exports.mapratings:getMapRating(mapName) if rating then local average = tonumber(rating.average) or "0" end local stringSet = "Next map: "..mapName.." ("..tostring(average).."/10)" nextmap = stringSet map = exports.mapmanager:getRunningGamemodeMap() if map then local mapName = getResourceInfo(map, "name") or getResourceName(map) local rating = exports.mapratings:getMapRating(mapName) if rating then local average = tonumber(rating.average) or "0" end stringSet = "Current map: ".. mapName.." ("..tostring(average).."/10)\n"..stringSet end setElementData(resourceRoot, 'gamemode.nextmap', stringSet) end addEventHandler('onNextmapSettingChange', root, nmap) And here's a screenshot showing what I want to achieve As you see, the "Next Map" window at top right shows "(nil/10) as map rating. I can't get it to show the actual average rating of the maps there (or if map has no rating yet, to show 0/10). I love rock/metal/pop but don't mind any other music genre except чалга...that thing sux I also love cars PS I'm friendly
koragg Posted September 28, 2016 Author Posted September 28, 2016 I put outputChatBoxes after each line and problem appears to be in lines: 5,6,14,15. I love rock/metal/pop but don't mind any other music genre except чалга...that thing sux I also love cars PS I'm friendly
koragg Posted September 28, 2016 Author Posted September 28, 2016 (edited) FIXED Thanks to @dugasz1 @xiti and @lukum! Working code below if anyone's interested. Client drawNextText = '' _nextWidth = 0 _nextHeight = 0 local g__sW, g__sH = guiGetScreenSize() local sx, sy = g__sW/1440, g__sH/900 local visible = true function getinfo(name, oldvalue) if source == getResourceRootElement() and name == 'gamemode.nextmap' then local what = getElementData(getResourceRootElement(), 'gamemode.nextmap') drawNextText = what _nextWidth = dxGetTextWidth(what, 0.45, 'bankgothic') _nextHeight = dxGetFontHeight(0.45, 'bankgothic') * 3 end end addEventHandler('onClientElementDataChange', root, getinfo) function drawinfo() if _nextWidth == 0 then return end if visible then dxDrawRectangle((g__sW-95)-(_nextWidth+20), 12*sy, _nextWidth+20, _nextHeight+10, tocolor(0,0,0,100),false) dxDrawText(drawNextText, (g__sW-95)-(_nextWidth+20)+5, 12*sy, (g__sW-100)-(_nextWidth+20)+_nextWidth+15, 5+_nextHeight+17, tocolor(254, 254, 34, 255), 0.45, 'bankgothic', 'center', 'center', true) end end addEventHandler("onClientRender",root, drawinfo) function shownextmap() visible = true end function hidenextmap() if visible then visible = false end end Server addEvent('onNextmapSettingChange', true) function nmap(nmap) local mapName = getResourceInfo(nmap, "name") or getResourceName(nmap) local rating = exports.mapratings:getMapRating(getResourceName(nmap)) local average = 0 if rating then average = tonumber(rating.average) or "0" end local stringSet = "Next map: "..mapName.." ("..tostring(average).."/10)" nextmap = stringSet map = exports.mapmanager:getRunningGamemodeMap() if map then local mapName = getResourceInfo(map, "name") or getResourceName(map) local rating = exports.mapratings:getMapRating(getResourceName(map)) local average = 0 if rating then average = tonumber(rating.average) or "0" end stringSet = "Current map: ".. mapName.." ("..tostring(average).."/10)\n"..stringSet end setElementData(resourceRoot, 'gamemode.nextmap', stringSet) end addEventHandler('onNextmapSettingChange', root, nmap) function safeString(s) s = string.gsub(s, '&', '&') s = string.gsub(s, '"', '"') s = string.gsub(s, '<', '<') s = string.gsub(s, '>', '>') return s:gsub( "(['])", "''" ) end meta.xml <meta> <info name="Current/Next Map Info" description="Map Names Info" author="SDK/BinSlayer" type="script" version="1.0"/> <script src="server.lua" type="server"/> <script src="client.lua" type="client"/> <export function="shownextmap" type="client"/> <export function="hidenextmap" type="client"/> </meta> PS Not sure if it can work on default race.zip but won't hurt to try. Lock the topic, problem fixed. Edited September 28, 2016 by koragg I love rock/metal/pop but don't mind any other music genre except чалга...that thing sux I also love cars PS I'm friendly
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