Jump to content

Map Ratings


GanJaRuleZ

Recommended Posts

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 by Guest
Link to comment

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

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 by Guest
Link to comment
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
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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...