Jump to content

[HELP] Stop gravity after 5 seconds


Tommy.

Recommended Posts

I want to stop the gravity after 5 seconds

Gravity changes to 0.0001 but does not return to 0.0008

 

--client side


panel = false
function test()
	dxDrawRectangle(414, 297, 109, 29, tocolor(0, 0, 0, 150), false)
	dxDrawText("TEST GRAVITY", 414, 297, 523, 326, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
end
function onClientClick (button,state)
	if parte1hab and button == "left" and state == "down" then
		if isCursorOnElement(414, 297, 109, 29) then 
			triggerServerEvent ("Gravity-5s", getLocalPlayer())
		end
	end
end
addEventHandler("onClientClick",root,onClientClick)

function open()
	if panel == false then
		addEventHandler ("onClientRender", root, test)
		panel = true 
		showCursor (true)
	else
		removeEventHandler ("onClientRender", root, test)
		panel = false
		showCursor (false) 
	end
end
bindKey("F5", "down", open)

 

--server side

function Gravity ()
    setPedGravity(source, 0.0001)
	setTimer(function()
		setPedGravity(source, 0.0008)
	end, 5000, 1)	
end
addEvent("Gravity-5s",true)
addEventHandler("Gravity-5s",getRootElement(),Gravity)

 

Edited by Tommy.
Link to comment

Source does not exists inside the timer (line 4 server)

You must pass the source as a parameter to the timer

Spoiler

function Gravity ()
    setPedGravity(source, 0.0001)
	setTimer(function(player)--this parameter is the parameter passed below
		setPedGravity(player, 0.0008)
	end, 5000, 1, source)--this parameter will be handled from the function
end
addEvent("Gravity-5s",true)
addEventHandler("Gravity-5s",getRootElement(),Gravity)

 

 

Edited by LoPollo
Link to comment
1 minute ago, LoPollo said:

Source does not exists inside the timer (line 4 server)

You must pass the source as a parameter to the timer

 

 

 

that's right?

function Gravity ()
    setPedGravity(source, 0.0001)
	setTimer(function(source)
		setPedGravity(source, 0.0008)
	end, 5000, 1)	
end
addEvent("Gravity-5s",true)
addEventHandler("Gravity-5s",getRootElement(),Gravity)

 

Link to comment
3 minutes ago, Gravestone said:

Try


function Gravity ()
    setPedGravity(source, 0.0001)
  	player = source 
	setTimer(function()
		setPedGravity(player, 0.0008)
	end, 5000, 1)	
end
addEvent("Gravity-5s",true)
addEventHandler("Gravity-5s",getRootElement(),Gravity)

No error in debugscript but does not work :'(

Link to comment
1 minute ago, LoPollo said:

the code i provided is working for me, but the default gravity is 0.008 (not 0.0008 btw

i do have an element at argument 1, are you sure u copied the code? (maybe you edited and forgot something, dunno)

Thanks, I was putting 0.0008 <3

  • Like 1
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...