GerardWay Posted July 24, 2011 Share Posted July 24, 2011 i am not sure how to use attachelement and where to use it i want to attach objects to different vehicles can anyone help me plz? Link to comment
bandi94 Posted July 24, 2011 Share Posted July 24, 2011 addEventHandler("onVehicleEnter", getRootElement(), function(thePlayer, seat, jacked) currentElement = createObject(3790, 0.0, 0.0, 0.0)--- the object what to attach 3790 is the object id attachElements(currentElement, source, 1.08, 0.98, 0.28, 0.0, 0.0, 267.994) --- attach to the vehicle currentElement is the object, source is the car and the numbers are the distance form the car x,y,z and rotation x,y,z end) server side Link to comment
BabY Posted July 28, 2011 Share Posted July 28, 2011 Better way! : function attach (Player, Command, ID, rotX, rotY, rotZ) local car = getPedOccupiedVehicle(Player) local posX, posY, posZ = getElementPosition(car) local object = createObject (ID, 0, 0, 0, 0, 0, 0) attachElements (object, car, posX, posY, posZ, rotX, rotY, rotZ) else outputChatBox ("* Error!", Player, 255, 0, 0) end addCommandHandler("attach", attach) addCommandHandler("removeattach", function(Player, command) destroyElement(getElementsAttachedTo(getPedOccupiedVehicle(Player))) end You should enter the ID of the object you want to attach to your car, then enter rotation X, Y and Z Example : /attach 12450 0 0 90 To remove attached elements, type /removeattach Hope it works for you! I put some effort on that! Link to comment
JR10 Posted July 28, 2011 Share Posted July 28, 2011 attachElements (object, car, posX, posY, posZ, rotX, rotY, rotZ) xPosOffset: The x offset, if you want the elements to be a certain distance from one another (default 0).yPosOffset: The y offset (default 0). zPosOffset: The z offset (default 0). xRotOffset: The x rotation offset (default 0). yRotOffset: The y rotation offset (default 0). zRotOffset: The z rotation offset (default 0). and else outputChatBox ("* Error!", Player, 255, 0, 0) end else @ a functions? Where is the effort really i can't see any effort in a 11 line code. I use this for attaching: function attachRotationAdjusted ( from, to ) local frPosX, frPosY, frPosZ = getElementPosition( from ) local frRotX, frRotY, frRotZ = getElementRotation( from ) local toPosX, toPosY, toPosZ = getElementPosition( to ) local toRotX, toRotY, toRotZ = getElementRotation( to ) local offsetPosX = frPosX - toPosX local offsetPosY = frPosY - toPosY local offsetPosZ = frPosZ - toPosZ local offsetRotX = frRotX - toRotX local offsetRotY = frRotY - toRotY local offsetRotZ = frRotZ - toRotZ offsetPosX, offsetPosY, offsetPosZ = applyInverseRotation ( offsetPosX, offsetPosY, offsetPosZ, toRotX, toRotY, toRotZ ) attachElements( from, to, offsetPosX, offsetPosY, offsetPosZ, offsetRotX, offsetRotY, offsetRotZ ) end function applyInverseRotation ( x,y,z, rx,ry,rz ) local DEG2RAD = (math.pi * 2) / 360 rx = rx * DEG2RAD ry = ry * DEG2RAD rz = rz * DEG2RAD local tempY = y y = math.cos ( rx ) * tempY + math.sin ( rx ) * z z = -math.sin ( rx ) * tempY + math.cos ( rx ) * z local tempX = x x = math.cos ( ry ) * tempX - math.sin ( ry ) * z z = math.sin ( ry ) * tempX + math.cos ( ry ) * z tempX = x x = math.cos ( rz ) * tempX + math.sin ( rz ) * y y = -math.sin ( rz ) * tempX + math.cos ( rz ) * y return x, y, z end use it like: attachRotationAdjusted(object, vehicle) Example: addCommandHandler("attach", function(player) local x, y, z = getElementPosition(player) local veh = createVehicle(411, x, y+3, z) local obj = createObject(2985, x, y+3, z+1) attachRotationAdjusted(obj, veh) This will create an infernus and attach a minigun base object to the top of it. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now