Jump to content

Calculating world offsets and rotation offsets with for rotating, and attaching veh components to peds for repair script


Pirulax

Recommended Posts

  • Discord Moderators

Okey, so im currently working on a repair script for my server, until this point everything worked, but now i need to calculate some offsets(world offset, and rotation offset too), and i have no idea how to do it.So, the basic idea is to hold every demounted component like this.Heres the script i made.

--CLIENT SIDE

local r = {
	["door_lf_dummy"] = {90,0,-90},
	["door_rf_dummy"] = {90,0,-90},	
	["door_lr_dummy"] = {90,0,-90},	
	["door_rr_dummy"] = {90,0,-90},
}



addEvent("addVehComponentToPlayer",true)
function funkzson(veh,comp,player)

	setTimer(function() 
		local rotx,roty,rotz = getElementRotation(player)
		setElementRotation(veh,rotx,rotx,rotz)
	
		for k in pairs(getVehicleComponents(veh)) do
			if not (k==comp) then
				setVehicleComponentVisible(veh,k,false)
			end
		end

		local cX,cY,cZ = getVehicleComponentPosition(veh,comp,"world")
		local vX,vY,vZ = getElementPosition(veh)
		local offsetX,offsetY,offsetZ = (vX-cX),(vY-cY),(cZ-vZ)

		exports.bone_attach:attachElementToBone(veh,player,2,0,-0.4,-0.65,r[comp][1],r[comp][2],r[comp][3])
		setPedAnimation(player,"carry","crry_prtial",0,false,false,false)

	end,50,1)

end
addEventHandler("addVehComponentToPlayer",getLocalPlayer(),funkzson)



--SERVER SIDE

addCommandHandler("setcompstate",function(source,_,comp)
	local x,y,z = getElementPosition(source)
	local veh = createVehicle(440,x,y,z,rotx,roty,rotz)
	setElementCollisionsEnabled(veh,false)
	setVehicleDamageProof(veh,true)
	setElementData(veh,"onlyfixveh",true)
	triggerClientEvent("addVehComponentToPlayer",root,veh,comp,source)
end)

Ignore that i attached the server side triggerClientEvent to a command, i made it like this only for testing purposes.

 

btw, maybe i will post the full script as a community script.  

 

Edited by Pirulax
Link to comment
  • Discord Moderators

Just messed up the boneAttach.

Okey, i will solve rotations somehow, but i still need to calculate X,Y,Z positions, and thats my biggest problem, by the way, if you want we can talk in hungarian,but only in PM.((Nem akarom hogy áthelyezzék a magyar Szekcióba.))

@NeXuS™

 

Edited by Pirulax
Link to comment
  • Discord Moderators

I think, that there is some way to calculate it, image it: the getElementPosition(veh) returns the center of the veh, getVehicleComponentPosition(veh,part,"world") returns  where to component is, then in theoretically you should be able to calculate them within the script.

@NeXuS™

World positions solved.

local cX,cY,cZ = getVehicleComponentPosition(veh,comp,"world")
local pX,pY,pZ = getElementPosition(player)
local offsetX,offsetY,offsetZ = (pX-cX),(pY-cY),(pZ-cZ)

I'll solve rotations somehow.

 

Edit: didnt solved.. forgot to use the calculated values in the attach function.

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