Jump to content

Server triggers empty table to Client


Et-win

Recommended Posts

Hello,

As you look to the title you know my question.

Client:

function requestServerMaps() 
    triggerServerEvent("clientrequestservermaps", getLocalPlayer()) 
end 
  
addCommandHandler("testen", requestServerMaps) 
  
function nowdooutput(themaps) 
    for l, k in ipairs(themaps) do 
        outputChatBox(tostring(k)) 
    end 
    outputChatBox(tostring(themaps)) 
    outputChatBox(tostring(themaps[1])) 
end 
  
addEvent("sendbackservermaps", true) 
addEventHandler("sendbackservermaps", getRootElement(), nowdooutput) 

Server:

function getservermapsnow() 
    themaps = exports.mapmanager:getMapsCompatibleWithGamemode(getResourceFromName("race")) 
    for l, k in ipairs(themaps) do 
        outputChatBox(tostring(k)) 
    end 
    triggerClientEvent(source, "sendbackservermaps", getRootElement(), themaps) 
end 
  
addEvent("clientrequestservermaps", true) 
addEventHandler("clientrequestservermaps", getRootElement(), getservermapsnow) 

(Script fastly made for testing, so sorry if it's a bit messy :P )

If I output it with "ipairs" in serverside, it does return every map that is on the server. If I do the same on clientside, the table is suddently empty. It DOES return the table, but still, it's empty.

My question now is: How it can be empty? I remade a simple function (This one here above) to check or it was my first function's fault, but nope, my official function and this function both do the same.

PS: I did try to trigger "lol = {"Hai", "Naab"}" towards client, this was successful.

Link to comment
  • Moderators

Probably because the resource element can't be send of to clients.

You should only send the names.

function getservermapsnow() 
    local raceResource = getResourceFromName("race") 
    if raceResource then 
        local themaps = exports.mapmanager:getMapsCompatibleWithGamemode(raceResource)   
        if themaps then 
            local mapNames = {} 
            for i=1,#themaps do 
                local name = getResourceName(themaps[i]) 
                if name then 
                    mapNames[#mapNames+1]= name 
                end 
            end 
            if #mapNames > 0 then 
                triggerClientEvent(source, "sendbackservermaps", root, mapNames) 
            end 
        end 
    end 
end 
  
addEvent("clientrequestservermaps", true) 
addEventHandler("clientrequestservermaps", root, getservermapsnow) 

Link to comment
Probably because the resource element can't be send of to clients.

You should only send the names.

[stuff]

Hello and thank you for the reply. Indeed this was the solution. I just totally forgot to only trigger the names, normally I did this before, but now I just forgot it. :)

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