Jump to content

[Help] Buy map


explOdeR

Recommended Posts

Well i made a Buy map , The client its work 100 % but i cant buy the map i see the list. here is the code:

u can help ? please

--Server Side :

  
-- Server Side 
-- 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 a next map 
function buyMap(thePlayer,mapName) 
    --local playerLevel = tonumber(loadPlayerData(thePlayer,"level")) 
    local playerCash = tonumber(loadPlayerData(thePlayer,"cash")) 
    if mapIsAlreadySet == false then 
        if not (mapName == "") then 
            --if playerLevel >= mapLevel then 
                if playerCash >= mapCost then 
                    triggerEvent("onExternalNextmapRequest",thePlayer,thePlayer,mapName) 
                else 
                    outputChatBox("#FF6600* #FFFFFFYou don't have enough money to set a map!",thePlayer,255,255,255,true) 
                end 
            --else 
                --outputChatBox("#FF6600* #FFFFFFYou need to be level #ABCDEF"..mapLevel.." #FFFFFFor higher to set maps!",thePlayer,255,255,255,true) 
            --end 
        else 
            outputChatBox("#FF6600* #FFFFFFPlease select a map from the list first!",thePlayer,255,255,255,true) 
        end 
    else 
        outputChatBox("#FF6600* #FFFFFFA map is already set at the moment! Please try again later.",thePlayer,255,255,255,true) 
    end 
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("#FFFFFFNextmap: "..getPlayerName(thePlayer).."#FFFFFF has bought a next map!",getRootElement(),255,255,255,true) 
    outputChatBox("#FFFFFFNextmap: #FF8800"..mapName,getRootElement(),255,255,255,true) 
    mapIsAlreadySet = true 
    scoreboardRefresh(thePlayer) 
    achievement31(thePlayer) 
end) 
  
addEvent("onRaceSetNextMap",true) 
addEventHandler("onRaceSetNextMap",getRootElement(), 
function () 
    mapIsAlreadySet = true 
end) 

Edited by Guest
Link to comment

XXS user panel buy nextrime :)

function buyMap(thePlayer,mapName) 
    --local playerLevel = tonumber(loadPlayerData(thePlayer,"level")) 
    local playerCash = tonumber(loadPlayerData(thePlayer,"cash")) 
    if mapIsAlreadySet == false then 
        if not (mapName == "") then 
            --if playerLevel >= mapLevel then 
                if playerCash >= mapCost then 
                    executeCommandHandler("nextmap", thePlayer, mapName) 
                else 
                    outputChatBox("#FF6600* #FFFFFFYou don't have enough money to set a map!",thePlayer,255,255,255,true) 
                end 
            --else 
                --outputChatBox("#FF6600* #FFFFFFYou need to be level #ABCDEF"..mapLevel.." #FFFFFFor higher to set maps!",thePlayer,255,255,255,true) 
            --end 
        else 
            outputChatBox("#FF6600* #FFFFFFPlease select a map from the list first!",thePlayer,255,255,255,true) 
        end 
    else 
        outputChatBox("#FF6600* #FFFFFFA map is already set at the moment! Please try again later.",thePlayer,255,255,255,true) 
    end 
end 

Link to comment
with your code :)

Stop.

lol Where i can put that code ? :roll:

Create a .lua file and put the code in. Save it. Then create a meta.xml like

<meta> 
    <script src="yourfilename.lua" type="server" /> 
</meta> 

And put it in your server resources folder. ( put the files in a folder or zip file )

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