itHyperoX Posted December 2, 2017 Share Posted December 2, 2017 Hello, how can i make that, if new resource loaded, its showing me only that, not the old ones? I tried like addCommandHandler("refreshres",function(source) local resources = getResources() for i,v in ipairs(resources) do if getResourceState(v) == "loaded" then end end refreshResources(true) outputChatBox("NewResource loaded: Here is the last resource name which loaded.", source, 255, 255,255,true) end) Anybody can help me please Link to comment
Bonus Posted December 2, 2017 Share Posted December 2, 2017 (edited) Your for loop doesn't do anything, use it properly and you got it. Edited December 2, 2017 by Bonus 1 Link to comment
Moderators IIYAMA Posted December 2, 2017 Moderators Share Posted December 2, 2017 addCommandHandler("refreshres",function(source) local resources = getResources() local oldResources = {} for i,v in ipairs(resources) do if getResourceState(v) ~= "failed to load" then oldResources[v] = true end end refreshResources(true) local resources = getResources() local newResources = {} for i,v in ipairs(resources) do if not oldResources[v] and getResourceState(v) ~= "failed to load" then newResources[#newResources + 1] = v end end iprint(newResources) outputChatBox("NewResource loaded: Here is the last resource name which loaded.", source, 255, 255,255,true) end) You might need to set a timer before you re-check the resources again. (not sure because I never tried it) 1 Link to comment
idarrr Posted December 2, 2017 Share Posted December 2, 2017 addCommandHandler("refreshres",function(source) refreshResources(true) -- refresh the resource first, then loop local resources = getResources() for i,v in ipairs(resources) do if getResourceState(v) == "loaded" then end end outputChatBox("NewResource loaded: Here is the last resource(s) name which loaded. Not that resource which is already loaded", source, 255, 255,255,true) end) Link to comment
itHyperoX Posted December 3, 2017 Author Share Posted December 3, 2017 (edited) 10 hours ago, IIYAMA said: addCommandHandler("refreshres",function(source) local resources = getResources() local oldResources = {} for i,v in ipairs(resources) do if getResourceState(v) ~= "failed to load" then oldResources[v] = true end end refreshResources(true) local resources = getResources() local newResources = {} for i,v in ipairs(resources) do if not oldResources[v] and getResourceState(v) ~= "failed to load" then newResources[#newResources + 1] = v end end iprint(newResources) outputChatBox("NewResource loaded: Here is the last resource name which loaded.", source, 255, 255,255,true) -- at here, i want something like this: outputChatBox("New resource loaded: "..newResourceName, source) end) You might need to set a timer before you re-check the resources again. (not sure because I never tried it) Thank you, but its keep debugging me "{}" outputChatBox("NewResource loaded: Here is the last resource name which loaded.", source, 255, 255,255,true) -- at here, i want something like this: outputChatBox("New resource loaded: "..newResourceName, source) i hope you understand what i want to do. Edited December 3, 2017 by TheMOG Link to comment
Bonus Posted December 3, 2017 Share Posted December 3, 2017 (edited) newResourceName is a table, not a string. Just use the "New resource loaded:" output instead of line 18 (newResources[#newResources + 1] ...). And use getResourceName ( v ) instead of newResourceName. Then you can also remove line 15 (local newResources = {}). Edited December 3, 2017 by Bonus Link to comment
Moderators IIYAMA Posted December 3, 2017 Moderators Share Posted December 3, 2017 7 hours ago, TheMOG said: Thank you, but its keep debugging me "{}" outputChatBox("NewResource loaded: Here is the last resource name which loaded.", source, 255, 255,255,true) -- at here, i want something like this: outputChatBox("New resource loaded: "..newResourceName, source) i hope you understand what i want to do. Add a time as I suggested. Link to comment
itHyperoX Posted December 3, 2017 Author Share Posted December 3, 2017 Yeah, already fixed it, forgot to reply. Thanks @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