Jump to content

Buy map bug D:


novo

Recommended Posts

Hi all.

I made a shop for buy map, but it's not working.

EDIT: There is an error: Bad argument "#1" to "ipairs" (table expected, got bolean)

Here is my code:

Client-Side:

  
-------------------------- MAP SHOP --------------------------------- 
  
mapTab = guiCreateTab("Maps",GUIEditor_TabPanel[1]) 
mapList = guiCreateGridList(4,5,554,166,false,mapTab) 
guiGridListSetSelectionMode(mapList,2) 
buyMap = guiCreateButton(4,173,187,41,"Buy map",false,mapTab) 
rateMap = guiCreateButton(196,173,121,41,"Rate this map",false,mapTab) 
rateValue = guiCreateEdit(318,172,51,42,"",false,mapTab) 
reportMap = guiCreateButton(371,172,186,42,"Report this map",false,mapTab) 
authorMapColumn = guiGridListAddColumn( mapList, "Author", 0.2 ) 
mapMapColumn = guiGridListAddColumn( mapList, "Name", 0.5 ) 
guiGridListSetSortingEnabled ( mapMapColumn, false ) 
guiGridListAutoSizeColumn( list_avatar, authorMapColumn) 
  
triggerServerEvent('getMaps', getRootElement()) 
addEvent('sendMaps', true) 
addEventHandler('sendMaps', getRootElement(), 
    function(name, author) 
        local row = guiGridListAddRow(mapList) 
        guiGridListSetItemText(mapList, row, 1, name, false, false) 
        guiGridListSetItemText ( mapList, row, authorMapColumn, author, false, false ) 
        guiGridListSetItemText ( mapList, row, mapMapColumn, name, false, false ) 
         
         
    end 
) 
  
addEventHandler('onClientGUIClick', buyMap, 
    function() 
            local row, mapMapColumn = guiGridListGetSelectedItem(mapList) 
            local map = guiGridListGetItemText(mapList, row, mapMapColumn) 
            triggerServerEvent("buyMapFromPanel", getLocalPlayer(), map) 
    end 
, false) 
  

Server-side:

  
-------------- MAP -------------------- 
  
function mapsList() 
    local resourceTable = getResources() 
    for resourceKey, resourceValue in ipairs(resourceTable) do 
        local name = getResourceInfo(resourceValue, 'name') 
        local type = getResourceInfo(resourceValue, 'type') 
        local game = getResourceInfo(resourceValue, 'gamemodes') 
        local author = getResourceInfo(resourceValue, 'author') 
        if type == 'map' and game == 'race' then 
            triggerClientEvent('sendMaps', getRootElement(), name, author) 
        else 
            cancelEvent() 
        end 
    end 
end 
addEvent('getMaps', true) 
addEventHandler('getMaps', getRootElement(), mapsList) 
  
  
addEvent('buyMapFromPanel', true) 
function buyMFP(mapname) 
    if g_ForcedNextMap then 
        outputChatBox('#575757[shop]#c8c8c8Next map is '..getMapName(g_ForcedNextMap),source,255,255,0, true) 
        return 
    end 
    local query = #{mapname}>0 and table.concat({mapname},' ') or nil 
    if not query then 
        if g_ForcedNextMap then 
            outputChatBox('#575757[shop]#c8c8c8Next map is '..getMapName(g_ForcedNextMap),source,255,255,0, true) 
        else 
            outputChatBox('#575757[shop]#c8c8c8Next map is not set',source,255,255,0, true) 
        end 
        return 
    end 
    local map, errormsg = findMap(query) 
    if not map then 
        outputChatBox(errormsg, source) 
        return 
    end 
    if lastmap_B == map then 
        outputChatBox('#575757[shop]#c8c8c8That map has been palyed too much recently !',source,255,255,0, true) 
    else 
        g_ForcedNextMap = map 
        local nameAh = getPlayerName(source) 
        local nameAhB = string.gsub(nameAh, "#%x%x%x%x%x%x", "") 
        outputChatBox('#575757[shop]#c8c8c8'..nameAhB..' bought map '..getMapName(g_ForcedNextMap)..' for $3500.',getRootElement(),255,255,0, true) 
        givePlayerMoney(source, -3500) 
        setElementData(source, 'Money', getPlayerMoney(source)) 
        lastmap_B = g_ForcedNextMap 
    end 
end 
addEventHandler('buyMapFromPanel', getRootElement(), buyMFP) 
  
  

Please help <3 Thanks.

Link to comment

-- client side:

-------------------------- MAP SHOP --------------------------------- 
  
mapTab = guiCreateTab("Maps",GUIEditor_TabPanel[1]) 
mapList = guiCreateGridList(4,5,554,166,false,mapTab) 
guiGridListSetSelectionMode(mapList,2) 
buyMap = guiCreateButton(4,173,187,41,"Buy map",false,mapTab) 
rateMap = guiCreateButton(196,173,121,41,"Rate this map",false,mapTab) 
rateValue = guiCreateEdit(318,172,51,42,"",false,mapTab) 
reportMap = guiCreateButton(371,172,186,42,"Report this map",false,mapTab) 
authorMapColumn = guiGridListAddColumn( mapList, "Author", 0.2 ) 
mapMapColumn = guiGridListAddColumn( mapList, "Name", 0.5 ) 
guiGridListSetSortingEnabled ( mapMapColumn, false ) 
guiGridListAutoSizeColumn( list_avatar, authorMapColumn) 
  
triggerServerEvent('getMaps', localPlayer) 
  
addEvent('sendMaps', true) 
addEventHandler('sendMaps', getRootElement(), 
    function(maps) 
        for index, map in ipairs(maps) do 
            local row = guiGridListAddRow(mapList) 
            guiGridListSetItemText(mapList, row, 1, name, false, false) 
            guiGridListSetItemText ( mapList, row, authorMapColumn, map.author, false, false ) 
            guiGridListSetItemText ( mapList, row, mapMapColumn, map.name, false, false ) 
        end 
    end 
) 
  
addEventHandler('onClientGUIClick', buyMap, 
    function() 
        local row, mapMapColumn = guiGridListGetSelectedItem(mapList) 
        local map = guiGridListGetItemText(mapList, row, mapMapColumn) 
        triggerServerEvent("buyMapFromPanel", getLocalPlayer(), map) 
    end 
,false) 

-- server side:

function mapsList() 
    local tempTable = {} 
    for resourceKey, resourceValue in ipairs(getResources()) do 
        local name = getResourceInfo(resourceValue, 'name') 
        local type = getResourceInfo(resourceValue, 'type') 
        local game = getResourceInfo(resourceValue, 'gamemodes') 
        local author = getResourceInfo(resourceValue, 'author') 
        if (type == 'map' and game == 'race') then 
            table.insert(tempTable, {author=author, name=name}) 
        end 
    end 
    triggerClientEvent(source, 'sendMaps', source, tempTable) 
end 
addEvent('getMaps', true) 
addEventHandler('getMaps', getRootElement(), mapsList) 
  
function buyMFP(mapname) 
    if g_ForcedNextMap then 
        outputChatBox('#575757[shop]#c8c8c8Next map is '..getMapName(g_ForcedNextMap),source,255,255,0, true) 
        return 
    end 
    local query = #{mapname}>0 and table.concat({mapname},' ') or nil 
    if not query then 
        if g_ForcedNextMap then 
            outputChatBox('#575757[shop]#c8c8c8Next map is '..getMapName(g_ForcedNextMap),source,255,255,0, true) 
        else 
            outputChatBox('#575757[shop]#c8c8c8Next map is not set',source,255,255,0, true) 
        end 
        return 
    end 
    local map, errormsg = findMap(query) 
    if not map then 
        outputChatBox(errormsg, source) 
        return 
    end 
    if lastmap_B == map then 
        outputChatBox('#575757[shop]#c8c8c8That map has been palyed too much recently !',source,255,255,0, true) 
    else 
        g_ForcedNextMap = map 
        local nameAh = getPlayerName(source) 
        local nameAhB = string.gsub(nameAh, "#%x%x%x%x%x%x", "") 
        outputChatBox('#575757[shop]#c8c8c8'..nameAhB..' bought map '..getMapName(g_ForcedNextMap)..' for $3500.',getRootElement(),255,255,0, true) 
        givePlayerMoney(source, -3500) 
        setElementData(source, 'Money', getPlayerMoney(source)) 
        lastmap_B = g_ForcedNextMap 
    end 
end 
addEvent('buyMapFromPanel', true) 
addEventHandler('buyMapFromPanel', getRootElement(), buyMFP) 

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