Jump to content

Mapshop ERROR help?


TheGuyNL

Recommended Posts

Hello,

So I am making this mapshop for my server. A friend send me his old mapshop but it comes up with an error:

ERROR: call: failed to call 'mapmanager:getGamemodeMap' [string "?"]

It actually spams the console with this error when you try to open the GUI.

Here is my server-side script:

  
mapCost = 5000   
  
-- Maps 
function getServerMaps (loadList) 
    local tableOut 
    if loadList then 
        tableOut = {} 
        -- local deletedMaps = {} 
        local gamemodes = {} 
        gamemodes = call(getResourceFromName("mapmanager"), "getGamemodes") 
        for id,gamemode in ipairs (gamemodes) do 
            tableOut[id] = {} 
            tableOut[id].name = getResourceInfo(gamemode, "name") or getResourceName(gamemode) 
            tableOut[id].resname = getResourceName(gamemode) 
            tableOut[id].maps = {} 
            local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode" , gamemode) 
            for _,map in ipairs (maps) do 
                table.insert(tableOut[id]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)}) 
            end 
            table.sort(tableOut[id]["maps"], sortCompareFunction) 
        end 
        table.sort((tableOut), sortCompareFunction) 
        table.insert(tableOut, {name = "no gamemode", resname = "no gamemode", maps = {}}) 
        local countGmodes = #tableOut 
        local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode") 
        for id,map in ipairs (maps) do 
            -- if fileOpen(":"..getResourceName(map).."/deleted") then 
                -- table.insert(deletedMaps ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)}) 
            -- else 
                table.insert(tableOut[countGmodes]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)}) 
            -- end 
        end 
        -- table.sort(deletedMaps, sortCompareFunction) 
        table.sort(tableOut[countGmodes]["maps"], sortCompareFunction) 
        -- table.insert(tableOut, {name = "deleted maps", resname = "deleted maps", maps = {}}) 
        -- local countGmodes = countGmodes + 1 
        -- tableOut[countGmodes]["maps"] = deletedMaps 
    end 
    local map = call(getResourceFromName("mapmanager"), "getRunningGamemodeMap") 
    local gamemode = call(getResourceFromName("mapmanager"), "getRunningGamemode") 
    gamemode = gamemode and getResourceName(gamemode) or "N/A" 
    map = map and getResourceName(map) or "N/A" 
    callClientFunction(loadList,"loadMaps", tableOut, gamemode, map) 
end 
  
function sortCompareFunction(s1, s2) 
    if type(s1) == "table" and type(s2) == "table" then 
        s1, s2 = s1.name, s2.name 
    end 
    s1, s2 = s1:lower(), s2:lower() 
    if s1 == s2 then 
        return false 
    end 
    local byte1, byte2 = string.byte(s1:sub(1,1)), string.byte(s2:sub(1,1)) 
    if not byte1 then 
        return true 
    elseif not byte2 then 
        return false 
    elseif byte1 < byte2 then 
        return true 
    elseif byte1 == byte2 then 
        return sortCompareFunction(s1:sub(2), s2:sub(2)) 
    else 
        return false 
    end 
end 
  
function callGetMaps() 
    for i,player in ipairs(getElementsByType("player")) do 
        callClientFunction(player,"getMaps") 
    end 
end 
addCommandHandler("rebuildMaps",callGetMaps) 
  
  
  
  
-- Buy as next map 
function buyMap(thePlayer,mapName) 
    local account = getPlayerAccount(player) 
    local playerCash = getAccountData(acount,"cash") 
    if mapIsAlreadySet == false then 
        if not (mapName == "") then 
            if playerCash >= mapCost then 
                triggerEvent("onExternalNextmapRequest",thePlayer,thePlayer,mapName) 
            else 
                outputChatBox("#FF6600* You don't have enough money to set a map!",thePlayer,255,255,255,true) 
            end 
        else 
            outputChatBox("#FF6600* Please select a map from the list first!",thePlayer,255,255,255,true) 
        end 
    else 
        outputChatBox("#FF6600* A map is already set at the moment! Please try again later.",thePlayer,255,255,255,true) 
    end 
else 
    outputChatBox("#FF6600* A map is already set at the moment! Please try again later.",thePlayer,255,255,255,true) 
end 
  
function resetMapSetStatus() 
    mapIsAlreadySet = false 
end 
addEventHandler("onMapStarting",getRootElement(),resetMapSetStatus) 
  
  
addEvent("onScriptSetNextMap",true) 
addEventHandler("onScriptSetNextMap",getRootElement(), 
function (mapName) 
    thePlayer = source 
    local playerCash = tonumber(loadPlayerData(thePlayer,"cash")) 
    savePlayerData(thePlayer,"cash",playerCash-mapCost) 
    outputChatBox("#FF6600Nextmap: #FFFFFF"..getPlayerName(thePlayer).."#FF6600 has bought a next map!",getRootElement(),255,255,255,true) 
    outputChatBox("#FF6600Nextmap: "..mapName,getRootElement(),255,255,255,true) 
    mapIsAlreadySet = true 
    scoreboardRefresh(thePlayer) 
    achievement31(thePlayer) 
end) 
  
addEvent("onRaceSetNextMap",true) 
addEventHandler("onRaceSetNextMap",getRootElement(), 
function () 
    mapIsAlreadySet = true 
end) 
  
  
  

Here is the client-side scipt:

    -- "Maps" TAB 
  
    gridMaps = guiCreateGridList(17,51,315,285,false,mapGui[1]) 
    guiGridListSetSortingEnabled(gridMaps,false) 
    guiGridListAddColumn(gridMaps,"Map name",0.9) 
  
    lblMapsInfo = guiCreateLabel(342,210,245,45,"Each map costs $5000, regardless whether it's DM or DD.",false,mapGui[1]) 
    guiLabelSetVerticalAlign(lblMapsInfo,"center") 
    guiLabelSetHorizontalAlign(lblMapsInfo,"center",true) 
    guiSetFont(lblMapsInfo,"default-bold-small") 
  
  
    lblTotalMapsOnServer = guiCreateLabel(342,28,193,19,"Total maps on the server: N/A",false,mapGui[1]) 
    guiSetFont(lblTotalMapsOnServer,"default-bold-small") 
  
    lblTotalDmMaps = guiCreateLabel(342,47,193,19,"Total DM maps: N/A",false,mapGui[1]) 
    guiSetFont(lblTotalDmMaps,"default-bold-small") 
  
    lblTotalDdMaps = guiCreateLabel(342,62,193,19,"Total DD maps: N/A",false,mapGui[1]) 
    guiSetFont(lblTotalDdMaps,"default-bold-small") 
  
    lblSetNextMapTitle = guiCreateLabel(342,189,245,16,"Set as next map",false,mapGui[1]) 
    guiLabelSetColor(lblSetNextMapTitle,255,120,0) 
    guiLabelSetVerticalAlign(lblSetNextMapTitle,"center") 
    guiLabelSetHorizontalAlign(lblSetNextMapTitle,"center",false) 
    guiSetFont(lblSetNextMapTitle,"default-bold-small") 
  
    lblSearchForMaps = guiCreateLabel(25,25,101,14,"Search for maps:",false,mapGui[1]) 
    guiLabelSetColor(lblSearchForMaps,255,120,0) 
    guiLabelSetVerticalAlign(lblSearchForMaps,"center") 
    guiSetFont(lblSearchForMaps,"default-bold-small") 
  
    lblSelectedMapNameTitle = guiCreateLabel(342,97,245,16,"Selected map name:",false,mapGui[1]) 
    guiLabelSetColor(lblSelectedMapNameTitle,150,255,150) 
    guiSetFont(lblSelectedMapNameTitle,"default-bold-small") 
  
    lblSelectedMapAuthorTitle = guiCreateLabel(342,136,245,16,"Map type:",false,mapGui[1]) 
    guiLabelSetColor(lblSelectedMapAuthorTitle,150,255,150) 
    guiSetFont(lblSelectedMapAuthorTitle,"default-bold-small") 
  
  
    lblSelectedMapName = guiCreateLabel(342,113,245,16,"N/A",false,mapGui[1]) 
  
    lblSelectedMapAuthor = guiCreateLabel(342,152,245,16,"N/A",false,mapGui[1]) 
  
  
    lblMapTabLine1 = guiCreateLabel(342,309,245,27,"---------------------------------------------------------------",false,mapGui[1]) 
    guiLabelSetColor(lblMapTabLine1,255,120,0) 
    guiLabelSetVerticalAlign(lblMapTabLine1,"center") 
    guiLabelSetHorizontalAlign(lblMapTabLine1,"center",false) 
    guiSetFont(lblMapTabLine1,"default-bold-small") 
  
    lblMapTabLine2 = guiCreateLabel(342,173,245,16,"---------------------------------------------------------------",false,mapGui[1]) 
    guiLabelSetColor(lblMapTabLine2,255,120,0) 
    guiLabelSetVerticalAlign(lblMapTabLine2,"center") 
    guiLabelSetHorizontalAlign(lblMapTabLine2,"center",false) 
    guiSetFont(lblMapTabLine2,"default-bold-small") 
  
    lblMapTabLine3 = guiCreateLabel(342,81,245,16,"---------------------------------------------------------------",false,tabs[1]) 
    guiLabelSetColor(lblMapTabLine3,255,120,0) 
    guiLabelSetVerticalAlign(lblMapTabLine3,"center") 
    guiLabelSetHorizontalAlign(lblMapTabLine3,"center",false) 
    guiSetFont(lblMapTabLine3,"default-bold-small") 
  
    editMapSearch = guiCreateEdit(129,23,198,21,"",false,tabs[1]) 
  
    btnBuyNextMap = guiCreateButton(380,265,169,44,"Buy as next map - $5000",false,tabs[1]) 
  
  
  
 function onresourceStart () 
  bindKey ("F1", "down", displayTab) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onresourceStart) 
  
function displayTab(openTab) 
    local visible = guiGetVisible(mapGui[1]) 
    if visible == false then 
        guiSetVisible(mapGui[1],true) 
    else 
        guiSetVisible(mapGui[1],false) 
    end 
end 
  
  
function getMaps() 
    totalServerMaps = 0 
    totalDmMaps = 0 
    totalDdMaps = 0 
    setTimer(callServerFunction,500,1,"getServerMaps",getLocalPlayer()) 
end 
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),getMaps) 
  
  
  
function loadMaps(gamemodeMapTable, gamemode, map) 
    guiGridListClear(gridMaps) 
    if gamemodeMapTable then 
        aGamemodeMapTable = gamemodeMapTable 
        for id,gamemode in pairs (gamemodeMapTable) do 
            if (gamemode.name == "Race") then 
                for id,map in ipairs (gamemode.maps) do 
                    local row = guiGridListAddRow ( gridMaps ) 
                    guiGridListSetItemText ( gridMaps, row, 1, map.name, false, false ) 
                    guiGridListSetItemData ( gridMaps, row, 1, map.resname) 
                    updateMapLabels(1) 
                end 
            end 
        end 
    end 
end 
  
  
-- Map search 
function mapSearch() 
    guiGridListClear(gridMaps) 
    local searchString = string.lower(guiGetText(editMapSearch)) 
    if ( searchString == "" ) then 
        for id,gamemode in pairs (aGamemodeMapTable) do 
            if (gamemode.name == "Race") then 
                for id,map in ipairs (gamemode.maps) do 
                    local row = guiGridListAddRow ( gridMaps ) 
                    guiGridListSetItemText ( gridMaps, row, 1, map.name, false, false ) 
                    guiGridListSetItemData ( gridMaps, row, 1, map.resname) 
                end 
            end 
        end 
    else 
        for id,gamemode in pairs (aGamemodeMapTable) do 
            if (gamemode.name == "Race") then 
                local noMapsFound = true 
                for id,map in ipairs (gamemode.maps) do 
                    if string.find(string.lower(map.name.." "..map.resname), searchString, 1, true) then 
                        local row = guiGridListAddRow ( gridMaps ) 
                        guiGridListSetItemText ( gridMaps, row, 1, map.name, false, false ) 
                        guiGridListSetItemData ( gridMaps, row, 1, map.resname) 
                        noMapsFound = false 
                    end 
                end 
                if noMapsFound == true then 
                    local row = guiGridListAddRow(gridMaps) 
                    guiGridListSetItemText (gridMaps, row, 1, "No maps matching your search query!", false, false) 
                    guiGridListSetItemColor (gridMaps, row, 1, 255,50,50) 
                end 
            end 
        end 
    end 
    updateMapLabels(2) 
end 
  
function buyNextMap() 
    local row,column = guiGridListGetSelectedItem(gridMaps) 
    local mapName = guiGridListGetItemText(gridMaps,row,1) 
    callServerFunction("buyMap",getLocalPlayer(),mapName) 
end 
  
  
-- Update labels 
function updateMapLabels(updateMode) 
    if updateMode == 1 then 
        guiSetText(lblTotalMapsOnServer,"Total maps on the server: "..totalServerMaps) 
        guiSetText(lblTotalDmMaps,"Total DM Maps:  "..totalDmMaps) 
        guiSetText(lblTotalDdMaps,"Total DD Maps:  "..totalDdMaps) 
    else 
        local row,column = guiGridListGetSelectedItem(gridMaps) 
        local mapName = guiGridListGetItemText(gridMaps,row,1) 
        if mapName == "" then 
            guiSetText(lblSelectedMapName,"N/A") 
            guiSetText(lblSelectedMapAuthor,"N/A") 
        else 
            guiSetText(lblSelectedMapName,mapName) 
            if string.find(mapName,"[DM]",1,true) then 
                guiSetText(lblSelectedMapAuthor,"Deathmatch") 
            elseif string.find(mapName,"[DD]",1,true) then 
                guiSetText(lblSelectedMapAuthor,"Destruction Derby") 
            elseif string.find(mapName,"[FUN]",1,true) then 
                guiSetText(lblSelectedMapAuthor,"Fun map") 
            else 
                guiSetText(lblSelectedMapAuthor,"UNKNOWN") 
            end 
        end 
    end 
end 
  

Thanks in advance for helping me!

Link to comment

In your code i not found this line

mapmanager:getGamemodeMap

Anyway in mapmanager not have this exported function.

You need use this

Returns the currently running gamemode's resource pointer.

resource getRunningGamemodeMap ( ) 

Link to comment

For your vote

  
tGamemodeMaps = getMapsCompatibleWithGamemode( getRunningGamemode ( ) )  
  

For change

function setGamemodeMap( sName )  
    if type( sName ) == 'string' then 
        local uResourceMap = getResourceFromName( sName ) 
        if uResourceMap then 
            changeGamemodeMap ( uResourceMap ) 
        end 
        return false 
    end 
    return false 
end 

https://wiki.multitheftauto.com/wiki/Mapmanager

Link to comment

Server

  
function getServerMaps(loadList) 
    local maps = {} 
    for i, res in ipairs(getResources()) do 
        if getResourceInfo(res, "type") == "map" then 
            table.insert(maps, { name = getResourceInfo(res, "name"), resname = getResourceName(res) }) 
        end 
    end 
    callClientFunction(loadList, "loadMaps", maps) 
end 

Client

  
function loadMaps(maps) 
    guiGridListClear(gridMaps) 
    aGamemodeMapTable = maps 
    for i, map in ipairs(maps) do 
        local row = guiGridListAddRow(gridMaps) 
        guiGridListSetItemText(gridMaps, row, 1, map.name, false, false) 
        guiGridListSetItemData(gridMaps, row, 1, map.resname) 
        updateMapLabels(1) 
    end 
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...