Jump to content

Superjump (player) script


Lalalu

Recommended Posts

Hello guys, i'm doing this post today because i need help with something .. i extracted this code from a superpowers script, i think that's all the code, i want to separate this code from all the script and that can be used with command, or always active, but i don't know what to delete to achieve that, could you guide me?this script basically consist in a superjump, if the key is pressed the player jumps very high until the button is released

superjumping = 0

function rocketjump()
	startrocketjumpingthing = nil
	if getControlState("jump") == true then
		local task = getPedSimplestTask(getLocalPlayer())
		if task == "TASK_SIMPLE_IN_AIR"  and superjumping == 0 then
			if isTimer(startgroundchecktimer) then
				resetTimer ( startgroundchecktimer)
			else
				startgroundchecktimer = setTimer ( startjumpgroundcheck, 300, 1)
			end
			superjumpgroundcheck = 0
			addEventHandler("onClientRender",getRootElement(), rocketplayer )
			addEventHandler("onClientRender",getRootElement(), jumpgroundcheck )
			triggerServerEvent ("onSpeedChange", getLocalPlayer(), "jumping")
			jumpstart = getTickCount()
			superjumping = 1
		end
	end
end

function triggersuperjump(key, keyState)
	if getElementData( getLocalPlayer(), "transport_power" ) == "superjump" then
		if keyState == "down" then
			local px,py,pz = getElementPosition( getLocalPlayer () )
			local isclear = isLineOfSightClear ( px, py, pz,px, py, pz-3,true,true, true, true,true,true, false, getLocalPlayer() )
			if isTimer(startrocketjumpingthing) == false and isclear == false then
				startrocketjumpingthing = setTimer ( rocketjump, 650, 1)
			end
		elseif keyState == "up" then
			removeEventHandler("onClientRender",getRootElement(), rocketplayer )
		end
	end
end
bindKey("jump", "both", triggersuperjump)

function rocketplayer()
	local px,py,pz = getElementPosition( getLocalPlayer () )
	local currenttask = getPedSimplestTask(getLocalPlayer())
	if getTickCount() - jumpstart < 4500 and currenttask ~= "TASK_SIMPLE_NAMED_ANIM" then
		if getTickCount() - jumpstart > 3000 then
			theZ = 0
		elseif getTickCount() - jumpstart > 2000 then
			theZ = .1
		else
			theZ = .3
		end
		local playerangle = getPedRotation(getLocalPlayer())
		local newradRot = math.rad ( playerangle )
		local radius = 3
		local ex = px + radius * math.sin(newradRot)
		local ey = py + -(radius) * math.cos(newradRot)
		local ez = pz
		x,y,z = px-ex,py-ey,pz-ez
		local dist = math.sqrt(x*x+y*y+z*z)
		x = x*.4/dist
		y = y*.4/dist
		setElementVelocity(getLocalPlayer(),x, y, theZ)
	else
		removeEventHandler("onClientRender",getRootElement(), rocketplayer )
	end
end

function jumpgroundcheck()
	if superjumpgroundcheck == 1 then
		local px,py,pz = getElementPosition( getLocalPlayer () )
		local isclear = isLineOfSightClear ( px, py, pz,px, py, pz-2.5,true,true, true, true,true,true, false, getLocalPlayer() )
		local currenttask = getPedSimplestTask(getLocalPlayer())
		if isclear == false or currenttask == "TASK_SIMPLE_LAND" or isElementInWater(getLocalPlayer()) == true then
			removeEventHandler("onClientRender",getRootElement(), jumpgroundcheck )
			setElementPosition(getLocalPlayer(),px,py,pz )
			removeEventHandler("onClientRender",getRootElement(), rocketplayer )
			superjumping = 0
			triggerServerEvent ("onJumpChange", getLocalPlayer(), "normal")
		end
	end
end

function startjumpgroundcheck()
	superjumpgroundcheck = 1
	startgroundchecktimer = nil
	triggerServerEvent ("onJumpChange", getLocalPlayer(), "jumping")
end

 

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