Jump to content

[Solucionado] Crear seguimientos


aka Blue

Recommended Posts

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 :P

  
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

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

[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
[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

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:

wZCLYLk.png

Link to comment
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:

wZCLYLk.png

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

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

¿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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...