itHyperoX Posted December 2, 2017 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
Bonus Posted December 2, 2017 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
Moderators IIYAMA Posted December 2, 2017 Moderators 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
idarrr Posted December 2, 2017 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)
itHyperoX Posted December 3, 2017 Author 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
Bonus Posted December 3, 2017 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
Moderators IIYAMA Posted December 3, 2017 Moderators 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.
itHyperoX Posted December 3, 2017 Author Posted December 3, 2017 Yeah, already fixed it, forgot to reply. Thanks @IIYAMA
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