Jump to content

LOCKED


Madex99

Recommended Posts

  • Moderators

Every time you press a key.

function Switch(button,press)
  -- yes here
end
addEventHandler("onClientKey", root, Switch)

=

You create a new function/functions with an addEventHandler attached to it.

 

With other words, you created a memory leak by doing this:

addEventHandler("onClientKey", root, function (button, press)
	if button == a[0] then    
		if (press) then
			if wep == 0 then
				setPedWeaponSlot(localPlayer, z+1)                                
			else
				setPedWeaponSlot(localPlayer,0)                                
			end                                
		end
	end
end)

 

For every next click you execute those addEventHandlers * times you clicked. The longer you are doing this, the more lag it creates.

 


 

You are having 8 loops that execute 13 times. 8 * 13 = 104 looping.

for z= 0,12 do
  -- yes this 8 times.
end

How about you just use 1? :x

 


 

 

I do not even know how it is suppose to work, so I am not going to rewrite your code.

What I do recommend you to is write very clear how your code is suppose to function. And write down which steps the code has to take to achieve it's goal.

 

>>> Writing a new unknown functionality without defining it's steps is bad practice. (Unless you have written something similar before) <<< Not everybody agrees to this, that is fine.

 

 

 

 

 

Edited by IIYAMA
Link to comment
On 8/13/2018 at 11:25, IIYAMA said:

Every time you press a key.


function Switch(button,press)
  -- yes here
end
addEventHandler("onClientKey", root, Switch)

=

You create a new function/functions with an addEventHandler attached to it.

 

With other words, you created a memory leak by doing this:


addEventHandler("onClientKey", root, function (button, press)
	if button == a[0] then    
		if (press) then
			if wep == 0 then
				setPedWeaponSlot(localPlayer, z+1)                                
			else
				setPedWeaponSlot(localPlayer,0)                                
			end                                
		end
	end
end)

 

For every next click you execute those addEventHandlers * times you clicked. The longer you are doing this, the more lag it creates.

 


 

You are having 8 loops that execute 13 times. 8 * 13 = 104 looping.


for z= 0,12 do
  -- yes this 8 times.
end

How about you just use 1? :x

 


 

 

I do not even know how it is suppose to work, so I am not going to rewrite your code.

What I do recommend you to is write very clear how your code is suppose to function. And write down which steps the code has to take to achieve it's goal.

 

>>> Writing a new unknown functionality without defining it's steps is bad practice. (Unless you have written something similar before) <<< Not everybody agrees to this, that is fine.

 

 

 

 

 

If you know CIT binds script,  weapon switch system with 2 slots in 1 bind, thats my code, if you can fix it please do it.

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

If you know CIT binds script,  weapon switch system with 2 slots in 1 bind, thats my code, if you can fix it please do it.

I am sorry, I do not play CIT.

 

Please make some of your own adjustments first based on my feedback, before you give it to somebody else. That is the least thing you can do in order to understand your own mistakes.

Link to comment
On 8/14/2018 at 08:14, IIYAMA said:

I am sorry, I do not play CIT.

 

Please make some of your own adjustments first based on my feedback, before you give it to somebody else. That is the least thing you can do in order to understand your own mistakes.

I would have done it if I understood you 

Link to comment
  • Moderators
10 hours ago, TheRobot2144 said:

I would have done it if I understood you 

Reducing 8 similar loops to 1 loop is unclear? Really?

Momentarily you are giving me the feeling that you do not understand your own script, which is a big issue.

Link to comment
  • Madex99 changed the title to LOCKED

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