Jump to content

xml


myyusuf

Recommended Posts

       local mapname = getResourceName(map) 

What is map?

idk why, btw he need name of folder.. so ok

server

local lastTimePlayed 
local month = {"January","February","March","April","May","June","Juli","August","September","October","November","December"} 
  
function timestampToDate(stamp) 
    local time = getRealTime(stamp) 
    return string.format("%d %s %02d:%02d",time.monthday,month[time.month+1],time.hour,time.minute) 
end 
  
addEvent("onMapStarting",true) 
addEventHandler ( 'onMapStarting', root, 
    function ( mapInfo ) 
        local resource = exports.mapmanager:getRunningGamemodeMap() 
        local mapname = getResourceInfo ( resource, "name" ) 
        local author = getResourceInfo(exports.mapmanager:getRunningGamemodeMap(),"author") 
        local lastTimePlayed = timestampToDate(mapInfo.lastTimePlayed) 
        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" ) 
                triggerClientEvent(source,"INFO",getRootElement(),mapname,author,rating,ratedBy,played,lastTimePlayed) 
            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 

client

local screenWidth, screenHeight = guiGetScreenSize() 
local endPosition = screenHeight-140 
local moveback = false 
  
function getDrawText(mapname,author,rating,ratedBy,played,lastTimePlayed) 
    addEventHandler ( "onClientRender", getRootElement(), drawMapInfo) 
    if mapname then 
        textM = "Map: "..mapname 
    else 
        textM = "Unknown" 
    end 
    if author then 
        textA = "Author: "..author 
    else 
        textA = "Unknown" 
    end 
    if rating then 
        textR = "Rate: " ..rating.. "/10 (by " ..ratedBy.. " players)" 
    else 
        textR = "Not rated yet" 
    end 
    if played then 
        textP = "Times played: "..played.." times" 
    else 
        textP = "Never played before" 
    end 
    if lastTimePlayed then 
        textPL = "Last Time Played\n"..lastTimePlayed 
    else 
        textPL = "Unknown" 
    end 
end 
addEvent( "INFO", true ) 
addEventHandler( "INFO", getRootElement(), getDrawText ) 
  
function drawMapInfo () 
    if position == endPosition then 
        if tickCount == 0 then 
            moveback = true 
        end 
        tickCount = tickCount-1 
        movePosition = 0 
    end 
    if position >= screenHeight+91 then 
        removeEventHandler("onClientRender",getRootElement(),drawMapInfo) 
    end 
    if moveback then 
        movePosition = -2.5 
        alpha = alpha - 10 
    end 
    alpha = alpha + 5 
    if alpha > 255 then 
        alpha = 255 
    elseif alpha < 0 then 
        alpha = 0 
    end 
    local heighResize = dxGetFontHeight(1.15, "default-bold") 
    local widthRezise1 = dxGetTextWidth("Map - "..name,1.15,"default-bold") 
    local widthRezise2 = dxGetTextWidth("Lasttime played - "..lastTimePlayed,1.15,"default-bold") 
    local widthRezise3 = dxGetTextWidth("By - "..author,1.15,"default-bold") 
    if widthRezise1 > widthRezise2 and widthRezise1 > widthRezise3 then 
        widthRezise = widthRezise1 
    elseif  widthRezise2 > widthRezise1 and widthRezise2 > widthRezise3 then 
        widthRezise = widthRezise2 
    elseif  widthRezise3 > widthRezise1 and widthRezise3 > widthRezise2 then 
        widthRezise = widthRezise3 
    end 
    dxDrawText ( textR,screenWidth/2-150,screenHeight/2+275,684.0,647.0,tocolor(255,255,255,255),1.5,"default-bold","left","top",false,false,false) 
    dxDrawText ( textP,screenWidth/2-150,screenHeight/2+250,636.0,675.0,tocolor(255,255,255,255),1.5,"default-bold","left","top",false,false,false)     
    dxDrawImage(screenWidth/2-200,screenHeight/2+185,420.0,176.0, "images/info_bgr.png",0,0,0,tocolor(200,200,200,alpha)) 
    dxDrawText ( textM,screenWidth/2-150,screenHeight/2+200,636.0,675.0,tocolor(255,255,255,255),1.5,"default-bold","left","top",false,false,false) 
    dxDrawText ( textA,screenWidth/2-150,screenHeight/2+225.0,636.0,619.0,tocolor(255,255,255,255),1.5,"default-bold","left","top",false,false,false) 
    dxDrawText ( textPL,screenWidth/2-150,screenHeight/2+300,684.0,647.0,tocolor(255,255,255,255),1.5,"default-bold","left","top",false,false,false) 
    dxDrawText ( "Mode: Destruction Derby",screenWidth/2-150,screenHeight/2+325,506.0,699.0,tocolor(255,255,255,255),1.5,"default-bold","left","top",false,false,false) 
    position = position - movePosition 
end 
  

Edited by Guest
Link to comment
       local mapname = getResourceName(map) 

What is map?

idk why, btw he need name of folder.. so ok

server

local lastTimePlayed 
local month = {"January","February","March","April","May","June","Juli","August","September","October","November","December"} 
  
function timestampToDate(stamp) 
    local time = getRealTime(stamp) 
    return string.format("%d %s %02d:%02d",time.monthday,month[time.month+1],time.hour,time.minute) 
end 
  
addEvent("onMapStarting",true) 
addEventHandler ( 'onMapStarting', root, 
    function ( mapInfo ) 
        local resource = exports.mapmanager:getRunningGamemodeMap() 
        local mapname = getResourceInfo ( resource, "name" ) 
        local author = getResourceInfo(exports.mapmanager:getRunningGamemodeMap(),"author") 
        local lastTimePlayed = timestampToDate(mapInfo.lastTimePlayed) 
        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" ) 
                triggerClientEvent(source,"INFO",getRootElement(),author,rating,ratedBy,played,lastTimePlayed) 
            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 

He can simply use

mapInfo.name 

-> started map name

Link to comment
of course.. but he don't know lua, and make all at random xD

or use part of admin panel for get name of folder

...

ON THIS CODE:

server:

local lastTimePlayed 
local month = {"January","February","March","April","May","June","Juli","August","September","October","November","December"} 
  
function timestampToDate(stamp) 
    local time = getRealTime(stamp) 
    return string.format("%d %s %02d:%02d",time.monthday,month[time.month+1],time.hour,time.minute) 
end 
  
addEvent("onMapStarting",true) 
addEventHandler ( 'onMapStarting', root, 
    function ( mapInfo ) 
        local resource = exports.mapmanager:getRunningGamemodeMap() 
        local mapname = getResourceInfo ( resource, "name" ) 
        local author = getResourceInfo(exports.mapmanager:getRunningGamemodeMap(),"author") 
        local lastTimePlayed = timestampToDate(mapInfo.lastTimePlayed) 
        local xml = xmlLoadFile("data/ratings.xml") 
        if ( xml ) then 
            local index = findIndexByName ( resource ) 
            if ( index ) then 
                local map = xmlFindChild ( xml, "map", index ) 
                local rating = xmlNodeGetAttribute ( map, "rating" ) 
                local ratedBy = xmlNodeGetAttribute ( map, "ratedBy" ) 
                local played = xmlNodeGetAttribute ( map, "played" ) 
                triggerClientEvent(source,"INFO",getRootElement(),mapname,author,rating,ratedBy,played,lastTimePlayed) 
            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 ( resource ) 
    local ratingsFile = xmlLoadFile("data/ratings.xml") 
    if ( ratingsFile ) then 
        for index, map in ipairs ( xmlNodeGetChildren ( ratingsFile ) ) do 
            local name = xmlNodeGetAttribute ( map, "id" ) 
            if ( name == resource ) then 
                return index -1 
            end 
        end 
        xmlUnloadFile(ratingsFile) 
    end 
end 

i want check resource name on here:

function findIndexByName ( resource ) 
    local ratingsFile = xmlLoadFile("data/ratings.xml") 
    if ( ratingsFile ) then 
        for index, map in ipairs ( xmlNodeGetChildren ( ratingsFile ) ) do 
            local name = xmlNodeGetAttribute ( map, "id" ) 
            if ( name == resource ) then 
                return index -1 
            end 
        end 
        xmlUnloadFile(ratingsFile) 
    end 
end 

your code checks the map name. idk why this code isnt running. its output "Map not found in our ratings list."

You do not understand what you're doing

Pls learn the LUA

viewtopic.php?f=148&t=40809

No one will be make completely for you the script

Link to comment

try:

local lastTimePlayed 
local month = {"January","February","March","April","May","June","Juli","August","September","October","November","December"} 
  
function timestampToDate(stamp) 
    local time = getRealTime(stamp) 
    return string.format("%d %s %02d:%02d",time.monthday,month[time.month+1],time.hour,time.minute) 
end 
  
addEvent("onMapStarting",true) 
addEventHandler ( 'onMapStarting', root,function ( mapInfo ) 
        local resource = exports.mapmanager:getRunningGamemodeMap() 
        local mapname = getResourceInfo ( resource, "name" ) 
        local author = getResourceInfo(exports.mapmanager:getRunningGamemodeMap(),"author") 
        local lastTimePlayed = timestampToDate(mapInfo.lastTimePlayed) 
        local xml = xmlLoadFile("data/ratings.xml") 
        if ( xml ) then 
            local index = findIndexByName ( resource ) 
            if ( index ) then 
                local map = xmlFindChild ( xml, "map", index ) 
                local rating = xmlNodeGetAttribute ( map, "rating" ) 
                local ratedBy = xmlNodeGetAttribute ( map, "ratedBy" ) 
                local played = xmlNodeGetAttribute ( map, "played" ) 
                triggerClientEvent(source,"INFO",root,mapname,author,rating,ratedBy,played,lastTimePlayed) 
            else 
                outputChatBox ( "Map not found in our ratings list.", root, 255, 0, 0) 
            end 
        else 
            outputChatBox ( "Unable to load map ratings XML file.", root, 255, 0, 0) 
        end 
end) 
  
function findIndexByName ( resource ) 
    local ratingsFile = xmlLoadFile("data/ratings.xml") 
    if ( ratingsFile ) then 
        for index, map in ipairs ( xmlNodeGetChildren ( ratingsFile ) ) do 
            local name = xmlNodeGetAttribute ( map, "id" ) 
            if ( name == resource ) then 
                return index -1 
            end 
        end 
        xmlUnloadFile(ratingsFile) 
    end 
end 

Link to comment
try:
local lastTimePlayed 
local month = {"January","February","March","April","May","June","Juli","August","September","October","November","December"} 
  
function timestampToDate(stamp) 
    local time = getRealTime(stamp) 
    return string.format("%d %s %02d:%02d",time.monthday,month[time.month+1],time.hour,time.minute) 
end 
  
addEvent("onMapStarting",true) 
addEventHandler ( 'onMapStarting', root,function ( mapInfo ) 
        local resource = exports.mapmanager:getRunningGamemodeMap() 
        local mapname = getResourceInfo ( resource, "name" ) 
        local author = getResourceInfo(exports.mapmanager:getRunningGamemodeMap(),"author") 
        local lastTimePlayed = timestampToDate(mapInfo.lastTimePlayed) 
        local xml = xmlLoadFile("data/ratings.xml") 
        if ( xml ) then 
            local index = findIndexByName ( resource ) 
            if ( index ) then 
                local map = xmlFindChild ( xml, "map", index ) 
                local rating = xmlNodeGetAttribute ( map, "rating" ) 
                local ratedBy = xmlNodeGetAttribute ( map, "ratedBy" ) 
                local played = xmlNodeGetAttribute ( map, "played" ) 
                triggerClientEvent(source,"INFO",root,mapname,author,rating,ratedBy,played,lastTimePlayed) 
            else 
                outputChatBox ( "Map not found in our ratings list.", root, 255, 0, 0) 
            end 
        else 
            outputChatBox ( "Unable to load map ratings XML file.", root, 255, 0, 0) 
        end 
end) 
  
function findIndexByName ( resource ) 
    local ratingsFile = xmlLoadFile("data/ratings.xml") 
    if ( ratingsFile ) then 
        for index, map in ipairs ( xmlNodeGetChildren ( ratingsFile ) ) do 
            local name = xmlNodeGetAttribute ( map, "id" ) 
            if ( name == resource ) then 
                return index -1 
            end 
        end 
        xmlUnloadFile(ratingsFile) 
    end 
end 

not working

getResourceName 

can you give me a example to use on mapInfo function?

addEvent("onMapStarting",true) 
addEventHandler ( 'onMapStarting', root, 
    function ( mapInfo ) 
        local resource = getResourceName ( mapInfo ) 
        local mapname = getResourceInfo(exports.mapmanager:getRunningGamemodeMap(),"name") 
        local author = getResourceInfo(exports.mapmanager:getRunningGamemodeMap(),"author") 
        local lastTimePlayed = timestampToDate(mapInfo.lastTimePlayed) 
        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" ) 
                triggerClientEvent(source,"INFO",getRootElement(),mapname,author,rating,ratedBy,played,lastTimePlayed) 
            else 
                outputChatBox ( "Map not found in our ratings list. " ..mapname, getRootElement(), 255, 0, 0, true ) 
            end 
        else 
            outputChatBox ( "Unable to load map ratings XML file.", getRootElement(), 255, 0, 0, true ) 
        end 
    end 
) 

is that right?

mapInfo isn't a function.

mapInfo is a table.

And your code is wrong, you're trying to get table resource name. You should use mapInfo.name to get map name.

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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