addEventHandler ( 'onGamemodeMapStart', root,
function ( uMapStart )
local mapname = getResourceName( uMapStart )
local xml = xmlLoadFile("data/ratings.xml")
if ( xml ) then
local index = findIndexByName ( mapname )
if ( index ) then
local map = xmlFindChild ( xml, "map", index )
local rating = xmlNodeGetAttribute ( map, "rating" )
local ratedBy = xmlNodeGetAttribute ( map, "ratedBy" )
local played = xmlNodeGetAttribute ( map, "played" )
outputChatBox ( "rated: ".. rating .." ratedBy: ".. ratedBy .." played ".. played, getRootElement(), 255, 0, 0, true )
else
outputChatBox ( "Map not found in our ratings list.", getRootElement(), 255, 0, 0, true )
end
else
outputChatBox ( "Unable to load map ratings XML file.", getRootElement(), 255, 0, 0, true )
end
end
)
function findIndexByName ( mapName )
local ratingsFile = xmlLoadFile("data/ratings.xml")
if ( ratingsFile ) then
for index, map in ipairs ( xmlNodeGetChildren ( ratingsFile ) ) do
local name = xmlNodeGetAttribute ( map, "id" )
if ( name == mapName ) then
return index -1
end
end
xmlUnloadFile(ratingsFile)
end
end
I tested it and it works.