Jump to content

Map Ratings


GanJaRuleZ

Recommended Posts

Posted (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 by Guest

My Projects!

No one.

Posted

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 
) 
  
  

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted (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 by Guest

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

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 ..

My Projects!

No one.

Posted
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 
) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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'

Posted

Which color? it uses like two HEX colors, this is the most used I think: #E1AA5A

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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..

My Projects!

No one.

Posted

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 ;).

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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...

My Projects!

No one.

Posted

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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You're welcome ;).

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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...