Jump to content

setTimer making fps drop every in 10 seconds


SoManyTears

Recommended Posts

these codes I wrote do drop fps every 10 seconds.How can I use the setlementCollidableWith function properly? please help friends.

 

setTimer (function()
for i,peds in ipairs (getElementsByType ("ped")) do
for i,players in ipairs (getElementsByType ("player")) do
setElementCollidableWith (peds,players,false)
end
for i,vehicles in ipairs (getElementsByType ("vehicle")) do
setElementCollidableWith (peds,vehicles,false)
end
for i,objects in ipairs (getElementsByType ("object")) do
setElementCollidableWith (peds,objects,false)
end
end
end,10000,0)

 

Link to comment
  • Moderators
3 hours ago, SoManyTears said:

these codes I wrote do drop fps every 10 seconds.How can I use the setlementCollidableWith function properly? please help friends.

You could apply the effect only when the elements are streamed in, that would be an enormous improved in terms of performance.

-- already streamed in elements
for i,peds in ipairs (getElementsByType ("ped", root, true)) do
  for i,players in ipairs (getElementsByType ("player", root, true)) do
  	setElementCollidableWith (peds,players,false)
  end
  for i,vehicles in ipairs (getElementsByType ("vehicle", root, true)) do
  	setElementCollidableWith (peds,vehicles,false)
  end
  for i,objects in ipairs (getElementsByType ("object", root, true)) do
  	setElementCollidableWith (peds,objects,false)
  end
end


--

-- new streamed in elements
local acceptedElementTypes = {player = true, vehicle = true, object = true}
addEventHandler( "onClientElementStreamIn", root,
    function ( )
		local elementType = getElementType( source )
		if acceptedElementTypes[elementType] then
			local peds = getElementsByType ("ped", root, true)
			for i=1, #peds do
				local ped = peds[i]
				setElementCollidableWith (ped,source,false)
			end
		elseif elementType == "ped" then
			-- what if it is a new ped? You can program this step yourself.
		end
    
	end
)

 

Edited by IIYAMA
  • Thanks 1
Link to comment
  • Moderators
37 minutes ago, SoManyTears said:

 

thank you for your help IIYAMA. i was away from the computer.I tried this but failed.still peds cannot pass through objects.

I assume you filled in the last part? (where my comment is)

Please show me what you cooked from it.

Link to comment
  • 2 weeks later...

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