Jump to content

Set movement style - function


srslyyyy

Recommended Posts

  • Scripting Moderators

Hi. I created a function for enable/disable things like: walk, sprint, jump. However this function runs every 300ms on client side.

Any idea how can i improve it, to remove timer at all? (I tried to do it without timer - but without it, it doesn't work as it should)

 

function checkPlayerMovementStyle()
	local value = skinsData["Movement"][getElementModel(getLocalPlayer())]
	if value then
		setPedControlState(getLocalPlayer(), "walk", value[1])
		toggleControl("sprint", value[2])
		toggleControl("jump", value[3])
	end
end
setTimer(checkPlayerMovementStyle, 300, 0)

 

 

Link to comment
  • Scripting Moderators
8 minutes ago, DeadthStrock said:

Seems this code is toggling  player's sprint and jump every 300 miliseconds. But when you toggle the control one time... it will last longer until you enable it. Is't it ?


Without timer this thing:

setPedControlState(getLocalPlayer(), "walk", value[1])

isn't working, if i want to player move slowly all the time, after sometime it looks like this thing disable. (player can walk like you are exhausted, i want to player move all the time on ALT)

Edited by majqq
Link to comment

can you test below peace of code separately from your resource ? and tell what you think about it related to your code ? after command as /walk

function checkPlayerMovementStyle()
    setTimer(
	function ()
	    value = {}
	    value[1] = true
	    value[2] = false
	    setTimer(setPedControlState,50,2,getLocalPlayer(), "walk", value[1])
	    toggleControl("walk", value[2])
	    toggleControl("sprint", value[2])
	    toggleControl("jump", value[2])
	end,500,1)
end
addCommandHandler("walk",checkPlayerMovementStyle)

 

Edited by DeadthStrock
  • Thanks 1
Link to comment
  • Scripting Moderators
On 05/02/2019 at 16:15, DeadthStrock said:

can you test below peace of code separately from your resource ? and tell what you think about it related to your code ? after command as /walk


function checkPlayerMovementStyle()
    setTimer(
	function ()
	    value = {}
	    value[1] = true
	    value[2] = false
	    setTimer(setPedControlState,50,2,getLocalPlayer(), "walk", value[1])
	    toggleControl("walk", value[2])
	    toggleControl("sprint", value[2])
	    toggleControl("jump", value[2])
	end,500,1)
end
addCommandHandler("walk",checkPlayerMovementStyle)

 

 

I'll try it out soon, after it i'll answer you. Thanks.

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