Jump to content

Buymap / racevoting_server.lua


=KoG=Rouche

Recommended Posts

Hi all,

I've an userpanel with a function to buy map.

Unfortunately since an update its not working anyway.

What to i have to change in racevoting.lua to make the Buy Map working.

I think it's about nextmap function ?

My userpanel dysplay that the player has buy the map but when the previous map end nothing happend except random map.

Can someone help me with racevoting.lua ?

racevoting_server.lua

I tried to put some lines in commentary.

Becaus ethe script was checking if the player is in an admin group.

But it doesn't work :-/

  
--------------------------------------------------------------------------- 
-- 
-- More things that should go in mapmanager 
-- 
--------------------------------------------------------------------------- 
  
addCommandHandler('checkmap', 
    function( player, command, ... ) 
        local query = #{...}>0 and table.concat({...},' ') or nil 
        if query then 
            local map, errormsg = findMap( query ) 
            outputRace( errormsg, player ) 
        end 
    end 
) 
  
addCommandHandler('nextmap', 
    function( player, command, ... ) 
        local query = #{...}>0 and table.concat({...},' ') or nil 
        if not query then 
            if g_ForcedNextMap then 
                outputRace( 'Next map is ' .. getMapName( g_ForcedNextMap ), player ) 
            else 
                outputRace( 'Next map is not set', player ) 
            end 
            return 
        end 
        --if not _TESTING and not isPlayerInACLGroup(player, g_GameOptions.admingroup) then 
        --   return 
        --end 
        local map, errormsg = findMap( query ) 
        if not map then 
            outputRace( errormsg, player ) 
            return 
        end 
        if g_ForcedNextMap == map then 
            outputRace( 'Next map is already set to ' .. getMapName( g_ForcedNextMap ), player ) 
            return 
        end 
        g_ForcedNextMap = map 
        outputChatBox('Next map set to ' .. getMapName( g_ForcedNextMap ) .. ' by ' .. getPlayerName( player ), g_Root, 0, 240, 0) 
    end 
) 
  
--Find a map which matches, or nil and a text message if there is not one match 
function findMap( query ) 
    local maps = findMaps( query ) 
  
    -- Make status string 
    local status = "Found " .. #maps .. " match" .. ( #maps==1 and "" or "es" ) 
    for i=1,math.min(5,#maps) do 
        status = status .. ( i==1 and ": " or ", " ) .. "'" .. getMapName( maps[i] ) .. "'" 
    end 
    if #maps > 5 then 
        status = status .. " (" .. #maps - 5 .. " more)" 
    end 
  
    if #maps == 0 then 
        return nil, status .. " for '" .. query .. "'" 
    end 
    if #maps == 1 then 
        return maps[1], status 
    end 
    if #maps > 1 then 
        return nil, status 
    end 
end 
  
-- Find all maps which match the query string 
function findMaps( query ) 
    local results = {} 
    --escape all meta chars 
    query = string.gsub(query, "([%*%+%?%.%(%)%[%]%{%}%\%/%|%^%$%-])","%%%1") 
    -- Loop through and find matching maps 
    for i,resource in ipairs(exports.mapmanager:getMapsCompatibleWithGamemode(getThisResource())) do 
        local resName = getResourceName( resource ) 
        local infoName = getMapName( resource  ) 
  
        -- Look for exact match first 
        if query == resName or query == infoName then 
            return {resource} 
        end 
  
        -- Find match for query within infoName 
        if string.find( infoName:lower(), query:lower() ) then 
            table.insert( results, resource ) 
        end 
    end 
    return results 
end 
  
function getMapName( map ) 
    return getResourceInfo( map, "name" ) or getResourceName( map ) or "unknown" 
end 
  

Edited by Guest
Link to comment
  • 3 months later...
  • 3 weeks later...

I just re-installed the server from scratch.

-- Buy a next map 
function buyMap(mapName) 
        local account = getPlayerAccount(source) 
        local cash = getAccountData(account, "cash") 
        local level = getAccountData(account, "level") 
        if mapIsAlreadySet == false or not getElementData (getRootElement(),"mapIsAlreadySet") == true then 
        if not (mapName == "") then 
        if not (isGuestAccount(getPlayerAccount(source))) then 
            if tonumber(level) >= 15 then 
                if tonumber(cash) >= 2000 then 
                    outputChatBox("#FFFFFF[userpanel] #FF9900"..getPlayerName(source).."#FF9900 set a map for #FFFFFF 2000$",getRootElement(),255,255,255,true) 
                    outputChatBox("#FFFFFF[userpanel] #FF9900Next map: #FFFFFF"..tostring(mapName).." !",getRootElement(),255,255,255,true) 
                    executeCommandHandler("buymap", source, mapName) 
                    addStat(account, "cash", -2000) 
                else 
                outputChatBox("#FFFFFF[userpanel] #FF9900You don't have enough money to set a map ! (2000$)",source,255,255,255,true) 
                end 
            else 
                outputChatBox("#FFFFFF[userpanel] #FF9900You need to be level #FFFFFF15 #FF9900to buy maps!",source,255,255,255,true) 
            end 
        end 
        else 
            outputChatBox("#FFFFFF[userpanel] #FF9900Please select a map from the list first!",source,255,255,255,true) 
        end 
end 
end 
addEvent("triggerbuyMap",true) 
addEventHandler( "triggerbuyMap", getRootElement(),buyMap ) 
  
function onBuyMapReady() 
local account = getPlayerAccount(source) 
addStat(account,"cash",-1500) 
end 
addEvent("setCashofBuyMap",true) 
addEventHandler( "setCashofBuyMap", getRootElement(), onBuyMapReady ) 
  
--end MAP 

Link to comment
The user panel have triggerServerEvent or executeCommandHandler? Check and post the string.

Why you no reply my old question? Anyway is a executeCommandHandler.

Add this function down on racevoting_server.lua

  
addCommandHandler('buymap', 
    function( player, command, ... ) 
        local query = #{...}>0 and table.concat({...},' ') or nil 
        if not query then 
            if g_ForcedNextMap then 
                outputRace( 'Next map is ' .. getMapName( g_ForcedNextMap ), player ) 
            else 
                outputRace( 'Next map is not set', player ) 
            end 
            return 
        end 
        local map, errormsg = findMap( query ) 
        if not map then 
            outputRace( errormsg, player ) 
            return 
        end 
        if g_ForcedNextMap == map then 
            outputRace( 'Next map is already set to ' .. getMapName( g_ForcedNextMap ), player ) 
            return 
        end 
        g_ForcedNextMap = map 
        outputChatBox('' .. getPlayerName( player )..' Buy Next map ' .. getMapName( g_ForcedNextMap ) .. '', g_Root, 255, 200, 0) 
    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...