Jump to content

JR10

Retired Staff
  • Posts

    2,947
  • Joined

  • Last visited

Everything posted by JR10

  1. No problem. 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. that's how to set the peds rotation to the players rotation.
  2. You think that someone will script for you for free? Unless you pay no one will script. Start to learn: https://wiki.multitheftauto.com/wiki/Main_Page
  3. 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.
  4. 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.
  5. No problem. I'm still pissed off that i couldn't fix it. I will give it a look tommorow though.
  6. 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.
  7. 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
  8. 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
  9. 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.
  10. 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.
  11. 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
  12. function teleport (player) local x,y,z = getElementPosition(marker2) setTimer(setElementPosition, 1000, 1, player, x, y, z) end addEventHandler("onMarkerHit", markerofcol, teleport )
  13. 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.
  14. 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
  15. 1 Month later exactly people gave up
  16. 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
  17. 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
  18. local lastPed = #peds - 1 attachElements ( peds[newPed], peds[lastPed], npX, npY + 0.1, npZ) Try this or 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
  19. Is it the line with the attachElements or another one.
  20. JR10

    Superman

    OMG, dude, you just want the damn code don't you There is a bindKey and addCommandHandler bindKey("jump", "down", Superman.onJump) addCommandHandler("superman", Superman.cmdSuperman) check if the player is admin and trigger them ITS NOT THAT HARD.
  21. You must use it from another script like this: addEventHandler('onResourceStart', getResourceFromName('markerResource'), ...) and add onResourceStart and stop create a marker that sets your team when you hit it, And add a handler to onResourceStop that changes the handler to a function that will spawn you a vehicle.
  22. attachElements ( peds[newPed], peds[#peds - 1], npX, npY + 0.1, npZ) Try it.
  23. Only one way you add a handler to onResourceStart to create a marker that sets your team when you hit it, And add a handler to onResourceStop that creates a marker in the same place and give you a car when you hit it.
  24. JR10

    Superman

    There is a bindKey and addCommandHandler check if a player is admin and trigger them
×
×
  • Create New...