SrPattif Posted December 13, 2020 Share Posted December 13, 2020 Hi. I had this script via server-side: -- server_side for i,v in ipairs(resourceTable) do print(getResourceName(v)) end server-side, works normally. But in client-side, it does not work. It just dont print nothing. -/> i got the resources table via triggerServerEvent, and the type() of the response via client-side is really table. if you can help, I would be grateful. Link to comment
Tekken Posted December 13, 2020 Share Posted December 13, 2020 (edited) May we see the serverside and also the entire handling in client? Edited December 13, 2020 by Tekken Link to comment
Moderators IIYAMA Posted December 13, 2020 Moderators Share Posted December 13, 2020 48 minutes ago, SrPattif said: But in client-side, it does not work. That is probably because the following function is serverside only: https://wiki.multitheftauto.com/wiki/GetResources See here a workaround for clientside: local resourceRoots = getElementsByType("resource") for i=1, #resourceRoots do local thisResourceRoot = resourceRoots[i] local resourceName = getElementID ( thisResourceRoot ) if resourceName then local res = getResourceFromName(resourceName) if res and res ~= resource and getResourceState(res) == "running" then end end end Source resource: draw-distance https://gitlab.com/IIYAMA12/draw-distance/-/blob/master/scripts/main_c.lua#L248 Link to comment
SrPattif Posted December 13, 2020 Author Share Posted December 13, 2020 33 minutes ago, IIYAMA said: That is probably because the following function is serverside only: https://wiki.multitheftauto.com/wiki/GetResources See here a workaround for clientside: local resourceRoots = getElementsByType("resource") for i=1, #resourceRoots do local thisResourceRoot = resourceRoots[i] local resourceName = getElementID ( thisResourceRoot ) if resourceName then local res = getResourceFromName(resourceName) if res and res ~= resource and getResourceState(res) == "running" then end end end Source resource: draw-distance https://gitlab.com/IIYAMA12/draw-distance/-/blob/master/scripts/main_c.lua#L248 This helped me, but it only shows the scripts already initialized. -- client-side function carregarResources() local resourceRoots = getElementsByType("resource") for i=1, #resourceRoots do local thisResourceRoot = resourceRoots[i] local resourceName = getElementID ( thisResourceRoot ) if resourceName then local res = getResourceFromName(resourceName) if res and res ~= resource then guiGridListAddRow(GUI.gridlist[1], getResourceName(res)) end end end end Link to comment
Moderators IIYAMA Posted December 13, 2020 Moderators Share Posted December 13, 2020 (edited) 49 minutes ago, SrPattif said: This helped me, but it only shows the scripts already initialized. That is correct, because you can't do anything with resources that are not initialized. Except maybe for the name. (for new resources: onClientResourceStart) If you only need the resourceNames: You could save elementdata on the resourceRoot containing all resourceNames. Or (more secure/controllable) triggerServerEvent > triggerClientEvent to send over all the resourceNames. But think twice about which resourceNames you send over. Since it might be a little privacy sensitive for you... Edited December 13, 2020 by IIYAMA Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now