JR10 Posted June 16, 2011 Share Posted June 16, 2011 No and try this: function appelHit ( thePlayer ) if getElementType(thePlayer) ~= "player" then return end local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local lastPed = #peds local newPed = #peds +1 peds[newPed] = createPed ( 0, 0, 0, 0, 0 ) local npX, npY, npZ = getElementPosition (peds[newPed]) if(detection) then -- outputChatBox( "You found the apple and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) setElementPosition ( peds[newPed], npX, npY + 0.1, npZ ) attachElements ( peds[newPed], newPed1, npX, npY + 0.1, npZ) triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) if(peds[newPed]) then outputChatBox ( "The new PED was created!") else outputChatBox ( "Failed to create the new PED!") end end end Link to comment
unknooooown Posted June 16, 2011 Author Share Posted June 16, 2011 I feel so bad about having you try so many things for me! LOL! Hope its OK. I just want to learn and gain skills I have tested the script above, and I don't get any errors with it, but they still spawn ontop of eachother local snakeAppels = { {-720,961,11}, {-705,968,11}, {-698,954,11}, {-711,960,11}, {-722,950,11}, {-720,977,11}, {-687,965,11}, {-678,949,11}, {-664,951,11}, {-711,942,11} } peds = {} -- cjSnake Marker & ColShape controller (Should only fire ONCE) -- function cjFirstSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelFirstHit ) end -- cjSnake Marker & ColShape controller (Should fire after the first PED is attached to CJ(thePlayer)) -- function cjSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelHit ) end addCommandHandler("cj-snake", cjFirstSnake) -- Should only fire ONCE! -- function appelFirstHit ( thePlayer ) local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local pX, pY, pZ = getElementPosition( thePlayer ) local prX, prY, prZ = getElementRotation( thePlayer ) newPed1 = createPed ( 0, pX + 1, pY, pZ, prZ ) if(detection) then outputChatBox( "You found the APPLE and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) attachElements ( newPed1, thePlayer, 0, -0.2, 0) triggerEvent ( "loopCjSnake", getRootElement(), "" ) end end -- Should fire after the first PED is attached to CJ(thePlayer) -- function appelHit ( thePlayer ) if getElementType(thePlayer) ~= "player" then return end local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local lastPed = #peds local newPed = #peds +1 peds[newPed] = createPed ( 0, 0, 0, 0, 0 ) local npX, npY, npZ = getElementPosition (peds[newPed]) if(detection) then -- outputChatBox( "You found the apple and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) setElementPosition ( peds[newPed], npX, npY + 0.1, npZ ) attachElements ( peds[newPed], newPed1, npX, npY + 0.1, npZ) triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) if(peds[newPed]) then outputChatBox ( "The new PED was created!") else outputChatBox ( "Failed to create the new PED!") end end end addEvent ( "loopCjSnake", true ) addEventHandler ( "loopCjSnake", getRootElement(), cjSnake ) Link to comment
JR10 Posted June 16, 2011 Share Posted June 16, 2011 with the script above they will attach to the first ped here is how you really attach them right function getPlayerBackPos(player) -- use this to spawn the ped behind player when its perfect use attachRotationAdjusted local rotz = getPedRotation(player) local x, y, z = getElementPosition(player) x = x + ( math.cos ( math.rad ( rotz-90 ) ) * 2)-- keep lowering "2" untill you find it perfect for you y = y + ( math.sin ( math.rad ( rotz-90 ) ) * 2)-- keep lowering "2" untill you find it perfect for you return x, y, z end -- and when they spawn perfect use this function function attachRotationAdjusted ( from, to ) -- Note: Objects being attached to ('to') should have at least two of their rotations set to zero -- Objects being attached ('from') should have at least one of their rotations set to zero -- Otherwise it will look all funny 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 ) -- Degress to radians local DEG2RAD = (math.pi * 2) / 360 rx = rx * DEG2RAD ry = ry * DEG2RAD rz = rz * DEG2RAD -- unrotate each axis 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 i think this will work i tested it before just keep lowering the 2 in getPlayerBackPosition function untill its perfect for you and use the attachRotationAdjusted function Link to comment
unknooooown Posted June 16, 2011 Author Share Posted June 16, 2011 Thank you. I will have a look at the script above later tonight. At first glance it doesn't make any sense to me what so ever, but I will do my best to figure out how to add it to my script. Thanks. Link to comment
JR10 Posted June 16, 2011 Share Posted June 16, 2011 The script are just functions that will help you getPlayerBackPos(player) - will calculate the players behind x, y, z you can use it to create the ped behind another one attachRotationAdjusted(object, to) - will attach objects the way they are so you don't have to adjust offsets here: x = x + ( math.cos ( math.rad ( rotz-90 ) ) * 2)-- keep lowering "2" untill you find it perfect for you y = y + ( math.sin ( math.rad ( rotz-90 ) ) * 2)-- keep lowering "2" untill you in getPlayerBackPos function you can lower the "2" to get a lower space behind him like 1.1 or 1.05 or 1.01 for really close or even lower you try and decide Link to comment
unknooooown Posted June 16, 2011 Author Share Posted June 16, 2011 @JR10 - Hehe. That part I understand ^^ I just dont see how I can impliment it into my exsisting script. I mean, where should I add it and where/what should I call it for? I am very very very confused about all this. Link to comment
JR10 Posted June 16, 2011 Share Posted June 16, 2011 local snakeAppels = { {-720,961,11}, {-705,968,11}, {-698,954,11}, {-711,960,11}, {-722,950,11}, {-720,977,11}, {-687,965,11}, {-678,949,11}, {-664,951,11}, {-711,942,11} } peds = {} -- cjSnake Marker & ColShape controller (Should only fire ONCE) -- function cjFirstSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelFirstHit ) end -- cjSnake Marker & ColShape controller (Should fire after the first PED is attached to CJ(thePlayer)) -- function cjSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelHit ) end addCommandHandler("cj-snake", cjFirstSnake) -- Should only fire ONCE! -- function appelFirstHit ( thePlayer ) local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local pX, pY, pZ = getElementPosition( thePlayer ) local prX, prY, prZ = getElementRotation( thePlayer ) newPed1 = createPed ( 0, pX + 1, pY, pZ, prZ ) if(detection) then outputChatBox( "You found the APPLE and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) attachElements ( newPed1, thePlayer, 0, -0.2, 0) triggerEvent ( "loopCjSnake", getRootElement(), "" ) end end -- Should fire after the first PED is attached to CJ(thePlayer) -- function appelHit ( thePlayer ) if getElementType(thePlayer) ~= "player" then return end local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local newPed = #peds +1 local lastPed = #peds local x, y, z = getPlayerBackPos(peds[#peds]) local rotz = getPedRotation(peds[#peds]) peds[newPed] = createPed ( 0, x, y, z, rotz ) if(detection) then -- outputChatBox( "You found the apple and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) setElementPosition ( peds[newPed], npX, npY + 0.1, npZ ) attachRotationAdjusted( peds[newPed], peds[lastPed]) triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) if(peds[newPed]) then outputChatBox ( "The new PED was created!") else outputChatBox ( "Failed to create the new PED!") end end end addEvent ( "loopCjSnake", true ) addEventHandler ( "loopCjSnake", getRootElement(), cjSnake ) function getPlayerBackPos(player) -- use this to spawn the ped behind player when its perfect use attachRotationAdjusted local rotz = getPedRotation(player) local x, y, z = getElementPosition(player) x = x + ( math.cos ( math.rad ( rotz-90 ) ) * 1.02) y = y + ( math.sin ( math.rad ( rotz-90 ) ) * 1.02) return x, y, z end -- and when they spawn perfect use this function function attachRotationAdjusted ( from, to ) -- Note: Objects being attached to ('to') should have at least two of their rotations set to zero -- Objects being attached ('from') should have at least one of their rotations set to zero -- Otherwise it will look all funny 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 ) -- Degress to radians local DEG2RAD = (math.pi * 2) / 360 rx = rx * DEG2RAD ry = ry * DEG2RAD rz = rz * DEG2RAD -- unrotate each axis 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 I hope this works. Link to comment
unknooooown Posted June 16, 2011 Author Share Posted June 16, 2011 @JR10 - I am soooo confused! When I look at the new added part of the script, I don't see it linked to my other functions in any way at all, other than it being in the same script. When I run it I get Warnings on line 82 & 83, and an error on line 84. I understand what the new part of the script does, I just dont have any idea how to make it work with the exsisting script. Link to comment
JR10 Posted June 16, 2011 Share Posted June 16, 2011 The whole problem is with the ped table because the function works i have tested it before here where it is: local x, y, z = getPlayerBackPos(peds[#peds]) local rotz = getPedRotation(peds[#peds]) peds[newPed] = createPed ( 0, x, y, z, rotz ) attachRotationAdjusted( peds[newPed], peds[lastPed]) the table thing is just a mess Link to comment
unknooooown Posted June 16, 2011 Author Share Posted June 16, 2011 Think this is too complicated for me at this point. Think I have to make some less advanced scripts before I understand any of this. Link to comment
JR10 Posted June 16, 2011 Share Posted June 16, 2011 local snakeAppels = { {-720,961,11}, {-705,968,11}, {-698,954,11}, {-711,960,11}, {-722,950,11}, {-720,977,11}, {-687,965,11}, {-678,949,11}, {-664,951,11}, {-711,942,11} } -- cjSnake Marker & ColShape controller (Should only fire ONCE) -- function cjFirstSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelFirstHit ) end -- cjSnake Marker & ColShape controller (Should fire after the first PED is attached to CJ(thePlayer)) -- function cjSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelHit ) end addCommandHandler("cj-snake", cjFirstSnake) -- Should only fire ONCE! -- function appelFirstHit ( thePlayer ) local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local pX, pY, pZ = getElementPosition( thePlayer ) local prX, prY, prZ = getElementRotation( thePlayer ) lastPed = createPed ( 0, pX + 1, pY, pZ, prZ ) if(detection) then outputChatBox( "You found the APPLE and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) attachElements ( newPed1, thePlayer, 0, -0.2, 0) triggerEvent ( "loopCjSnake", getRootElement(), "" ) end end -- Should fire after the first PED is attached to CJ(thePlayer) -- function appelHit ( thePlayer ) if getElementType(thePlayer) ~= "player" then return end local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local lastPed2 = lastPed local x, y, z = getPlayerBackPos(lastPed2) local rotz = getPedRotation(lastPed2) lastPed = createPed ( 0, x, y, z, rotz ) if(detection) then -- outputChatBox( "You found the apple and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) setElementPosition ( peds[newPed], npX, npY + 0.1, npZ ) attachRotationAdjusted( peds[newPed], peds[lastPed]) triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) if(peds[newPed]) then outputChatBox ( "The new PED was created!") else outputChatBox ( "Failed to create the new PED!") end end end addEvent ( "loopCjSnake", true ) addEventHandler ( "loopCjSnake", getRootElement(), cjSnake ) function getPlayerBackPos(player) -- use this to spawn the ped behind player when its perfect use attachRotationAdjusted local rotz = getPedRotation(player) local x, y, z = getElementPosition(player) x = x + ( math.cos ( math.rad ( rotz-90 ) ) * 1.02) y = y + ( math.sin ( math.rad ( rotz-90 ) ) * 1.02) return x, y, z end -- and when they spawn perfect use this function function attachRotationAdjusted ( from, to ) -- Note: Objects being attached to ('to') should have at least two of their rotations set to zero -- Objects being attached ('from') should have at least one of their rotations set to zero -- Otherwise it will look all funny 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 ) -- Degress to radians local DEG2RAD = (math.pi * 2) / 360 rx = rx * DEG2RAD ry = ry * DEG2RAD rz = rz * DEG2RAD -- unrotate each axis 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 Just try this last one and tells me what happens and post any errors warnings and show me the line of the error/warning. Link to comment
unknooooown Posted June 16, 2011 Author Share Posted June 16, 2011 When I hit the first marker a new ped is created, but not attached to the player. When I hit the second marker, another ped is created behind the first ped, but still not connected to the the player. I get these errors: WARNING: blahblah\cjSnake.lua:46: Bad argument @ 'attachElements' ERROR: blahblah\cjSnake.lua:66: attempt to index global 'peds' (a nil value) Link to comment
JR10 Posted June 16, 2011 Share Posted June 16, 2011 local snakeAppels = { {-720,961,11}, {-705,968,11}, {-698,954,11}, {-711,960,11}, {-722,950,11}, {-720,977,11}, {-687,965,11}, {-678,949,11}, {-664,951,11}, {-711,942,11} } -- cjSnake Marker & ColShape controller (Should only fire ONCE) -- function cjFirstSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelFirstHit ) end -- cjSnake Marker & ColShape controller (Should fire after the first PED is attached to CJ(thePlayer)) -- function cjSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelHit ) end addCommandHandler("cj-snake", cjFirstSnake) -- Should only fire ONCE! -- function appelFirstHit ( thePlayer ) local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local pX, pY, pZ = getElementPosition( thePlayer ) local prX, prY, prZ = getElementRotation( thePlayer ) lastPed = createPed ( 0, pX + 1, pY, pZ, prZ ) if(detection) then outputChatBox( "You found the APPLE and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) attachElements ( newPed1, thePlayer, 0, -0.2, 0) triggerEvent ( "loopCjSnake", getRootElement(), "" ) end end -- Should fire after the first PED is attached to CJ(thePlayer) -- function appelHit ( thePlayer ) if getElementType(thePlayer) ~= "player" then return end local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local lastPed2 = lastPed local x, y, z = getPlayerBackPos(lastPed2) local rotz = getPedRotation(lastPed2) lastPed = createPed ( 0, x, y, z, rotz ) if(detection) then -- outputChatBox( "You found the apple and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) attachRotationAdjusted( lastPed, lastPed2) triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) if(lastPed) then outputChatBox ( "The new PED was created!") else outputChatBox ( "Failed to create the new PED!") end end end addEvent ( "loopCjSnake", true ) addEventHandler ( "loopCjSnake", getRootElement(), cjSnake ) function getPlayerBackPos(player) -- use this to spawn the ped behind player when its perfect use attachRotationAdjusted local rotz = getPedRotation(player) local x, y, z = getElementPosition(player) x = x + ( math.cos ( math.rad ( rotz-90 ) ) * 1.02) y = y + ( math.sin ( math.rad ( rotz-90 ) ) * 1.02) return x, y, z end -- and when they spawn perfect use this function function attachRotationAdjusted ( from, to ) -- Note: Objects being attached to ('to') should have at least two of their rotations set to zero -- Objects being attached ('from') should have at least one of their rotations set to zero -- Otherwise it will look all funny 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 ) -- Degress to radians local DEG2RAD = (math.pi * 2) / 360 rx = rx * DEG2RAD ry = ry * DEG2RAD rz = rz * DEG2RAD -- unrotate each axis 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 Try that. Link to comment
unknooooown Posted June 16, 2011 Author Share Posted June 16, 2011 Now the new peds are lined up on a row just the way I want (With more space than needed, but I know how to change that), but they are still not attached to the player. WARNING: blahblah\cjSnake.lua:46: Bad argument @ 'attachElements' Link to comment
JR10 Posted June 16, 2011 Share Posted June 16, 2011 local snakeAppels = { {-720,961,11}, {-705,968,11}, {-698,954,11}, {-711,960,11}, {-722,950,11}, {-720,977,11}, {-687,965,11}, {-678,949,11}, {-664,951,11}, {-711,942,11} } -- cjSnake Marker & ColShape controller (Should only fire ONCE) -- function cjFirstSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelFirstHit ) end -- cjSnake Marker & ColShape controller (Should fire after the first PED is attached to CJ(thePlayer)) -- function cjSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelHit ) end addCommandHandler("cj-snake", cjFirstSnake) -- Should only fire ONCE! -- function appelFirstHit ( thePlayer ) local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local pX, pY, pZ = getElementPosition( thePlayer ) local prX, prY, prZ = getElementRotation( thePlayer ) lastPed = createPed ( 0, pX + 1, pY, pZ, prZ ) if(detection) then outputChatBox( "You found the APPLE and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) attachElements ( newPed1, thePlayer, 0, -0.2, 0) triggerEvent ( "loopCjSnake", getRootElement(), "" ) end end -- Should fire after the first PED is attached to CJ(thePlayer) -- function appelHit ( thePlayer ) if getElementType(thePlayer) ~= "player" then return end local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local lastPed2 = lastPed local x, y, z = getPlayerBackPos(lastPed2) local rotz = getPedRotation(lastPed2) lastPed = createPed ( 0, x, y, z, rotz ) if(detection) then -- outputChatBox( "You found the apple and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) attachRotationAdjusted( lastPed, lastPed2) triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) if(lastPed) then outputChatBox ( "The new PED was created!") else outputChatBox ( "Failed to create the new PED!") end end end addEvent ( "loopCjSnake", true ) addEventHandler ( "loopCjSnake", getRootElement(), cjSnake ) function getPlayerBackPos(player) -- use this to spawn the ped behind player when its perfect use attachRotationAdjusted local rotz = getPedRotation(player) local x, y, z = getElementPosition(player) x = x + ( math.cos ( math.rad ( rotz-90 ) ) * 1.008) y = y + ( math.sin ( math.rad ( rotz-90 ) ) * 1.008) return x, y, z end -- and when they spawn perfect use this function function attachRotationAdjusted ( from, to ) -- Note: Objects being attached to ('to') should have at least two of their rotations set to zero -- Objects being attached ('from') should have at least one of their rotations set to zero -- Otherwise it will look all funny 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 ) -- Degress to radians local DEG2RAD = (math.pi * 2) / 360 rx = rx * DEG2RAD ry = ry * DEG2RAD rz = rz * DEG2RAD -- unrotate each axis 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 Try this Link to comment
unknooooown Posted June 16, 2011 Author Share Posted June 16, 2011 Same warning. Don't you think it has something to do with line 39 and 59 being the same and not local? Link to comment
JR10 Posted June 16, 2011 Share Posted June 16, 2011 (edited) My idea was the last ped store it in lastPed and lastPed2 was meant to get the lastPed before the new one is created damn this is pissing me off local snakeAppels = { {-720,961,11}, {-705,968,11}, {-698,954,11}, {-711,960,11}, {-722,950,11}, {-720,977,11}, {-687,965,11}, {-678,949,11}, {-664,951,11}, {-711,942,11} } -- cjSnake Marker & ColShape controller (Should only fire ONCE) -- function cjFirstSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelFirstHit ) end -- cjSnake Marker & ColShape controller (Should fire after the first PED is attached to CJ(thePlayer)) -- function cjSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelHit ) end addCommandHandler("cj-snake", cjFirstSnake) -- Should only fire ONCE! -- function appelFirstHit ( thePlayer ) local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local pX, pY, pZ = getElementPosition( thePlayer ) local prX, prY, prZ = getElementRotation( thePlayer ) lastPed = createPed ( 0, pX + 1, pY, pZ, prZ ) if(detection) then outputChatBox( "You found the APPLE and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) attachElements ( newPed1, thePlayer, 0, -0.2, 0) triggerEvent ( "loopCjSnake", getRootElement(), "" ) end end -- Should fire after the first PED is attached to CJ(thePlayer) -- function appelHit ( thePlayer ) if getElementType(thePlayer) ~= "player" then return end local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) lastPed2 = lastPed local x, y, z = getPlayerBackPos(lastPed2) local rotz = getPedRotation(lastPed2) lastPed = createPed ( 0, x, y, z, rotz ) if(detection) then -- outputChatBox( "You found the apple and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) attachRotationAdjusted( lastPed, lastPed2) triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) if(lastPed) then outputChatBox ( "The new PED was created!") else outputChatBox ( "Failed to create the new PED!") end end end addEvent ( "loopCjSnake", true ) addEventHandler ( "loopCjSnake", getRootElement(), cjSnake ) function getPlayerBackPos(player) -- use this to spawn the ped behind player when its perfect use attachRotationAdjusted local rotz = getPedRotation(player) local x, y, z = getElementPosition(player) x = x + ( math.cos ( math.rad ( rotz-90 ) ) * 1.008) y = y + ( math.sin ( math.rad ( rotz-90 ) ) * 1.008) return x, y, z end -- and when they spawn perfect use this function function attachRotationAdjusted ( from, to ) -- Note: Objects being attached to ('to') should have at least two of their rotations set to zero -- Objects being attached ('from') should have at least one of their rotations set to zero -- Otherwise it will look all funny 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 ) -- Degress to radians local DEG2RAD = (math.pi * 2) / 360 rx = rx * DEG2RAD ry = ry * DEG2RAD rz = rz * DEG2RAD -- unrotate each axis 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 maybe Edited June 16, 2011 by Guest Link to comment
JR10 Posted June 16, 2011 Share Posted June 16, 2011 After this i honestly don't know, i spent my day trying to figure out this and maybe it's a stupid mistake we can't see right now. Sorry. Link to comment
unknooooown Posted June 16, 2011 Author Share Posted June 16, 2011 Hmm. Think I give the script a break for now and return to it at some other time, so see if I can figure out whats wrong. Thank you so much for helping me all day with the script. I really appreciate it a lot! I hope it didnt ruin your entire day! LOL Link to comment
JR10 Posted June 16, 2011 Share Posted June 16, 2011 No problem. I'm still pissed off that i couldn't fix it. I will give it a look tommorow though. Link to comment
unknooooown Posted June 16, 2011 Author Share Posted June 16, 2011 No problem.I'm still pissed off that i couldn't fix it. I will give it a look tommorow though. Sounds great It has to be possible to make the script work. I have always heard that nothing is impossible when it comes to scripting Link to comment
JR10 Posted June 16, 2011 Share Posted June 16, 2011 No problem.I'm still pissed off that i couldn't fix it. I will give it a look tommorow though. Sounds great It has to be possible to make the script work. I have always heard that nothing is impossible when it comes to scripting Almost nothing is impossible when it comes to scripting Because you can't make cj come out of the screen and say hi Jacob can you? but again yes your script should work and tonight or tommorow i will test it myself. Link to comment
Castillo Posted June 16, 2011 Share Posted June 16, 2011 local snakeAppels = { {-720,961,11}, {-705,968,11}, {-698,954,11}, {-711,960,11}, {-722,950,11}, {-720,977,11}, {-687,965,11}, {-678,949,11}, {-664,951,11}, {-711,942,11} } -- cjSnake Marker & ColShape controller (Should only fire ONCE) -- function cjFirstSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelFirstHit ) end -- cjSnake Marker & ColShape controller (Should fire after the first PED is attached to CJ(thePlayer)) -- function cjSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelHit ) end addCommandHandler("cj-snake", cjFirstSnake) -- Should only fire ONCE! -- function appelFirstHit ( thePlayer ) local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local pX, pY, pZ = getElementPosition( thePlayer ) local prX, prY, prZ = getElementRotation( thePlayer ) lastPed = createPed ( 0, pX + 1, pY, pZ, prZ ) if(detection) then outputChatBox( "You found the APPLE and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) attachElements ( lastPed, thePlayer, 0, -0.2, 0) triggerEvent ( "loopCjSnake", getRootElement(), "" ) end end -- Should fire after the first PED is attached to CJ(thePlayer) -- function appelHit ( thePlayer ) if getElementType(thePlayer) ~= "player" then return end local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) lastPed2 = lastPed local x, y, z = getPlayerBackPos(lastPed2) local rotz = getPedRotation(lastPed2) lastPed = createPed ( 0, x, y, z, rotz ) if(detection) then -- outputChatBox( "You found the apple and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) attachRotationAdjusted( lastPed, lastPed2) triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) if(lastPed) then outputChatBox ( "The new PED was created!") else outputChatBox ( "Failed to create the new PED!") end end end addEvent ( "loopCjSnake", true ) addEventHandler ( "loopCjSnake", getRootElement(), cjSnake ) function getPlayerBackPos(player) -- use this to spawn the ped behind player when its perfect use attachRotationAdjusted local rotz = getPedRotation(player) local x, y, z = getElementPosition(player) x = x + ( math.cos ( math.rad ( rotz-90 ) ) * 1.008) y = y + ( math.sin ( math.rad ( rotz-90 ) ) * 1.008) return x, y, z end -- and when they spawn perfect use this function function attachRotationAdjusted ( from, to ) -- Note: Objects being attached to ('to') should have at least two of their rotations set to zero -- Objects being attached ('from') should have at least one of their rotations set to zero -- Otherwise it will look all funny 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 ) -- Degress to radians local DEG2RAD = (math.pi * 2) / 360 rx = rx * DEG2RAD ry = ry * DEG2RAD rz = rz * DEG2RAD -- unrotate each axis 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 Your problem: You did: attachElements ( newPed1, thePlayer, 0, -0.2, 0) but it was lastPed not newPed1, I tested ant it works. Link to comment
JR10 Posted June 16, 2011 Share Posted June 16, 2011 Whew! i did it!, but, there is 1 problem that the peds are not rotated as the player so the payer might be lookin > and the peds looking ^ local snakeAppels = { {-720,961,11}, {-705,968,11}, {-698,954,11}, {-711,960,11}, {-722,950,11}, {-720,977,11}, {-687,965,11}, {-678,949,11}, {-664,951,11}, {-711,942,11} } -- cjSnake Marker & ColShape controller (Should only fire ONCE) -- function cjFirstSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelFirstHit ) end -- cjSnake Marker & ColShape controller (Should fire after the first PED is attached to CJ(thePlayer)) -- function cjSnake (thePlayer, command) local rX, rY, rZ = unpack(snakeAppels[math.random(#snakeAppels)]) theAppleMarker = createMarker ( rX, rY, rZ, "cylinder", 1.5, 255, 255, 0, 170 ) theAppleMarkerCol = createColCircle ( rX, rY, 3.0) appleBlip = createBlipAttachedTo ( theAppleMarker, 56 ) addEventHandler ( "onColShapeHit", theAppleMarkerCol, appelHit ) end addCommandHandler("cj-snake", cjFirstSnake) -- Should only fire ONCE! -- function appelFirstHit ( thePlayer ) local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local pX, pY, pZ = getPlayerBackPos(thePlayer) local prX, prY, prZ = getElementRotation( thePlayer ) lastPed = createPed ( 0, pX, pY, pZ, prZ ) if(detection) then outputChatBox( "You found the APPLE and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) attachRotationAdjusted ( lastPed, thePlayer) triggerEvent ( "loopCjSnake", getRootElement(), "" ) end end -- Should fire after the first PED is attached to CJ(thePlayer) -- function appelHit ( thePlayer ) if getElementType(thePlayer) ~= "player" then return end local detection = isElementWithinColShape ( thePlayer, theAppleMarkerCol ) local randomMoney = math.random(50,500) local lastPed2 = lastPed local x, y, z = getPlayerBackPos(lastPed2) local rotz = getPedRotation(lastPed2) lastPed = createPed ( 0, x, y, z, rotz ) if(detection) then -- outputChatBox( "You found the apple and got $" ..randomMoney ) givePlayerMoney ( thePlayer, randomMoney ) destroyElement ( theAppleMarkerCol ) destroyElement ( theAppleMarker ) destroyElement ( appleBlip ) attachRotationAdjusted( lastPed, lastPed2) triggerEvent ( "loopCjSnake", getRootElement(), thePlayer ) if(lastPed) then outputChatBox ( "The new PED was created!") else outputChatBox ( "Failed to create the new PED!") end end end addEvent ( "loopCjSnake", true ) addEventHandler ( "loopCjSnake", getRootElement(), cjSnake ) function getPlayerBackPos(player) -- use this to spawn the ped behind player when its perfect use attachRotationAdjusted local rotz = getPedRotation(player) local x, y, z = getElementPosition(player) x = x + ( math.cos ( math.rad ( rotz-90 ) ) * 0.5) y = y + ( math.sin ( math.rad ( rotz-90 ) ) * 0.5) return x, y, z end -- and when they spawn perfect use this function function attachRotationAdjusted ( from, to ) -- Note: Objects being attached to ('to') should have at least two of their rotations set to zero -- Objects being attached ('from') should have at least one of their rotations set to zero -- Otherwise it will look all funny 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 ) -- Degress to radians local DEG2RAD = (math.pi * 2) / 360 rx = rx * DEG2RAD ry = ry * DEG2RAD rz = rz * DEG2RAD -- unrotate each axis 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 This will work i tested it. you should use table.insert to add the peds to a table And set a timer that will set the peds rotation to the player rotation shouldnt be hard. 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