Jump to content

Problem With Ped


Recommended Posts

  • 1 month later...

You may use a glue system
Try mine

 

local glues = {}

function glue (plr, cmd)

	local veh = getPedContactElement(plr)
	if (getElementData(plr, "glue") == false) then
		-- Boolean again >_<
		if isElement(veh) and (getElementType(veh) == "vehicle") then
			local px, py, pz = getElementPosition(plr)
			local vx, vy, vz = getElementPosition(veh)
			local sx = px - vx
			local sy = py - vy
			local sz = pz - vz
			
			local rotpX = 0
			local rotpY = 0
			local rotpZ = getElementRotation(plr)
			
			local rotvX,rotvY,rotvZ = getVehicleRotation(veh)
			
			local t = math.rad(rotvX)
			local p = math.rad(rotvY)
			local f = math.rad(rotvZ)
			
			local ct = math.cos(t)
			local st = math.sin(t)
			local cp = math.cos(p)
			local sp = math.sin(p)
			local cf = math.cos(f)
			local sf = math.sin(f)
			
			local z = ct*cp*sz + (sf*st*cp + cf*sp)*sx + (-cf*st*cp + sf*sp)*sy
			local x = -ct*sp*sz + (-sf*st*sp + cf*cp)*sx + (cf*st*sp + sf*cp)*sy
			local y = st*sz - sf*ct*sx + cf*ct*sy
			
			local rotX = rotpX - rotvX
			local rotY = rotpY - rotvY
			local rotZ = rotpZ - rotvZ
			attachElements(plr, veh, x,y,z, rotX, rotY, rotZ)
			setElementData(plr, "glue", true)
			glues[plr] = veh
		end
	else
		if (isElement(glues[plr])) then
			detachElements(plr, glues[plr])
			setElementData(plr, "glue", false)
		end
	end
end
addCommandHandler("glue", glue)

 

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