GerardWay Posted July 24, 2011 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?
bandi94 Posted July 24, 2011 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 Ingame Name : |DGT|Puma DGT Clan Server 24/7 Owner/Scripter MultiGameMode in progress :
BabY Posted July 28, 2011 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! Thanks dzek for bearing my stupid questions as a noob. You helped me become a better programmer. Now I understand how important it is to help those who SUCK at programming.
JR10 Posted July 28, 2011 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. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
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