Jump to content

Problem whit userpanel


Snoop.Cat

Recommended Posts

hey guys , i have this code on my userpanel to buy maps , but it doesnt not really buys the map , it takes the money but nothing happens then :/ , also i dont know if is problem of racevoting_server.lua, but i dont know what to add on there.

Client

-- Get all maps on server 
function getMaps() 
    totalServerMaps = 0 
    totalDmMaps = 0 
    totalDdMaps = 0 
    setTimer(callServerFunction,2000,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) 
                    totalServerMaps = totalServerMaps+1 
                    if (string.find(map.name,"[DM]",1,true)) then 
                        totalDmMaps = totalDmMaps+1 
                    elseif (string.find(map.name,"[DD]",1,true)) then 
                        totalDdMaps = totalDdMaps+1 
                    elseif (string.find(map.name,"[FUN]",1,true)) then 
                        totalDdMaps = totalDdMaps+1 
                    end 
                    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) 
    guiSetVisible(tabs[5],false) 
    guiSetInputEnabled (false) 
    showCursor(false) 
end 
  
--Command for buy maps 
function buyMapsCommand(command, ... ) 
local mapName = #{...}>0 and table.concat({...},' ') or nil 
  
    if not(mapName)then 
        getMapsOnce() 
        guiSetVisible(tabs[5],true) 
        guiSetInputEnabled (true) 
        showCursor(true) 
    else 
        callServerFunction("buyMapSecond",getLocalPlayer(),mapName) 
    end 
end 
addCommandHandler("bm", buyMapsCommand) 
  
  
-- 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/FUN 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 

Server

-- Buy a next map 
function buyMap(thePlayer,mapName) 
if not(isEventRunning)then 
    local playersOn = getPlayerCount() 
    local playerPoint = tonumber(getPlayerDataRam(thePlayer,"pointsRam")) 
    local playerCash = tonumber(getPlayerDataRam(thePlayer,"cash")) 
    if mapIsAlreadySet == false then 
        if not (mapName == "") then 
        if(playersOn == 1)then 
            triggerEvent("onPlayerBuyMap", getRootElement(), false, 50000, mapName) 
            outputChatBox("#FF6600* #999999Buying a map when you are alone on the server is free.",thePlayer,255,255,255,true) 
            return 
        end 
                if playerCash >= mapCost then 
                    triggerEvent("onPlayerBuyMap", getRootElement(), thePlayer, playerCash, mapName) 
                else 
                    outputChatBox("#FF6600* #FFFFFFYou don't have enough money to set a map!",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, try again nextmap.",thePlayer,255,255,255,true) 
    end 
else 
    outputChatBox("#FF6600* #FFFFFFYou can't buy maps during the #aaff00DGE#FFFFFF.",thePlayer,255,255,255,true) 
end 
end 
  
  
function buyMapSecond(thePlayer,mapName) 
if not(isEventRunning)then 
    local playersOn = getPlayerCount() 
    local playerPoint = tonumber(getPlayerDataRam(thePlayer,"pointsRam")) 
    local playerCash = tonumber(getPlayerDataRam(thePlayer,"cash")) 
     
    if mapIsAlreadySet == false then 
        if not (mapName == "") then 
        if(playersOn == 1)then 
            triggerEvent("onPlayerBuyMapSecond", getRootElement(), false, 50000, mapName) 
            outputChatBox("#FF6600* #999999Buying a map when you are alone on the server is free.",thePlayer,255,255,255,true) 
            return 
        end 
                if playerCash >= mapCost then 
                    triggerEvent("onPlayerBuyMapSecond", getRootElement(), thePlayer, playerCash, mapName) 
                else 
                    outputChatBox("#FF6600* #FFFFFFYou don't have enough money to set a map!",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 
    else 
        outputChatBox("#FF6600* #FFFFFFYou can't buy maps during the #aaff00DGE#FFFFFF.",thePlayer,255,255,255,true) 
end 
end 
  
  
function onPlayerSuccessfullyBuyMap(thePlayer, mapName, expensive) 
local playerCash = tonumber(getPlayerDataRam(thePlayer,"cash")) 
local cost = mapCost 
if(expensive)then cost = 50000 end 
    setPlayerDataRam(thePlayer,"cash",playerCash-cost,false) 
    scoreboardRefresh(thePlayer) 
    outputChatBox("#FF4000*#FFFFFF "..getPlayerName(thePlayer).."#FFFFFF has bought #FF6600'"..mapName.."#FF6600'#FFFFFF!",getRootElement(),255,255,255,true) 
    achievement31(thePlayer) 
end 
addEvent("onPlayerSuccessBuyMap", true) 
addEventHandler("onPlayerSuccessBuyMap", getRootElement(), onPlayerSuccessfullyBuyMap) 
  
  
rootElement = getRootElement() 
  
addEvent('buyMapFromPanel', true) 
function buyMFP(mapname) 
    buyMap(source, command, mapname) 
end 
addEventHandler('buyMapFromPanel', rootElement, buyMFP) 
  
  
addCommandHandler("mapcount", 
    function(source) 
        local resourceTable = getResources() 
        local mapcount = 0 
        for resourceKey, resourceValue in ipairs(resourceTable) do 
            local type = getResourceInfo(resourceValue, "type") 
            local game = getResourceInfo(resourceValue, "gamemodes") 
            if type == "map" and game == "race" then 
                mapcount = mapcount+1 
            else 
                cancelEvent() 
            end 
        end 
        outputChatBox("There are " ..tostring(mapcount).. " maps on the server.", source, 46, 154, 254) 
    end 
) 
  
  
addEvent("onRaceSetNextMap",true) 
addEventHandler("onRaceSetNextMap",getRootElement(), 
function () 
    mapIsAlreadySet = true 
end) 
  
function executeOnMatStarting() 
    mapIsAlreadySet = false 
end 
addEvent("onMapSuccessfullyStart") 
addEventHandler("onMapSuccessfullyStart", getRootElement(), executeOnMatStarting) 
  
--Disables the votemanager resource 
function disableRaceVotingResource() 
    local resource = getResourceFromName ( "votemanager" ) 
    if (getResourceState(resource) == "running" ) then 
       stopResource(resource) 
    end 
end 
addEventHandler("onMapStarting",getRootElement(),function()setTimer(disableRaceVotingResource, 3000, 1)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...