Jump to content

Forced parachute jump on changing position


Recommended Posts

When he´s changing the position? You mean when he moves, when you use setElementPosition or when he falls?

If you´re talking about movement, you could use bindKey (), if you´re talking about setElementPosition(), you need to trigger an event, if you're talking about falling, use isPedOnGround() and a timer. giveWeapon () to give him the parachute and setElementPosition (x,y,z+100) to get the player be 100 units above his actual position (x,y,z obviously being his position parameters using getElementPosition()).

I think you should be more specific.

Link to comment
---------------------------
-- Set position window
---------------------------
do
	local screenWidth, screenHeight = guiGetScreenSize()
	if screenHeight < 700 then
		g_MapSide = 450
	else
		g_MapSide = 700
	end
end

function setPosInit()
	local x, y, z = getElementPosition(g_Me)
	setControlNumbers(wndSetPos, { x = x, y = y, z = z })	
	addEventHandler('onClientRender', g_Root, updatePlayerBlips)
end

function fillInPosition(relX, relY, btn)
	if (btn == 'right') then
		closeWindow (wndSetPos)
		return
	end

	local x = relX*6000 - 3000
	local y = 3000 - relY*6000
	local hit, hitX, hitY, hitZ
	hit, hitX, hitY, hitZ = processLineOfSight(x, y, 3000, x, y, -3000)
	setControlNumbers(wndSetPos, { x = x, y = y, z = hitZ or 0 })
end

function setPosClick()
	setPlayerPosition(getControlNumbers(wndSetPos, {'x', 'y', 'z'}))
	closeWindow(wndSetPos)
end

function setPlayerPosition(x, y, z)
    if getElementData ( localPlayer, "attached" ) then return end
	if getElementData(g_Me, "timer.setpos") == "cooldown" then
	errMsg('Please Wait 10 Seconds Before Warping Again.')
	return
	else
		if not isPedInVehicle(g_Me) then
		setElementData(g_Me, "timer.setpos", "cooldown")
		setTimer(setElementData, 10000, 1, g_Me, "timer.setpos", "normal")
		end
	local elem = getPedOccupiedVehicle(g_Me)
	local distanceToGround
	local isVehicle
		if elem then
		errMsg('Please leave the vehicle to change your position.')
		return
		else
		elem = g_Me
		distanceToGround = 0.4
		isVehicle = false
		end
	local hit, hitX, hitY, hitZ = processLineOfSight(x, y, 3000, x, y, -3000)
	if not hit then
		if isVehicle then
		server.fadeVehiclePassengersCamera(false)
		else
		fadeCamera(false)
		end
	setTimer(setCameraMatrix, 1000, 1, x, y, z)
	local grav = getGravity()
	setGravity(0.001)
	g_TeleportTimer = setTimer(
		function()
		local hit, groundX, groundY, groundZ = processLineOfSight(x, y, 3000, x, y, -3000)
			if hit then
			local waterZ = getWaterLevel(x, y, 100)
			z = (waterZ and math.max(groundZ, waterZ) or groundZ) + distanceToGround
				if isPlayerDead(g_Me) then
				server.spawnMe(x, y, z)
				else
				setElementPosition(elem, x, y, z)
				end
			setCameraPlayerMode()
			setGravity(grav)
				if isVehicle then
				server.fadeVehiclePassengersCamera(true)
				else
				fadeCamera(true)
				end
			killTimer(g_TeleportTimer)
			g_TeleportTimer = nil
			end
		end,
	500,
	0
	)
	else
		if isPlayerDead(g_Me) then
		server.spawnMe(x, y, z + distanceToGround)
		else
		setElementPosition(elem, x, y, z + distanceToGround)
			if isVehicle then
			setTimer(setElementVelocity, 100, 1, elem, 0, 0, 0)
			setTimer(setVehicleTurnVelocity, 100, 1, elem, 0, 0, 0)
			end
		end
	end
end
end

function updatePlayerBlips()
	if not g_PlayerData then
		return
	end
	local wnd = isWindowOpen(wndSpawnMap) and wndSpawnMap or wndSetPos
	local mapControl = getControl(wnd, 'map')
	for elem,player in pairs(g_PlayerData) do
		if not player.gui.mapBlip then
			player.gui.mapBlip = guiCreateStaticImage(0, 0, 9, 9, elem == g_Me and 'localplayerblip.png' or 'playerblip.png', false, mapControl)
			player.gui.mapLabelShadow = guiCreateLabel(0, 0, 100, 14, player.name, false, mapControl)
			local labelWidth = guiLabelGetTextExtent(player.gui.mapLabelShadow)
			guiSetSize(player.gui.mapLabelShadow, labelWidth, 14, false)
			guiSetFont(player.gui.mapLabelShadow, 'default-bold-small')
			guiLabelSetColor(player.gui.mapLabelShadow, 255, 255, 255)
			player.gui.mapLabel = guiCreateLabel(0, 0, labelWidth, 14, player.name, false, mapControl)
			guiSetFont(player.gui.mapLabel, 'default-bold-small')
			guiLabelSetColor(player.gui.mapLabel, 0, 0, 0)
			for i,name in ipairs({'mapBlip', 'mapLabelShadow'}) do
				addEventHandler('onClientGUIDoubleClick', player.gui[name],
					function()
						server.warpMe(elem)
						closeWindow(wnd)
					end,
					false
				)
			end
		end
		local x, y = getElementPosition(elem)
		x = math.floor((x + 3000) * g_MapSide / 6000) - 4
		y = math.floor((3000 - y) * g_MapSide / 6000) - 4
		guiSetPosition(player.gui.mapBlip, x, y, false)
		guiSetPosition(player.gui.mapLabelShadow, x + 14, y - 4, false)
		guiSetPosition(player.gui.mapLabel, x + 13, y - 5, false)
	end
end

addEventHandler('onClientPlayerChangeNick', g_Root,
	function(oldNick, newNick)
		if (not g_PlayerData) then return end
		local player = g_PlayerData[source]
		player.name = newNick
		if player.gui.mapLabel then
			guiSetText(player.gui.mapLabelShadow, newNick)
			guiSetText(player.gui.mapLabel, newNick)
			local labelWidth = guiLabelGetTextExtent(player.gui.mapLabelShadow)
			guiSetSize(player.gui.mapLabelShadow, labelWidth, 14, false)
			guiSetSize(player.gui.mapLabel, labelWidth, 14, false)
		end
	end
)

function closePositionWindow()
	removeEventHandler('onClientRender', g_Root, updatePlayerBlips)
end

wndSetPos = {
	'wnd',
	text = 'Set position',
	width = g_MapSide + 20,
	controls = {
		{'img', id='map', src='map.png', width=g_MapSide, height=g_MapSide, onclick=fillInPosition, ondoubleclick=setPosClick},
		{'txt', id='x', text='', width=0},
		{'txt', id='y', text='', width=0},
		{'txt', id='z', text='', width=0},
		{'btn', id='close', closeswindow=true},
	},
	oncreate = setPosInit,
	onclose = closePositionWindow
}


function setPlayerPosition(x, y, z)
	if getElementData(g_Me, "timer.setpos") == "cooldown" then
	errMsg('Please wait at least 30 seconds before seting your position again.')
	return
	end
	if getPedOccupiedVehicle(g_Me) then
	errMsg('Please leave the vehicle before changing your position.')
	return
	end
	if getElementAttachedTo(g_Me) then
	errMsg('Please unglue from another object before setting your position.')
	return
	end
	setElementData(g_Me, "timer.setpos", "cooldown")
	setTimer(setElementData, 30000, 1, g_Me, "timer.setpos", "normal")
	fadeCamera(false)
	setTimer(
		function()
		setCameraMatrix(x, y, 600)
		setElementPosition(localPlayer, x, y, 600)
		setElementInterior(localPlayer, 0)
		server.setElementInterior(localPlayer, 0)
		setCameraInterior(0)
		setCameraTarget(localPlayer)
		server.giveMeWeapon(46, 1)
		fadeCamera(true)
		end, 500, 1)
--[[local elem = g_Me
local distanceToGround = 0.4
	if isLineOfSightClear(x, y, 3000, x, y, -3000, true, true, true, true, true, false, false, nil) then	
	fadeCamera(false)
	setTimer(setCameraMatrix, 1000, 1, x, y, z)
	end
g_TeleportTimer = setTimer(
	function()
	local hit, groundX, groundY, groundZ = processLineOfSight(x, y, 3000, x, y, -3000, true, true, true, true, true, false, false, false, nil, true, true)
		if hit then
		local waterZ = getWaterLevel(x, y, z, true)
		z = (waterZ and math.max(groundZ, waterZ) or groundZ) + distanceToGround
		setElementPosition(elem, x, y, z)
		setElementInterior(elem, 0)
		server.setElementInterior(g_Me, 0)
		setCameraInterior(0)
		setCameraTarget(g_Me)
		fadeCamera(true)
		killTimer(g_TeleportTimer)
		g_TeleportTimer = nil
		end
	end, 500, 0)]]--
end

replace the code in fr_cilent.lua under setposition and if you want remove the error msg or let it be as i think u r copying groam style!!

 

Edited by Khadeer143
  • Like 1
Link to comment
  • 1 month later...

 

On 16.12.2017 at 07:03, Khadeer143 said:
  • function setPlayerPosition(x, y, z)
  • if getElementData(g_Me, "timer.setpos") == "cooldown" then
  • errMsg('Please wait at least 30 seconds before seting your position again.')

 

I click on the map once, I get warmed up, then I wait for 30 seconds, then I do not get warmed up, but I keep all 30 as well

Edited by carli
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...