Jump to content

newResource


itHyperoX

Recommended Posts

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
  • Moderators
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)

  • Like 1
Link to comment
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
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 "{}"

 

  1. outputChatBox("NewResource loaded: Here is the last resource name which loaded.", source, 255, 255,255,true) -- at here, i want something like this:
  2.  
  3. outputChatBox("New resource loaded: "..newResourceName, source)

i hope you understand what i want to do.

Edited by TheMOG
Link to comment

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