Jump to content

a nil value


Newbie

Recommended Posts

Posted

I'ma trying to make a map shop, when i select map on gridlist and press button to buy i get this:

attempt to callServerFunction a nil value

Server:

function buyMap(player, command,  ...) 
    local account = ( ( getPlayerAccount( player ) and not isGuestAccount( getPlayerAccount( player ) ) ) and getPlayerAccount( player ) or false ) 
    if ( account ) then 
        local cashHave = tonumber( getAccountData( account, "Cash" ) ) 
        local buyMapss = tonumber( getAccountData( account, "BuyMaps" ) ) 
        if g_ForcedNextMap then 
            outputChatBox( 'Next map is ' .. getMapName( g_ForcedNextMap ), player ) 
            return 
        end 
        local query = #{...}>0 and table.concat({...},' ') or nil 
        if not query then 
            if g_ForcedNextMap then 
                outputChatBox( '#FF0000={#FFFFFFBuyMap#FF0000}=#FFFFFF Next map is ' .. getMapName( g_ForcedNextMap )"", player, 255, 0, 0, true) 
            else 
                outputChatBox( '#FF0000={#FFFFFFBuyMap#FF0000}=#FFFFFF Next map is not set', player, 255, 0, 0, true ) 
            end 
            return 
        end 
        local map = findMap(query) 
        if not map then 
            outputChatBox(errormsg, player) 
            return 
        end 
        if ( cashHave ) and ( cashHave >= 3000 ) then 
            if lastmap_B == map then 
                outputChatBox( '#FF0000={#FFFFFFBuyMap#FF0000}=#FFFFFF That map has been played too much recently.', player, 255, 0, 0, true) 
            else 
                g_ForcedNextMap = map 
                outputChatBox("#FF0000={#FFFFFFBuyMap#FF0000}=#FFFFFF "..getPlayerName(player).. " #FFFFFFbought next map to be #FF0000'" ..getMapName(g_ForcedNextMap).. "'", g_Root, 255, 255, 255, true) 
                setAccountData( account, "Cash", cashHave - 3000 ) 
                setAccountData( account,"BuyMaps",tostring( getAccountData( account,"BuyMaps" ) or 0 )+1 ) 
                lastmap_B = g_ForcedNextMap 
            end 
        else 
            outputChatBox("#FF0000={#FFFFFFBuyMap#FF0000}=#FFFFFF You don't have enough money! #FF00003000$", player, 255, 0, 0, true) 
        end 
    end 
end 
addCommandHandler('bm', buyMap) 
addCommandHandler('buymap', buyMap) 

Client:

function buyNextMap() 
    local row,column = guiGridListGetSelectedItem(mapGridList) 
    local mapName = guiGridListGetItemText(mapGridList,row,1) 
    callServerFunction("buyMap",getLocalPlayer(),mapName) 
end 
addEventHandler ( "onClientGUIClick", GUIEditor.button[4], buyNextMap, false ) 

Posted

I've have fixed it by changing to getMapName from mapName

and adding function to read the resource name of the selected map to make it match with buyMap function

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