aka Blue Posted October 4, 2015 Share Posted October 4, 2015 (edited) Bueno, estoy creando un pequeño script para la comunidad y querría saber cómo puedo hacer que un ped siga al jugador. Edited October 14, 2015 by Guest Link to comment
Tomas Posted October 4, 2015 Share Posted October 4, 2015 setPedAnimation setPedRotation Link to comment
aka Blue Posted October 4, 2015 Author Share Posted October 4, 2015 Si pero quiero que siga al jugador, no que vaya caminando a su bola jaja. Link to comment
Tomas Posted October 4, 2015 Share Posted October 4, 2015 Si pero quiero que siga al jugador, no que vaya caminando a su bola jaja. Una parte de un script que se filtró en la web de mi server function followArrestor(player, cop) if (not isElement(player) or not isElement(cop)) then return end if (isPedInVehicle(player) or not isPlayerArrested(player)) then return end local cX, cY = getElementPosition(cop) local pX, pY = getElementPosition(player) local copangle = (360 - math.deg(math.atan2((cX - pX), (cY - pY)))) % 360 setPedRotation(player, copangle) setCameraTarget(player, player) setElementInterior(player, getElementInterior(cop)) setElementDimension(player, getElementDimension(cop)) local dist = getDistanceBetweenPoints2D(cX, cY, pX, pY) if (dist > 16) then -- Warp local x, y, z = getElementPosition(cop) setElementPosition(player, x, y, z) setTimer(followArrestor, 500, 1, player, cop) elseif (dist > 12) then -- Sprint setControlState(player, "sprint", true) setControlState(player, "walk", false) setControlState(player, "forwards", true) setTimer(followArrestor, 500, 1, player, cop) elseif (dist > 6) then -- Jog setControlState(player, "sprint", false) setControlState(player, "walk", false) setControlState(player, "forwards", true) setTimer(followArrestor, 500, 1, player, cop) elseif (dist > 1.5) then -- Walk setControlState(player, "sprint", false) setControlState(player, "walk", true) setControlState(player, "forwards", true) setTimer(followArrestor, 500, 1, player, cop) elseif (dist <= 1.5) then -- Stop setControlState(player, "sprint", false) setControlState(player, "walk", false) setControlState(player, "forwards", false) setTimer(followArrestor, 500, 1, player, cop) end end Link to comment
aka Blue Posted October 4, 2015 Author Share Posted October 4, 2015 Muchas gracias, ahora lo pruebo Link to comment
aka Blue Posted October 4, 2015 Author Share Posted October 4, 2015 Me tira esto todo el rato. [21:58:17] WARNING: peds\peds.lua:56: Bad argument @ 'setControlState' [Expected player at argument 1, got ped] [21:58:17] WARNING: peds\peds.lua:54: Bad argument @ 'setControlState' [Expected player at argument 1, got ped] [21:58:17] WARNING: peds\peds.lua:55: Bad argument @ 'setControlState' [Expected player at argument 1, got ped] [21:58:17] WARNING: peds\peds.lua:56: Bad argument @ 'setControlState' [Expected player at argument 1, got ped] PD: Me sigue y tal pero sin animación, al cabo de unos segundos, se tpea a mi. Link to comment
Tomas Posted October 4, 2015 Share Posted October 4, 2015 Fue creado para funcionar con jugadores, utiliza setPedControlState Link to comment
aka Blue Posted October 4, 2015 Author Share Posted October 4, 2015 No me fije en eso, lo siento jaja. PD: Voy a probar. Link to comment
aka Blue Posted October 4, 2015 Author Share Posted October 4, 2015 [00:27:02] ERROR: peds\peds.lua:75: attempt to call global 'setPedControlState' (a nil value) elseif (dist <= 1.5) then setPedControlState(ped, "sprint", false) setPedControlState(ped, "walk", false) setPedControlState(ped, "forwards", false) setTimer(followArrestor, 500, 1, ped, cop) end Link to comment
Tomas Posted October 4, 2015 Share Posted October 4, 2015 [00:27:02] ERROR: peds\peds.lua:75: attempt to call global 'setPedControlState' (a nil value) elseif (dist <= 1.5) then setPedControlState(ped, "sprint", false) setPedControlState(ped, "walk", false) setPedControlState(ped, "forwards", false) setTimer(followArrestor, 500, 1, ped, cop) end Client-side.. Link to comment
Centauro Posted October 5, 2015 Share Posted October 5, 2015 Perdón me meto acá.. y para hacer que el jugador lo deje de seguir, que se podria hacer?, solo por curiosidad. Link to comment
Tomas Posted October 5, 2015 Share Posted October 5, 2015 Perdón me meto acá.. y para hacer que el jugador lo deje de seguir, que se podria hacer?, solo por curiosidad. Le agregas un check en la función para ver si debe seguir, y cuando quieras que no siga, se lo quitas Link to comment
aka Blue Posted October 5, 2015 Author Share Posted October 5, 2015 Es que no el jugador sigue al ped, sino, el ped sigue al jugador. Esa es la función que quiero hacer para el script. PD: ¿Hay algo para cancelar una función? Link to comment
aka Blue Posted October 5, 2015 Author Share Posted October 5, 2015 Me tira errores rarísimos: function seguir(ped, cop) if (isPedInVehicle(cop)) then local vehiculo = getPedOccupiedVehicle(cop) warpPedIntoVehicle(ped, vehiculo, 1) end local cX, cY = getElementPosition(cop) local pX, pY = getElementPosition(ped) local copangle = (360 - math.deg(math.atan2((cX - pX), (cY - pY)))) % 360 setPedRotation(ped, copangle) setCameraTarget(ped, ped) setElementInterior(ped, getElementInterior(cop)) setElementDimension(ped, getElementDimension(cop)) local dist = getDistanceBetweenPoints2D(cX, cY, pX, pY) if (dist > 16) then local x, y, z = getElementPosition(cop) setElementPosition(ped, x, y, z) setTimer(followArrestor, 500, 1, ped, cop) elseif (dist > 12) then setPedControlState(ped, "sprint", true) setPedControlState(ped, "walk", false) setPedControlState(ped, "forwards", true) setTimer(followArrestor, 500, 1, ped, cop) elseif (dist > 6) then setPedControlState(ped, "sprint", false) setPedControlState(ped, "walk", false) setPedControlState(ped, "forwards", true) setTimer(followArrestor, 500, 1, ped, cop) elseif (dist > 1.5) then setPedControlState(ped, "sprint", false) setPedControlState(ped, "walk", true) setPedControlState(ped, "forwards", true) setTimer(followArrestor, 500, 1, ped, cop) elseif (dist <= 1.5) then setPedControlState(ped, "sprint", false) setPedControlState(ped, "walk", false) setPedControlState(ped, "forwards", false) setTimer(followArrestor, 500, 1, ped, cop) end end ERRORES: Link to comment
Tomas Posted October 5, 2015 Share Posted October 5, 2015 Me tira errores rarísimos: function seguir(ped, cop) if (isPedInVehicle(cop)) then local vehiculo = getPedOccupiedVehicle(cop) warpPedIntoVehicle(ped, vehiculo, 1) end local cX, cY = getElementPosition(cop) local pX, pY = getElementPosition(ped) local copangle = (360 - math.deg(math.atan2((cX - pX), (cY - pY)))) % 360 setPedRotation(ped, copangle) setCameraTarget(ped, ped) setElementInterior(ped, getElementInterior(cop)) setElementDimension(ped, getElementDimension(cop)) local dist = getDistanceBetweenPoints2D(cX, cY, pX, pY) if (dist > 16) then local x, y, z = getElementPosition(cop) setElementPosition(ped, x, y, z) setTimer(followArrestor, 500, 1, ped, cop) elseif (dist > 12) then setPedControlState(ped, "sprint", true) setPedControlState(ped, "walk", false) setPedControlState(ped, "forwards", true) setTimer(followArrestor, 500, 1, ped, cop) elseif (dist > 6) then setPedControlState(ped, "sprint", false) setPedControlState(ped, "walk", false) setPedControlState(ped, "forwards", true) setTimer(followArrestor, 500, 1, ped, cop) elseif (dist > 1.5) then setPedControlState(ped, "sprint", false) setPedControlState(ped, "walk", true) setPedControlState(ped, "forwards", true) setTimer(followArrestor, 500, 1, ped, cop) elseif (dist <= 1.5) then setPedControlState(ped, "sprint", false) setPedControlState(ped, "walk", false) setPedControlState(ped, "forwards", false) setTimer(followArrestor, 500, 1, ped, cop) end end ERRORES: El error que te salta es que te faltan argumentos en la función 'createPed', si editaste el nombre de la función también debes editar la función de los timers Link to comment
aka Blue Posted October 9, 2015 Author Share Posted October 9, 2015 Perdón por responder tarde. Éste es el código antes que ejecuta la función. peds = {} function crear ( thePlayer ) if peds [ thePlayer ] == nil then peds [ thePlayer ] = 0 end if peds [ thePlayer] < 1 and peds [ thePlayer ] == 0 then local x, y, z = getElementPosition ( thePlayer ) outputChatBox ( "* Has creado tu ped satisfactoriamente.", thePlayer, 0, 255, 120 ) local mascota = createPed ( 299, x, y, z ) seguir(mascota, thePlayer) peds [ thePlayer ] = 1 addCommandHandler("delped", function ( thePlayer, mascota ) if mascota then deleteElement(mascota) outputChatBox("* Has borrado el Ped correctamente.", thePlayer, 0, 255, 120) peds [ thePlayer ] = 0 else outputChatBox ( "* No tienes peds creados.", thePlayer, 255, 0, 0 ) end end) else outputChatBox ( "No puedes crear más peds.", thePlayer, 0, 255, 120) end end addCommandHandler("myped", crear) Link to comment
Tomas Posted October 9, 2015 Share Posted October 9, 2015 La única manera que tienes de hacer caminar un ped en server-side es usando animaciones. Link to comment
aka Blue Posted October 9, 2015 Author Share Posted October 9, 2015 La cosa es que todo el script es client side ya que la función que me diste es cliente. Link to comment
Platin Posted October 9, 2015 Share Posted October 9, 2015 ¿Y slothbot? Y no, la unica forma de hacer que un bot se mueva no es con anims. Los zombies funcionan con pedControlState en client, por eso los teleports, porque uno ve que salto para un lado pero el otro para otro, o que hizo tal cosa y el otro tal otra. Es lo complicado del asunto. EDIT: Recién leí server-side, mala mía. Link to comment
Tomas Posted October 9, 2015 Share Posted October 9, 2015 La cosa es que todo el script es client side ya que la función que me diste es cliente. Nope.. tu la adaptaste, está funcionando en el lado del servidor está el repo en github, buscalo como gti-rpg Link to comment
Enargy, Posted October 14, 2015 Share Posted October 14, 2015 Nose si ya esta solucionado esto pero da igual, Edité el código de Tomas. --[[ function myPed( thePlayer ) local x, y, z = getElementPosition( thePlayer ); y = y - 5 ped = createPed( 0, x, y, z ) if ped then follow( ped, thePlayer ) end end addCommandHandler( "myped", myPed ) ]] function follow(element, player) if (not isElement(element) or not isElement(player)) then return end if (isPedInVehicle(element)) then return end local cX, cY = getElementPosition(player) local pX, pY = getElementPosition(element) local copangle = (360 - math.deg(math.atan2((cX - pX), (cY - pY)))) % 360 setPedRotation(element, copangle) setElementInterior(element, getElementInterior(player)) setElementDimension(element, getElementDimension(player)) local dist = getDistanceBetweenPoints2D(cX, cY, pX, pY) if (dist > 16) then -- Warp local x, y, z = getElementPosition(player) setElementPosition(element, x, y, z) setTimer(follow, 200, 1, element, player) elseif (dist > 6) then -- Sprint setPedAnimation( element, "PED", "sprint_civi" ) setTimer(follow, 200, 1, element, player) elseif (dist > 4) then -- Jog setPedAnimation( element, "PED", "JOG_maleA" ) setTimer(follow, 200, 1, element, player) elseif (dist > 1.5) then -- Walk setPedAnimation( element, "PED", "WALK_civi" ) setTimer(follow, 200, 1, element, player) elseif (dist <= 2) then -- Stop setPedAnimation( element, "PED", "IDLE_stance" ) setTimer(follow, 200, 1, element, player) end end Link to comment
aka Blue Posted October 14, 2015 Author Share Posted October 14, 2015 Si, ya funciona, gracias @Enargy y @Tomas Link to comment
Recommended Posts