Jump to content

Job Help


Killer...

Recommended Posts

Hello everyone. I need some help whit this script. Because i want to do when you say /ruta and you're in a vehicle to start the job, showing to you the checkpoints.

Server Part

local vehicles = get( "vehicles" )-- load the civilian vehicles that'll automatically trigger the delivery mission if being entered 
local max_earnings = tonumber( get( "earnings" ) ) or 125 
local delay = tonumber( get( "delay" ) ) or 25 
  
  
  
  
  
-- 
  
local p = { } 
  
local function advanceRoute( player, earnings ) 
    if p[ player ] and p[ player ].route and p[ player ].checkpoint then 
        local cp = p[ player ].checkpoint + 1 
        local c = p[ player ].route[ cp ] 
        local n = p[ player ].route[ cp + 1 ] 
        if c then 
            if p[ player ].route[ p[ player ].checkpoint ] then 
                if p[ player ].route[ p[ player ].checkpoint ].stop and earnings and earnings > 0 then 
                    exports.players:giveMoney( player, earnings ) 
                end 
                 
                if p[ player ].route[ p[ player ].checkpoint ].hint then 
                    triggerClientEvent( player, "gui:hint", player, "Ve a buscar provisiones a la fábrica abandonada.", p[ player ].route[ p[ player ].checkpoint ].hint ) 
                end 
            end 
             
            if not n then 
                -- last checkpoint 
                triggerClientEvent( player, getResourceName( resource ) .. ":set", player, c.x, c.y, c.z, c.stop and true ) 
            else 
                triggerClientEvent( player, getResourceName( resource ) .. ":set", player, c.x, c.y, c.z, c.stop and true, n.x, n.y, n.z, n.stop and true ) 
            end 
        else 
            if earnings then 
                exports.players:giveMoney( player, earnings * 3 ) 
            end 
            triggerClientEvent( player, getResourceName( resource ) .. ":set", player ) 
            p[ player ] = nil 
            return false 
        end 
        p[ player ].checkpoint = cp 
        return true 
    end 
end 
  
local function newRoute( player ) 
    p[ player ].vehicleOnResourceStart = nil 
    local route = math.random( #routes ) 
    p[ player ].route = routes[ route ] 
    p[ player ].checkpoint = 0 
     
    advanceRoute( player ) 
end 
  
  
  
  
addEventHandler( "onVehicleEnter", root, 
    function ruta( player, seat ) 
        if seat == 0 and isPedInVehicle ( player ) then 
            if not p[ player ] then 
                p[ player ] = { } 
            end 
             
            if not p[ player ].route then 
                newRoute( player ) 
            else 
                triggerClientEvent( player, getResourceName( resource ) .. ":show", player ) 
            end 
        end 
    end 
) 
addCommandHandler ("ruta", ruta) 
-- 
  
addEventHandler( "onResourceStart", resourceRoot, 
    function( ) 
        if not routes or routes == 0 then 
            cancelEvent( ) 
            return 
        end 
         
        -- 
         
        setElementData( resourceRoot, "delay", delay ) 
         
        -- 
         
        for key, value in ipairs( getElementsByType( "player" ) ) do 
            local vehicle = getPedOccupiedVehicle( value ) 
            if vehicle and getPedOccupiedVehicleSeat( value ) == 0 then 
                p[ value ] = { vehicleOnResourceStart = vehicle } 
            end 
        end 
         
        setTimer( 
            function( ) 
                for key, value in pairs( p ) do 
                    p[ key ].vehicleOnResourceStart = nil 
                end 
            end, 10000, 1 
        ) 
    end 
) 
  
addEvent( getResourceName( resource ) .. ":ready", true ) 
addEventHandler( getResourceName( resource ) .. ":ready", root, 
    function( ) 
        if source == client then 
            if p[ source ] and getPedOccupiedVehicle( source ) == p[ source ].vehicleOnResourceStart and getPedOccupiedVehicleSeat( source ) == 0 then 
                newRoute( source ) 
            end 
        end 
    end 
) 
  
-- 
  
addEvent( getResourceName( resource ) .. ":complete", true ) 
addEventHandler( getResourceName( resource ) .. ":complete", root, 
    function( ) 
        if source == client then 
            local vehicle = getPedOccupiedVehicle( source ) 
            if p[ source ] and p[ source ].route and getPedOccupiedVehicleSeat( source ) == 0 then 
                -- distance check 
                if not p[ source ].route[ p[ source ].checkpoint ].stop or getDistanceBetweenPoints2D( p[ source ].route[ p[ source ].checkpoint ].x, p[ source ].route[ p[ source ].checkpoint ].y, getElementPosition( vehicle ) ) < 5 then 
                    local health = math.min( 1000, getElementHealth( vehicle ) ) 
                    if health > 350 then 
                         
                        -- get a checkpoint 
                        advanceRoute( source, earnings ) 
                         
                    end 
                end 
            end 
        end 
    end 
) 
  
addEventHandler( "onCharacterLogout", root, 
    function( ) 
        if p[ source ] and p[ source ].route then 
            triggerClientEvent( source, getResourceName( resource ) .. ":set", source ) 
        end 
        p[ source ] = nil 
    end 
) 
  
addEventHandler( "onPlayerQuit", root, 
    function( ) 
        p[ source ] = nil 
    end 
) 
  
-- 
  
  
-- 
  
function introduce( player ) 
    triggerClientEvent( player, getResourceName( resource ) .. ":introduce", player ) 
end 
  

Client Part

local localPlayer = getLocalPlayer( ) 
local position = nil 
local marker = nil 
local blip = nil 
local blip2 = nil 
local wait = false 
local screenX, screenY = guiGetScreenSize( ) 
  
function drawWaitingText( ) 
    -- check if we still need to wait 
    local text = "Espera..." 
    local vehicle = getPedOccupiedVehicle( localPlayer ) 
    if vehicle then 
        if wait and wait ~= 0 then 
            local diff = wait - getTickCount( ) 
            if diff >= 0 then 
                text = ( "Espera %.1f segundos para subir los paquetes al vehiculo!" ):format( diff / 1000 ) 
            else 
                triggerServerEvent( getResourceName( resource ) .. ":complete", localPlayer ) 
                wait = 0 
            end 
         
        -- draw the text 
        dxDrawText( text, 4, 4, screenX, screenY, tocolor( 0, 0, 0, 255 ), 1, "pricedown", "center", "center" ) 
        dxDrawText( text, 0, 0, screenX, screenY, tocolor( 255, 255, 255, 255 ), 1, "pricedown", "center", "center" ) 
    end 
end 
  
-- 
  
local function hide( ) 
    if isElement( blip ) then 
        destroyElement( blip ) 
    end 
    blip = nil 
     
    if isElement( blip2 ) then 
        destroyElement( blip2 ) 
    end 
    blip2 = nil 
     
    if isElement( marker ) then 
        destroyElement( marker ) 
    end 
    marker = nil 
     
    if wait then 
        wait = false 
        removeEventHandler( "onClientRender", root, drawWaitingText ) 
    end 
end 
  
local function show( ) 
    hide( ) 
     
    if position then 
        -- in lack of a more detailed close-location (aka we use the entrance), use large markers 
        marker = createMarker( position.x, position.y, position.z, "checkpoint", 3, position.stop and 0 or 255, 255, 0, 63 ) 
        if marker then 
            blip = createBlipAttachedTo( marker, 0, 2, position.stop and 0 or 255, 255, 0, 255 ) 
        end 
         
        if position.nx and position.ny and position.nz then 
            blip2 = createBlip( position.nx, position.ny, position.nz, 0, 1, position.nstop and 0 or 255, 255, 0, 255 ) 
        end 
    end 
end 
  
addEvent( getResourceName( resource ) .. ":show", true ) 
addEventHandler( getResourceName( resource ) .. ":show", localPlayer, show ) 
  
addEvent( getResourceName( resource ) .. ":set", true ) 
addEventHandler( getResourceName( resource ) .. ":set", localPlayer, 
    function( x, y, z, stop, nx, ny, nz, nstop ) 
        if x and y and z then 
            position = { x = x, y = y, z = z, stop = stop, nx = nx, ny = ny, nz = nz, nstop = nstop } 
            show( ) 
        else 
            position = nil 
            hide( ) 
        end 
    end 
) 
  
addEventHandler( "onClientPlayerVehicleExit", localPlayer, hide ) 
  
addEventHandler( "onClientResourceStart", resourceRoot, 
    function( ) 
        triggerServerEvent( getResourceName( resource ) .. ":ready", localPlayer ) 
    end 
) 
  
addEventHandler( "onClientMarkerHit", resourceRoot, 
    function( element, matching ) 
        if matching and element == localPlayer then 
            if position.stop then 
                if not wait then 
                    wait = getTickCount( ) + getElementData( resourceRoot, "delay" ) * 1000 
                    addEventHandler( "onClientRender", root, drawWaitingText ) 
                end 
            else 
                triggerServerEvent( getResourceName( resource ) .. ":complete", localPlayer ) 
            end 
        end 
    end 
) 
  
addEventHandler( "onClientMarkerLeave", resourceRoot, 
    function( element, matching ) 
        if matching and element == localPlayer then 
            wait = false 
            removeEventHandler( "onClientRender", root, drawWaitingText ) 
            exports.gui:hint( "Cargador", "Para recibir paga, ve a por paquetes en la vieja fábrica. Se recomienda no ir solo!", 3 ) 
        end 
    end 
) 

Please help me, i do this because i'm doing an Zombie Roleplay, trying to combine MTA Paradise whit a ZombieGamemode. And for now it's going good. If you want to participate in this Spanish project, contact me.

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