GanJaRuleZ Posted January 3, 2012 Share Posted January 3, 2012 (edited) Hai all , this is the last script-problem that i have for now local root = getRootElement() addEventHandler('onGamemodeMapStart', root, function( theMapStarts) local mapName = getMapName local theMapRate = call(getResourceFromName("mapratings"), "getMapRating", mapName) outputChatBox ("#CC0000*This map has a rate of ".. theMapRate .."!", 255,255,255, true) end ) ERROR: unzipped\mapratingsonmapstart\maprate.lua:6: attempt to concatenate local 'theMapRate' ( a boolean value ) Edited January 3, 2012 by Guest Link to comment
GTX Posted January 3, 2012 Share Posted January 3, 2012 Try this local root = getRootElement() addEventHandler('onGamemodeMapStart', root, function( theMapStarts) local mapName = getMapName theMapRate = call(getResourceFromName("mapratings"), "getMapRating", mapName) outputChatBox ("#CC0000*This map has a rate of ".. theMapRate .."!", 255,255,255, true) end ) Link to comment
GanJaRuleZ Posted January 3, 2012 Author Share Posted January 3, 2012 The same error... Link to comment
Kenix Posted January 3, 2012 Share Posted January 3, 2012 (edited) Try: addEventHandler('onGamemodeMapStart', root, function( theMapStarts) local mapName = getMapName( ) if mapName then theMapRate = call( getResourceFromName("mapratings"), "getMapRating", mapName ) outputChatBox ( "#CC0000*This map has a rate of ".. theMapRate .."!", 255,255,255, true ) else outputChatBox( "can't get map name" ) end end ) Edited January 3, 2012 by Guest Link to comment
GanJaRuleZ Posted January 3, 2012 Author Share Posted January 3, 2012 The same error ... Link to comment
GanJaRuleZ Posted January 3, 2012 Author Share Posted January 3, 2012 Nope , the map starts , it outputs the following : It has average rating nil/10 (by 1 players) So in the debuscript 3 it gives that error .. Link to comment
Castillo Posted January 3, 2012 Share Posted January 3, 2012 addEventHandler('onGamemodeMapStart', root, function( theMapStarts ) setTimer(function () local mapName = getMapName( ) if (mapName and mapName ~= "None") then local theMapRate = exports["mapratings"]:getMapRating( mapName ) outputChatBox ( "#CC0000*This map has a rate of ".. tostring(theMapRate.average) .."!", getRootElement(), 255,255,255, true ) -- The value returned by getMapRatings is a TABLE. else outputChatBox( "can't get map name" ) end end, 1000, 1) end ) Link to comment
GanJaRuleZ Posted January 3, 2012 Author Share Posted January 3, 2012 No errors but it doesn't output the rate it output this line : It has average rating nil/10 (by 1 players) Link to comment
Castillo Posted January 3, 2012 Share Posted January 3, 2012 For me it said this: "*This map has a rate of 8!" That's the rate I set manually to the map in the sqlite table. P.S: I think to get the amount of players who rated it you must use: theMapRate.count Link to comment
BinSlayer1 Posted January 3, 2012 Share Posted January 3, 2012 No errors but it doesn't output the rate it output this line : It has average rating nil/10 (by 1 players) It's nil because there's no set rate for it yet (you havent rated the map yet) you must add an extra IF to check if .average returned something different than nil Edit: You must also make sure getMapRating is exported in 'mapratings' Link to comment
GanJaRuleZ Posted January 4, 2012 Author Share Posted January 4, 2012 Ok i made it working , but now , does anybody know the #FFFFFF ( HEX DECIMALS ) color codes from maprating resource ? Thank you.. Link to comment
Castillo Posted January 4, 2012 Share Posted January 4, 2012 Which color? it uses like two HEX colors, this is the most used I think: #E1AA5A Link to comment
GanJaRuleZ Posted January 4, 2012 Author Share Posted January 4, 2012 I mean each number has one HEX . Try /rate 2 , will give some sort of red and if you write /rate 10 , it will give green , so these i need these colors.. Link to comment
Castillo Posted January 4, 2012 Share Posted January 4, 2012 The script has these functions: function getRatingColor(rating) local r, g = -5.1*(rating^2) + 25.5*rating + 255, -5.1*(rating^2) + 76.5*rating r, g = r > 255 and 255 or math.floor(r+0.5), g > 255 and 255 or math.floor(g+0.5) -- outputDebugString("mapratings: rating = "..rating.." r = "..r.." g = "..g) return {r,g,0}--"#"..string.format("%02X", r)..string.format("%02X", g).."00" end function getRatingColorAsHex(rating) local r, g = unpack(getRatingColor(rating)) return "#"..string.format("%02X", r)..string.format("%02X", g).."00" end And they're used like this: outputChatBox("Rated '"..(getResourceInfo(getResourceFromName(mapresname), "name") or mapresname).."' "..getRatingColorAsHex(rating)..rating.."/10#E1AA5A.", player, 225, 170, 90, true) I think that's what you want . Link to comment
GanJaRuleZ Posted January 4, 2012 Author Share Posted January 4, 2012 Well , i started the script from 0 , and i made it working , but i don't know how to set these colors , can anybody help me? addEvent("onMapStarting",true) addEventHandler("onMapStarting",getRootElement(), function (mapInfo) local map = exports.mapmanager:getRunningGamemodeMap() local mapname = getResourceName(map) rate = exports.mapratings:getMapRating(mapname) if rate then local average = rate.average local players = rate.count setTimer(outputChatBox,50,1,"#FFE303[RATE]This map has average rating of "..tostring(average).."/10 (by "..tostring(players).." players)",getRootElement(),255,255,255,true) else setTimer(outputChatBox,50,1,"#FFE303[RATE]This map isn't rated yet.",getRootElement(),255,255,255,true) end end ) P.S : Thanks Solidsnake , but i don't know how to make it... Link to comment
Castillo Posted January 4, 2012 Share Posted January 4, 2012 Try with this: addEvent("onMapStarting",true) addEventHandler("onMapStarting",getRootElement(), function (mapInfo) local map = exports.mapmanager:getRunningGamemodeMap() local mapname = getResourceName(map) local rate = exports.mapratings:getMapRating(mapname) if rate then local average = rate.average local players = rate.count setTimer(outputChatBox,50,1,"#FFE303[RATE]This map has average rating of "..getRatingColorAsHex(average)..tostring(average).."/10 (by "..tostring(players).." players)",getRootElement(),255,255,255,true) else setTimer(outputChatBox,50,1,"#FFE303[RATE]This map isn't rated yet.",getRootElement(),255,255,255,true) end end ) function getRatingColor(rating) local r, g = -5.1*(rating^2) + 25.5*rating + 255, -5.1*(rating^2) + 76.5*rating r, g = r > 255 and 255 or math.floor(r+0.5), g > 255 and 255 or math.floor(g+0.5) return {r,g,0}--"#"..string.format("%02X", r)..string.format("%02X", g).."00" end function getRatingColorAsHex(rating) local r, g = unpack(getRatingColor(rating)) return "#"..string.format("%02X", r)..string.format("%02X", g).."00" end 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