Jump to content

Taksi Mesleği / Taxi Work Script


Reappersz

Recommended Posts

Taksi Scripti Mta

-- MTA SA Script Reappersz
-- İyi oyunlar.

local workMarker = createMarker(-520.324, 2582.393, 52.414, "cylinder", 1.5, 252,0,255,50)--marker
createBlipAttachedTo(workMarker, 12, 2, 255,0,0, 255, 0, 1000) --blip

local rightWheeledCars = {
    [543] = true,    -- arac
    [558] = true,    -- arac
    [560] = true,    -- arac
    [562] = true,    -- arac
    [566] = true,    -- arac
    [587] = true,    -- arac
}

-- ==========     PANEL     ==========
local scx1920, scy1080 = guiGetScreenSize()
local scx1920, scy1080 = guiGetScreenSize()

local GUI = {
    window = {},
    label = {},
    button = {},
}
addEventHandler("onClientResourceStart", resourceRoot, function()
    -- BUTONLAR
    local screenW, screenH = guiGetScreenSize()
    GUI.window.start = guiCreateStaticImage((screenW - 1340)/0.5,(screenH - 768)/0.5,1250,900, "image/ui.png", false)

        GUI.button.startWork = guiCreateButton(680, 370, 275, 60, "İşe Başla", false, GUI.window.start)
    GUI.button.closeStart = guiCreateButton(680, 450, 275, 60, "İptal", false, GUI.window.start)
    
    -- BUTONLAR
    GUI.window.finish = guiCreateStaticImage((screenW - 1340)/0.5,(screenH - 768)/0.5,1250,900, "image/ui.png", false)

    GUI.button.finishWork = guiCreateButton(680, 370, 275, 60, "İşi Bitir", false, GUI.window.finish)
    GUI.button.closeFinish = guiCreateButton(680, 450, 275, 60, "İptal", false, GUI.window.finish)
    
    guiSetVisible(GUI.window.start, false)
    guiSetVisible(GUI.window.finish, false)
end)

 --- Kanka şimdi bu scripti sparrow türkçe yapmış felan hani sitesine bakmak istersen bir çok TÜRKÇE script mevcut : https://sparrow-mta.blogspot.com
 
addEventHandler("onClientMarkerHit", workMarker, function(player, matchingDimension)
    if (player == localPlayer) and (matchingDimension) then
        local vehicle = getPedOccupiedVehicle(localPlayer)
        if (not vehicle) or (getPedOccupiedVehicleSeat(localPlayer) == 0) then
            triggerServerEvent("openWorkWindow", resourceRoot)
        end
    end
end)

--[[
addEventHandler("onClientMarkerLeave", workMarker, function(player)
    if (player == localPlayer) then
        hideWorkGUI()
    end
end)
]]

local vehicleToUse = false
addEvent("showStartWorkGUI", true)
addEventHandler("showStartWorkGUI", resourceRoot, function(vehicle)
    if not isElementWithinMarker(localPlayer, workMarker) then return end
    if (vehicle) then
        if isResourceRunning("car_system") then
            guiSetText(GUI.label.vehicle, "Bu aracı kullana bilirsin ("..exports.car_system:getVehicleModName(vehicle)..").")
        else
            guiSetText(GUI.label.vehicle, "Bu araç taksi.")
        end
    else
        guiSetText(GUI.label.vehicle, "Kendi aracınız yok ise kiralık bir araç temin edilecek.")
    end
    vehicleToUse = vehicle
    guiSetVisible(GUI.window.start, true)
    showCursor(true)
end)

addEvent("showFinishWorkGUI",true)
addEventHandler("showFinishWorkGUI", resourceRoot, function(money)
    if not isElementWithinMarker(localPlayer, workMarker) then return end
    guiSetText(GUI.label.finishText, "\n\n\n\nTaksi şöförlüğü işini bitirmeden önce, bu parayı ödemelisin "..tostring(money).." $.")
    guiSetVisible(GUI.window.finish, true)
    showCursor(true)
end)

addEventHandler("onClientGUIClick", resourceRoot, function()
    if (source == GUI.button.closeStart) or (source == GUI.button.closeFinish) then
        hideWorkGUI()

    elseif (source == GUI.button.startWork) then
        if (getElementDimension(localPlayer) ~= 0) or (getElementInterior(localPlayer) ~= 0) then
            return
        end
        if isResourceRunning("car_driving_school") and (not exports.car_driving_school:doesPlayerHaveLic(localPlayer, "car")) then
            exports.car_driving_school:outputNoLicenseClient("car")
            return
        end
        triggerServerEvent("startTaxiJob", resourceRoot, vehicleToUse)
        hideWorkGUI()
        
    elseif (source == GUI.button.finishWork) then
        triggerServerEvent("finishTaxiJob", resourceRoot)
        hideWorkGUI()
        
    end
end)

function hideWorkGUI()
    guiSetVisible(GUI.window.start, false)
    guiSetVisible(GUI.window.finish, false)
    showCursor(false)
    vehicleToUse = false
end


-- ==========     Получение нового заказа и создание маркеров     ==========
addEventHandler("onClientPedDamage", resourceRoot, cancelEvent)

local currentPed, currentPoint
local sourceMarker, rotateMarker, jobBlip, destinationMarker

addEvent("createSourceMarker", true)
addEventHandler("createSourceMarker", resourceRoot, function(point, ped)
    removePedPickupElements()
    
    currentPoint = point
    currentPed = ped
    sourceMarker = createMarker(point[1], point[2], point[3], "cylinder", 2, 100,100,0,200)
    rotateMarker = createMarker(point[4], point[5], point[6], "cylinder", 30, 0,0,0,0)
    jobBlip = createBlipAttachedTo(sourceMarker, 56, 2, 255, 0, 0, 255, 32767, 65535)
    
    outputTaxiMessage("Yeni müşteri haritada sarı nokta ile gösterilir.")
end)

function removePedPickupElements()
    currentPed = false
    currentPoint = false
    if isElement(sourceMarker) then destroyElement(sourceMarker) end
    if isElement(rotateMarker) then destroyElement(rotateMarker) end
    if isElement(jobBlip) then destroyElement(jobBlip) end
    sourceMarker = false
    rotateMarker = false
    jobBlip = false
end


-- ==========     Обновление поворота педа при подъезде машины     ==========
addEventHandler("onClientMarkerHit", resourceRoot, function(player, matchingDimension)
    if (player == localPlayer) and (source == rotateMarker) and (matchingDimension) then
        addEventHandlerNoWarnings("onClientRender", root, updatePedRotation)
    end
end)
addEventHandler("onClientMarkerLeave", resourceRoot, function(player, matchingDimension)
    if (player == localPlayer) and (source == rotateMarker) and (matchingDimension) then
        removeEventHandlerNoWarnings("onClientRender", root, updatePedRotation)
    end
end)
function updatePedRotation()
    if not isElement(currentPed) then
        removeEventHandlerNoWarnings("onClientRender", root, updatePedRotation)
    end
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if (not vehicle) then return end
    local pedX, pedY, _ = getElementPosition(currentPed)
    local carX, carY, _ = getElementPosition(vehicle)
    setElementRotation(currentPed, 0, 0, getRotationFromVec2D(carX-pedX, carY-pedY), "default", true)
end

-- ==========     Ожидание остановки машины при заезде на маркер     ==========
local pickupStopTimer, dropStopTimer
addEventHandler("onClientMarkerHit", resourceRoot, function(player, matchingDimension)
    if (player == localPlayer) and (matchingDimension) and (source==sourceMarker or source==destinationMarker) then
        local _, _, mZ = getElementPosition(source)
        local _, _, pZ = getElementPosition(localPlayer)
        if (pZ-mZ < 5) and (pZ-mZ > -1) then
            if (source == sourceMarker) then
                if isTimer(pickupStopTimer) then killTimer(pickupStopTimer) end
                pickupStopTimer = setTimer(waitingForPickupStop, 100, 1)
            else
                if isTimer(dropStopTimer) then killTimer(dropStopTimer) end
                dropStopTimer = setTimer(waitingForDropStop, 100, 1)
            end
        end
    end
end)

addEventHandler("onClientMarkerLeave", resourceRoot, function(player, matchingDimension)
    if (player == localPlayer) and (matchingDimension) and (source==sourceMarker or source==destinationMarker) then
        if isTimer(pickupStopTimer) then killTimer(pickupStopTimer) end
        if isTimer(dropStopTimer) then killTimer(dropStopTimer) end
        if getPedOccupiedVehicle(localPlayer) then
            outputTaxiMessage("Aracı bölgede durdur.")
        end
    end
end)

function waitingForPickupStop()
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if (not vehicle) then return end
    local spX, spY, spZ = getElementVelocity(vehicle)
    local speed = math.floor(math.sqrt(spX^2 + spY^2 + spZ^2)*180)
    if (speed < 5) then
        antiDOSsend("pedPickup", 1000, "startPedPickup", resourceRoot)
    else
        pickupStopTimer = setTimer(waitingForPickupStop, 100, 1)
    end
end

-- ==========     Подход педа к машине и посадка     ==========
local pos = {
    [0] = {name = "door_lf_dummy"},
    [1] = {name = "door_rf_dummy"},
    [2] = {name = "door_lr_dummy"},
    [3] = {name = "door_rr_dummy"},
}
local animVehicle, animPed, animSeat
local doorTimer, resettingDoorTimer
addEvent("putPedInVehicle",true)
addEventHandler("putPedInVehicle", resourceRoot, function(vehicle, ped)
    if not isElement(vehicle) or not isElement(ped) then return end
    removeEventHandlerNoWarnings("onClientRender", root, updatePedRotation)
    removePedPickupElements()
    
    local pedX, pedY, _ = getElementPosition(ped)
    animVehicle, animPed = vehicle, ped
    for i = 0, #pos do
        local offX, offY = getDoorOffset(i, getElementRotation(vehicle))
        pos.x, pos.y, pos.z = getVehicleComponentPosition(vehicle, pos.name, "world")
        if (pos.x) then
            pos.x = pos.x + offX
            pos.y = pos.y + offY
        end
    end
    if pos[3].x and (getVehicleMaxPassengers(vehicle) > 1) then
        if getDistanceBetweenPoints2D(pedX, pedY, pos[3].x, pos[3].y) < getDistanceBetweenPoints2D(pedX, pedY, pos[2].x, pos[2].y) then
            animSeat = 3
        else
            animSeat = 2
        end
    else
        if (rightWheeledCars[getElementModel(vehicle)]) then
            animSeat = 0
        else
            animSeat = 1
        end
    end
    setPedAnalogControlState(ped, "forwards", 0.5)
    
    if isTimer(doorTimer) then killTimer(doorTimer) end
    doorTimer = setTimer(waitForDoor, 100, 1)
    if isTimer(resettingDoorTimer) then killTimer(resettingDoorTimer) end
    resettingDoorTimer = setTimer(resetWaitForDoor, 10000, 1)
end)

function waitForDoor()
    local pedX, pedY, pedZ = getElementPosition(animPed)
    local offX, offY = getDoorOffset(animSeat, getElementRotation(animVehicle))
    pos[animSeat].x, pos[animSeat].y, _ = getVehicleComponentPosition(animVehicle, pos[animSeat].name, "world")
    pos[animSeat].x = pos[animSeat].x + offX
    pos[animSeat].y = pos[animSeat].y + offY
    if (getDistanceBetweenPoints2D(pos[animSeat].x, pos[animSeat].y, pedX, pedY) > 0.5) then
        setElementRotation(animPed, 0, 0, getRotationFromVec2D(pos[animSeat].x-pedX, pos[animSeat].y-pedY), "default", true)
        doorTimer = setTimer(waitForDoor, 100, 1)
    else
        if isTimer(resettingDoorTimer) then killTimer(resettingDoorTimer) end
        setPedAnalogControlState(animPed, "forwards", 0)
        attachAndAnimate1()
    end
end

function resetWaitForDoor()
    if isTimer(doorTimer) then killTimer(doorTimer) end
    setPedAnalogControlState(animPed, "forwards", 0)
    attachAndAnimate1()
end
    
local animPedZShift
function attachAndAnimate1()
    local vehRotX, vehRotY, vehRotZ = getElementRotation(animVehicle, "default")
    local offX, offY = getDoorOffset(animSeat)
    local _, _, worldZ = getVehicleComponentPosition(animVehicle, pos[animSeat].name, "world")
    local _, _, pedZ = getElementPosition(animPed)
    animPedZShift = pedZ - worldZ
    pos[animSeat].x, pos[animSeat].y, pos[animSeat].z = getVehicleComponentPosition(animVehicle, pos[animSeat].name, "root")
    pos[animSeat].x = pos[animSeat].x + offX
    pos[animSeat].y = pos[animSeat].y + offY
    pos[animSeat].z = pos[animSeat].z + animPedZShift
    setElementCollidableWith(animPed, animVehicle, false)
    attachElements(animPed, animVehicle, pos[animSeat].x, pos[animSeat].y, pos[animSeat].z, vehRotX, vehRotY, vehRotZ)
    setElementRotation(animPed, vehRotX, vehRotY, vehRotZ)
    local animation = (animSeat%2 == 1) and "CAR_open_RHS" or "CAR_open_LHS"
    setPedAnimation(animPed, "ped", animation, -1, false, false, false, true)
    setTimer(function(v,s) setVehicleDoorOpenRatio(v, s, 1, 300) end, 500, 1, animVehicle, animSeat+2)
    setTimer(animate2, 1000, 1)
end

function animate2()
    local animation = (animSeat%2 == 1) and "CAR_getin_RHS" or "CAR_getin_LHS"
    setPedAnimation(animPed, "ped", animation, -1, false, false, false, true)
    setTimer(animate3, 1000, 1)
end

function animate3()
    local animation = (animSeat%2 == 1) and "CAR_closedoor_RHS" or "CAR_closedoor_LHS"
    setPedAnimation(animPed, "ped", animation, -1, false, false, false, true)
    setTimer(function(v,s) setVehicleDoorOpenRatio(v, s, 0, 200) end, 300, 1, animVehicle, animSeat+2)
    setTimer(function(event, rootElement, vehicle, seat)
        triggerServerEvent(event, rootElement, vehicle, seat)
    end, 500, 1, "pedPutIntoVehicle", resourceRoot, animVehicle, animSeat)
end


-- ==========     Создание точки назначения     ==========
addEvent("createDestinationMarker", true)
addEventHandler("createDestinationMarker", resourceRoot, function(point)
    removePedDropElements()
    
    currentPoint = point
    destinationMarker = createMarker(point[1], point[2], point[3], "cylinder", 2, 100,100,0,200)
    jobBlip = createBlipAttachedTo(destinationMarker, 56, 2, 255, 0, 0, 255, 32767, 65535)
end)

function removePedDropElements()
    currentPoint = false
    if isElement(destinationMarker) then destroyElement(destinationMarker) end
    if isElement(jobBlip) then destroyElement(jobBlip) end
    destinationMarker = false
    jobBlip = false
end

-- ==========     Ожидание остановки машины при заезде на маркер окончания     ==========
function waitingForDropStop()
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if (not vehicle) then return end
    local spX, spY, spZ = getElementVelocity(vehicle)
    local speed = math.floor(math.sqrt(spX^2 + spY^2 + spZ^2)*180)
    if (speed < 5) then
        antiDOSsend("pedDrop", 1000, "startPedDrop", resourceRoot)
    else
        dropStopTimer = setTimer(waitingForDropStop, 100, 1)
    end
end

-- ==========     Выход педа из машины и исчезновение     ==========
addEvent("extractPedFromVehicle",true)
addEventHandler("extractPedFromVehicle", resourceRoot, function(vehicle, ped, seat)
    removePedDropElements()
    if (seat == 1) and (rightWheeledCars[getElementModel(vehicle)]) then
        seat = 0
    end
    animVehicle, animPed, animSeat = vehicle, ped, seat
    local vehRotX, vehRotY, vehRotZ = getElementRotation(vehicle, "default")
    local offX, offY = getDoorOffset(seat)
    pos[seat].x, pos[seat].y, pos[seat].z = getVehicleComponentPosition(vehicle, pos[seat].name, "root")
    pos[seat].x = pos[seat].x + offX
    pos[seat].y = pos[seat].y + offY
    pos[seat].z = pos[seat].z + animPedZShift
    setElementCollidableWith(ped, vehicle, false)
    attachElements(ped, vehicle, pos[seat].x, pos[seat].y, pos[seat].z-10, vehRotX, vehRotY, vehRotZ)
    setElementRotation(ped, vehRotX, vehRotY, vehRotZ)
    local animation = (seat%2 == 1) and "CAR_getout_RHS" or "CAR_getout_LHS"
    setPedAnimation(ped, "ped", animation, -1, false, false, false, true)
    setTimer(function(v,s) setVehicleDoorOpenRatio(v, s, 1, 300) end, 150, 1, vehicle, seat+2)
    setTimer(function(p, v, x, y, z, rX, rY, rZ)
        attachElements(p, v, x, y, z, rX, rY, rZ)
    end, 200, 1, ped, vehicle, pos[seat].x, pos[seat].y, pos[seat].z, vehRotX, vehRotY, vehRotZ)
    setTimer(closeDoor, 900, 1)
end)

function closeDoor()
    local animation = (animSeat%2 == 1) and "CAR_close_RHS" or "CAR_close_LHS"
    setPedAnimation(animPed, "ped", animation, -1, false, false, false, true)
    setTimer(function(v,s) setVehicleDoorOpenRatio(v, s, 0, 300 ) end, 150, 1, animVehicle, animSeat+2)
    setTimer(startWalkOut, 900, 1)
end

local pedAlpha
function startWalkOut()
    local _, _, vehRotZ = getElementRotation(animVehicle, "default")
    detachElements(animPed)
    setPedAnimation(animPed)
    setElementCollidableWith(animPed, animVehicle, true)
    setPedAnalogControlState(animPed, "forwards", 0.5)
    setElementRotation(animPed, 0, 0, (animSeat%2 == 1) and (vehRotZ-90) or (vehRotZ+90), "default", true)
    pedAlpha = 255
    addEventHandler("onClientRender", root, vanishPed)
    triggerServerEvent("pedDropped", resourceRoot, animVehicle)
end

function vanishPed()
    pedAlpha = pedAlpha-1
    if isElement(animPed) then
        setElementAlpha(animPed, pedAlpha)
    end
    if (pedAlpha == 0) or (not isElement(animPed)) then
        removeEventHandler("onClientRender", root, vanishPed)
        triggerServerEvent("killVanishedPed", resourceRoot)
    end
end


-- ==========     Очистка всей инфы о работе     ==========
addEvent("deleteAllObjects", true)
addEventHandler("deleteAllObjects", resourceRoot, function()
    currentPed = false
    currentPoint = false
    if isElement(sourceMarker) then destroyElement(sourceMarker) end
    if isElement(rotateMarker) then destroyElement(rotateMarker) end
    if isElement(jobBlip) then destroyElement(jobBlip) end
    if isElement(destinationMarker) then destroyElement(destinationMarker) end
    if isTimer(pickupStopTimer) then killTimer(pickupStopTimer) end
    if isTimer(dropStopTimer) then killTimer(dropStopTimer) end
    animVehicle = false
    animPed = false
    animSeat = false
    if isTimer(doorTimer) then killTimer(doorTimer) end
    if isTimer(resettingDoorTimer) then killTimer(resettingDoorTimer) end
end)


-- ==========     Мелкие вспомогательные функции     ==========
-- Получить смещение педа относительно дверной петли
function getDoorOffset(seat, _, _, rotZ)
    local Xshift, Yshift = 0.5, -1.25
    if (tonumber(seat)%2 == 0) then
        Xshift = -Xshift
    end
    if (rotZ) then
        rotZ = math.rad(rotZ)
        return Xshift*math.cos(rotZ)-Yshift*math.sin(rotZ), Xshift*math.sin(rotZ)+Yshift*math.cos(rotZ)
    else
        return Xshift, Yshift
    end
end

-- Получить угол наклона вектора
function getRotationFromVec2D(x, y)
    local a = math.deg(math.acos(y/((x^2+y^2)^0.5)))
    return (x < 0) and (a) or (-a)
end

-- Сообщения от имени такси
function outputTaxiMessage(text)
    outputChatBox("[TAKSİ] #FFFFFF"..text, 227, 173, 0, true)
end

-- Убирание ошибки при добавлении/убирании эвента
function addEventHandlerNoWarnings(eventName, element, func)
    for _, attachedFunc in ipairs(getEventHandlers(eventName, element)) do
        if (attachedFunc == func) then
            return
        end
    end
    addEventHandler(eventName, element, func)
end
function removeEventHandlerNoWarnings(eventName, element, func)
    for _, attachedFunc in ipairs(getEventHandlers(eventName, element)) do
        if (attachedFunc == func) then
            removeEventHandler(eventName, element, func)
        end
    end
end

-- Проверка, что ресурс запущен
function isResourceRunning(resName)
    local res = getResourceFromName(resName)
    return (res) and (getResourceState(res) == "running")
end

--    ==========     Слоумод на кнопку/действие     ==========
local sendData = {}
local sendTimers = {}
function antiDOSsend(actionGroup, pause, ...)
    local args = {...}
    if isTimer(sendTimers[actionGroup]) then
        sendData[actionGroup] = args[1] and args
    else
        if (args[1]) then
            triggerServerEvent(...)
            sendData[actionGroup] = false
            sendTimers[actionGroup] = setTimer(slowSend, pause, 1, actionGroup)
        end
    end
end
function slowSend(actionGroup)
    if (sendData[actionGroup]) then
        triggerServerEvent(unpack(sendData[actionGroup]))
        sendData[actionGroup] = nil
    end
end

--[[
addEventHandler("onClientPreRender",root,
    function ()
    if animPed and isElement(animPed) then
        local block, animation = getPedAnimation(animPed)
        dxDrawText ( "CURRENT ANIMATION INFO...", 500, 300 )
        if not block then block = "N/A" end
        if not animation then animation = "N/A" end
        dxDrawText ( "Block = "..block.." Animation = "..animation, 500, 315 )
    end
end )
]]

--[[
addEventHandler ( "onClientRender", root,
function()
    if isPedInVehicle ( localPlayer ) and getPedOccupiedVehicle ( localPlayer ) then
        local veh = getPedOccupiedVehicle ( localPlayer )
        for v in pairs ( getVehicleComponents(veh) ) do
            local x,y,z = getVehicleComponentPosition ( veh, v, "world" )
            if x then
                local wx,wy,wz = getScreenFromWorldPosition ( x, y, z )
                if wx and wy then
                    dxDrawText ( v, wx -1, wy -1, 0 -1, 0 -1, tocolor(0,0,0), 1, "default-bold" )
                    dxDrawText ( v, wx +1, wy -1, 0 +1, 0 -1, tocolor(0,0,0), 1, "default-bold" )
                    dxDrawText ( v, wx -1, wy +1, 0 -1, 0 +1, tocolor(0,0,0), 1, "default-bold" )
                    dxDrawText ( v, wx +1, wy +1, 0 +1, 0 +1, tocolor(0,0,0), 1, "default-bold" )
                    dxDrawText ( v, wx, wy, 0, 0, tocolor(0,255,255), 1, "default-bold" )
                end
            end
        end
    end
end)
]]


 

Edited by Reappersz
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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