Help make character walk in lua

Tuzas

Active member
Joined
Nov 1, 2019
Messages
145
Reaction score
80
Location
null
JavaScript:
function go_to_point(point, is_sprint)
    local dist
    repeat
        set_camera_direction(point)
        wait(0)
        setGameKeyState(1, -255)
        local mx, my, mz = getCharCoordinates(playerPed)
        if is_sprint then
            setGameKeyState(16, 255)
        end
        dist = getDistanceBetweenCoords2d(point.x, point.y, mx, my)
        if dist < 0.6 then
            pressEnterKey()
        end
    until dist < 0.6
end
function set_camera_direction(point)
    local c_pos_x, c_pos_y, c_pos_z = getActiveCameraCoordinates()
    local vect = {
        x = point.x - c_pos_x,
        y = point.y - c_pos_y
    }
    local ax = math.atan2(vect.y, -vect.x)
    setCameraPositionUnfixed(0.0, -ax)
end

Usage example:

JavaScript:
function sampev.onCreatePickup(id, model, type, pos)

    if model == 19605 then

        lua_thread.create(go_to_point, {
            x = pos.x,
            y = pos.y
        })
    end
end
 
Top