Jump to content

[HELP] Trucker Job


Imposter

Recommended Posts

This is a modification of rrtrucker, i am trying to change it so when you get to the ped, it spawns a trailer, and when trailer is attached to you, it gives you a destination, but i am having problems at function givePoint(), it gives an error saying no ponts specified, can somebody help?

serverside:

  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
    function()
        truckSkins = { [206]=true, [133]=true }
        trucks = { [515]=true, [514]=true, [403]=true }
        playerClients = { }
        playerCols = { }
        playerBlips = { }
        jobClients = { }
        playerJobLocation = {  };
        local XMLTruckerLocations = xmlLoadFile ( "XML\\trucker_locations.xml" )
        if ( not XMLTruckerLocations ) then
            local XMLTruckerLocations = xmlCreateFile ( "XML\\trucker_locations.xml", "trucker_locations" )
            xmlSaveFile ( XMLTruckerLocations )
        end
       
        local trucker_locations = xmlNodeGetChildren(XMLTruckerLocations)
        truckerLocations = {}
        for i,node in ipairs(trucker_locations) do
            truckerLocations[i] = {}
            truckerLocations[i]["x"] = xmlNodeGetAttribute ( node, "posX" )
            truckerLocations[i]["y"] = xmlNodeGetAttribute ( node, "posY" )
            truckerLocations[i]["z"] = xmlNodeGetAttribute ( node, "posZ" )
            truckerLocations[i]["r"] = xmlNodeGetAttribute ( node, "rot" )
        end
        xmlUnloadFile ( XMLTruckerLocations )
    end
)
 
function enterVehicle ( thePlayer, seat, jacked )
    if ( trucks[getElementModel ( source )] ) and ( not truckSkins[getElementModel ( thePlayer )] ) and (seat == 0) then
        cancelEvent()
        outputChatBox ( "Only truckers drivers can drive Transports!", thePlayer )
    end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle )
 
function startJob ( playerSource )
    local x, y, z = getElementPosition ( playerSource )
        if not playerClients[ playerSource ] then
            local numLocations = #truckerLocations
            if ( numLocations > 0 ) then
                repeatCount = 0;
                repeat
                    local pickupPoint = math.random(numLocations)
                    pickupx = truckerLocations[pickupPoint]["x"]
                    pickupy = truckerLocations[pickupPoint]["y"]
                    pickupz = truckerLocations[pickupPoint]["z"]
                    pickupr = truckerLocations[pickupPoint]["r"]
                    local jobDistance = getDistanceBetweenPoints3D ( x, y, z, pickupx, pickupy, pickupz );
                    repeatCount = repeatCount+1
                until jobDistance > 100 and jobDistance < 800 + repeatCount*100
               
                repeat
                    local id = math.random( 10, 270 )
                    ped = createPed( tonumber( id ), pickupx, pickupy, pickupz )
                    setPedRotation ( ped, pickupr )
                until ped
               
                playerClients[ playerSource ] = {  };
                table.insert( playerClients[ playerSource ], ped );
                table.insert( jobClients, ped );
               
                local pedBlip = createBlipAttachedTo ( ped, 41, 2, 255, 0, 0, 255, 1, 99999.0, playerSource)
                playerBlips[ playerSource ] = {  };
                table.insert( playerBlips[ playerSource ], pedBlip );
               
                pedMarker = createMarker ( pickupx, pickupy, 0, cylinder, 6.5, 255, 255, 0, 150, playerSource)
                playerCols[ playerSource ] = {  };
                table.insert( playerCols[ playerSource ], pedMarker );
                addEventHandler( "onMarkerHit", pedMarker, arrivePickup )
                outputChatBox ( "Pickup the passenger with delivery located at the marker.", playerSource );
            else
                outputChatBox ( "No passenger pickup points specified, contact an admin!", playerSource );
            end
        else
            outputChatBox ( "You already have an assignment!", source );
        end
end
addCommandHandler ("startjob", startJob);
 
function arrivePickup ( playerSource )
    if playerClients[ playerSource ] then
        for k, ped in pairs( playerClients[ playerSource ] ) do
            if ped then
                local x,y,z     = getElementPosition(ped);
                local tx,ty,tz  = getElementPosition(playerSource);
                setPedRotation(ped, findRotation(x,y,tx,ty) );
                local numLocations = #truckerLocations
                if ( numLocations > 0 ) then
                    local playerVehicle = getPedOccupiedVehicle ( playerSource );
                    if playerVehicle and trucks[getElementModel ( playerVehicle )] then
                        local speedx, speedy, speedz = getElementVelocity ( playerSource );
                        local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5);
                        if actualspeed < 0.25 then
                            local occupants = getVehicleOccupants(playerVehicle);
                            local seats = getVehicleMaxPassengers(playerVehicle);
                            local freeSeats = 0;
                            for seat = 0, seats do
                                local occupant = occupants[seat];
                                if not occupant and tonumber(freeSeats) == 0 then
                                    freeSeats = freeSeats + 1;
                                    warpPedIntoVehicle ( ped, playerVehicle, seat );
                                    if playerBlips[ playerSource ] then
                                        for k, blip in pairs( playerBlips[ playerSource ] ) do
                                            if blip then
                                                destroyElement( blip );
                                                playerBlips[ playerSource ] = nil;
                                            end
                                        end
                                    end
                                    if playerCols[ playerSource ] then
                                        for k, col in pairs( playerCols[ playerSource ] ) do
                                            if col then
                                                destroyElement( col );
                                                playerCols[ playerSource ] = nil;
                                            end
                                        end
                                    end
                                    trailer =  createVehicle ( 435,  x-2 ,y-2 ,z+1)
                                    triggerEvent("givePoint")
                                end
                            end
                            if tonumber(freeSeats) == 0 then
                                outputChatBox ( "You don't have an empty seat for the passenger!", playerSource );
                            end
                        else
                            outputChatBox ( "Slow down to pick up the passenger!", playerSource );
                        end
                    else
                        outputChatBox ( "You do not have a driver vehicle!", playerSource );
                    end
                else
                    outputChatBox ( "No passenger pickup points specified, contact an admin!", playerSource );
                end
            end
        end
    end
end
addEvent("givePoint", true)
function givePoint( playerSource )
     local x,y,z = getElementPosition(ped);
    playerJobLocation[ playerSource ] = {  };
    playerJobLocation[ playerSource ] = { ["x"]=x, ["y"]=y, ["z"]=z };
 
    repeat
        local dropOffPoint = math.random(numLocations)
        dropOffx = truckerLocations[dropOffPoint]["x"]
        dropOffy = truckerLocations[dropOffPoint]["y"]
        dropOffz = truckerLocations[dropOffPoint]["z"]
        local jobDistance = getDistanceBetweenPoints3D ( x, y, z, dropOffx, dropOffy, dropOffz );              
    until jobDistance > 1000 and jobDistance < 35000
 
    local dropOffBlip = createBlip ( dropOffx, dropOffy, dropOffz, 41, 2, 255, 0, 0, 255, 1, 99999.0, playerSource)
    playerBlips[ playerSource ] = {  };
    table.insert( playerBlips[ playerSource ], dropOffBlip );
                                   
    pedMarker = createMarker ( dropOffx, dropOffy, 0, cylinder, 6.5, 255, 255, 0, 150, playerSource)
    playerCols[ playerSource ] = {  };
    table.insert( playerCols[ playerSource ], pedMarker );
    addEventHandler( "onMarkerHit", pedMarker, arriveDropOff )
    outputChatBox ( "Drive your products to the destination marker.", playerSource );
end
addEventHandler("givePoint", getRootElement(), givePoint)
 
function arriveDropOff ( playerSource )
    if playerClients[ playerSource ] then
        for k, ped in pairs( playerClients[ playerSource ] ) do
            if ped then
                local pedVehicle = getPedOccupiedVehicle ( ped );
                local playerVehicle = getPedOccupiedVehicle ( playerSource );
                if playerVehicle and trucks[getElementModel ( playerVehicle )] then
                    if pedVehicle == playerVehicle then
                        local speedx, speedy, speedz = getElementVelocity ( playerSource );
                        local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5);
                        if actualspeed < 0.22 then
                            removePedFromVehicle ( ped );
                            if playerClients[ playerSource ] then
                                for k, ped in pairs( playerClients[ playerSource ] ) do
                                    if ped then
                                        destroyElement( ped );
                                        playerClients[ playerSource ] = nil;
                                    end
                                end
                                for k, blip in pairs( playerBlips[ playerSource ] ) do
                                    if blip then
                                        destroyElement( blip );
                                        playerBlips[ playerSource ] = nil;
                                    end
                                end
                                for k, col in pairs( playerCols[ playerSource ] ) do
                                    if col then
                                        destroyElement( col );
                                        playerCols[ playerSource ] = nil;
                                    end
                                end
                                dx = tonumber(playerJobLocation[ playerSource ]["x"]);
                                dy = tonumber(playerJobLocation[ playerSource ]["y"]);
                                dz = tonumber(playerJobLocation[ playerSource ]["z"]);
                                local tx,ty,tz  = getElementPosition(playerSource);
                                local jobDistance = getDistanceBetweenPoints3D ( dx, dy, dz, tx, ty, tz );     
                                local jobDistanceKM = round(jobDistance/1000,2);
                                local jobReward = round(10+(jobDistanceKM^0.75)*3000);
                                givePlayerMoney ( playerSource, jobReward );
                               
                                for k, jobLocation in pairs( playerJobLocation[ playerSource ] ) do
                                    if jobLocation then
                                        playerJobLocation[ playerSource ] = nil;
                                    end
                                end
                                outputChatBox ( "Job succesful, you earned "..jobReward.." dollar.", playerSource );
                            end
                        else
                            outputChatBox ( "Slow down to drop off the passenger!", playerSource );
                        end
                    else
                        outputChatBox ( "You have lost your passenger!", playerSource );
                    end
                else
                    outputChatBox ( "You do not have a driver vehicle!", playerSource );
                end
            end
        end
    end
end
 
function quitJob ( playerSource )
    if playerClients[ playerSource ] then
        for k, ped in pairs( playerClients[ playerSource ] ) do
            if ped then
                destroyElement( ped );
                playerClients[ playerSource ] = nil;
            end
        end
        for k, blip in pairs( playerBlips[ playerSource ] ) do
            if blip then
                destroyElement( blip );
                playerBlips[ playerSource ] = nil;
            end
        end
        for k, col in pairs( playerCols[ playerSource ] ) do
            if col then
                destroyElement( col );
                playerCols[ playerSource ] = nil;
            end
        end
        if playerJobLocation[ playerSource ] then
            for k, jobLocation in pairs( playerJobLocation[ playerSource ] ) do
                if jobLocation then
                    destroyElement( jobLocation );
                    playerJobLocation[ playerSource ] =
Link to comment
  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
    function()
        truckSkins = { [206]=true, [133]=true }
        trucks = { [515]=true, [514]=true, [403]=true }
        playerClients = { }
        playerCols = { }
        playerBlips = { }
        jobClients = { }
        playerJobLocation = {  };
        local XMLTruckerLocations = xmlLoadFile ( "XML\\trucker_locations.xml" )
        if ( not XMLTruckerLocations ) then
            local XMLTruckerLocations = xmlCreateFile ( "XML\\trucker_locations.xml", "trucker_locations" )
            xmlSaveFile ( XMLTruckerLocations )
        end
       
        local trucker_locations = xmlNodeGetChildren(XMLTruckerLocations)
        truckerLocations = {}
        for i,node in ipairs(trucker_locations) do
            truckerLocations[i] = {}
            truckerLocations[i]["x"] = xmlNodeGetAttribute ( node, "posX" )
            truckerLocations[i]["y"] = xmlNodeGetAttribute ( node, "posY" )
            truckerLocations[i]["z"] = xmlNodeGetAttribute ( node, "posZ" )
            truckerLocations[i]["r"] = xmlNodeGetAttribute ( node, "rot" )
        end
        xmlUnloadFile ( XMLTruckerLocations )
    end
)
 
function enterVehicle ( thePlayer, seat, jacked )
    if ( trucks[getElementModel ( source )] ) and ( not truckSkins[getElementModel ( thePlayer )] ) and (seat == 0) then
        cancelEvent()
        outputChatBox ( "Only truckers drivers can drive Transports!", thePlayer )
    end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle )
 
function startJob ( playerSource )
    local x, y, z = getElementPosition ( playerSource )
        if not playerClients[ playerSource ] then
            local numLocations = #truckerLocations
            if ( numLocations > 0 ) then
                repeatCount = 0;
                repeat
                    local pickupPoint = math.random(numLocations)
                    pickupx = truckerLocations[pickupPoint]["x"]
                    pickupy = truckerLocations[pickupPoint]["y"]
                    pickupz = truckerLocations[pickupPoint]["z"]
                    pickupr = truckerLocations[pickupPoint]["r"]
                    local jobDistance = getDistanceBetweenPoints3D ( x, y, z, pickupx, pickupy, pickupz );
                    repeatCount = repeatCount+1
                until jobDistance > 100 and jobDistance < 800 + repeatCount*100
               
                repeat
                    local id = math.random( 10, 270 )
                    ped = createPed( tonumber( id ), pickupx, pickupy, pickupz )
                    setPedRotation ( ped, pickupr )
                until ped
               
                playerClients[ playerSource ] = {  };
                table.insert( playerClients[ playerSource ], ped );
                table.insert( jobClients, ped );
               
                local pedBlip = createBlipAttachedTo ( ped, 41, 2, 255, 0, 0, 255, 1, 99999.0, playerSource)
                playerBlips[ playerSource ] = {  };
                table.insert( playerBlips[ playerSource ], pedBlip );
               
                pedMarker = createMarker ( pickupx, pickupy, 0, cylinder, 6.5, 255, 255, 0, 150, playerSource)
                playerCols[ playerSource ] = {  };
                table.insert( playerCols[ playerSource ], pedMarker );
                addEventHandler( "onMarkerHit", pedMarker, arrivePickup )
                outputChatBox ( "Pickup the passenger with delivery located at the marker.", playerSource );
            else
                outputChatBox ( "No passenger pickup points specified, contact an admin!", playerSource );
            end
        else
            outputChatBox ( "You already have an assignment!", source );
        end
end
addCommandHandler ("startjob", startJob);
 
function arrivePickup ( playerSource )
    if playerClients[ playerSource ] then
        for k, ped in pairs( playerClients[ playerSource ] ) do
            if ped then
                local x,y,z     = getElementPosition(ped);
                local tx,ty,tz  = getElementPosition(playerSource);
                setPedRotation(ped, findRotation(x,y,tx,ty) );
                local numLocations = #truckerLocations
                if ( numLocations > 0 ) then
                    local playerVehicle = getPedOccupiedVehicle ( playerSource );
                    if playerVehicle and trucks[getElementModel ( playerVehicle )] then
                        local speedx, speedy, speedz = getElementVelocity ( playerSource );
                        local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5);
                        if actualspeed < 0.25 then
                            local occupants = getVehicleOccupants(playerVehicle);
                            local seats = getVehicleMaxPassengers(playerVehicle);
                            local freeSeats = 0;
                            for seat = 0, seats do
                                local occupant = occupants[seat];
                                if not occupant and tonumber(freeSeats) == 0 then
                                    freeSeats = freeSeats + 1;
                                    warpPedIntoVehicle ( ped, playerVehicle, seat );
                                    if playerBlips[ playerSource ] then
                                        for k, blip in pairs( playerBlips[ playerSource ] ) do
                                            if blip then
                                                destroyElement( blip );
                                                playerBlips[ playerSource ] = nil;
                                            end
                                        end
                                    end
                                    if playerCols[ playerSource ] then
                                        for k, col in pairs( playerCols[ playerSource ] ) do
                                            if col then
                                                destroyElement( col );
                                                playerCols[ playerSource ] = nil;
                                            end
                                        end
                                    end
                                    trailer =  createVehicle ( 435,  x-2 ,y-2 ,z+1)
                                    givePoint(playerSource)
                                end
                            end
                            if tonumber(freeSeats) == 0 then
                                outputChatBox ( "You don't have an empty seat for the passenger!", playerSource );
                            end
                        else
                            outputChatBox ( "Slow down to pick up the passenger!", playerSource );
                        end
                    else
                        outputChatBox ( "You do not have a driver vehicle!", playerSource );
                    end
                else
                    outputChatBox ( "No passenger pickup points specified, contact an admin!", playerSource );
                end
            end
        end
    end
end
addEvent("givePoint", true)
function givePoint( playerSource )
     local x,y,z = getElementPosition(ped);
    playerJobLocation[ playerSource ] = {  };
    playerJobLocation[ playerSource ] = { ["x"]=x, ["y"]=y, ["z"]=z };
 
    repeat
        local dropOffPoint = math.random(numLocations)
        dropOffx = truckerLocations[dropOffPoint]["x"]
        dropOffy = truckerLocations[dropOffPoint]["y"]
        dropOffz = truckerLocations[dropOffPoint]["z"]
        local jobDistance = getDistanceBetweenPoints3D ( x, y, z, dropOffx, dropOffy, dropOffz );              
    until jobDistance > 1000 and jobDistance < 35000
 
    local dropOffBlip = createBlip ( dropOffx, dropOffy, dropOffz, 41, 2, 255, 0, 0, 255, 1, 99999.0, playerSource)
    playerBlips[ playerSource ] = {  };
    table.insert( playerBlips[ playerSource ], dropOffBlip );
                                   
    pedMarker = createMarker ( dropOffx, dropOffy, 0, cylinder, 6.5, 255, 255, 0, 150, playerSource)
    playerCols[ playerSource ] = {  };
    table.insert( playerCols[ playerSource ], pedMarker );
    addEventHandler( "onMarkerHit", pedMarker, arriveDropOff )
    outputChatBox ( "Drive your products to the destination marker.", playerSource );
end
addEventHandler("givePoint", getRootElement(), givePoint)
 
function arriveDropOff ( playerSource )
    if playerClients[ playerSource ] then
        for k, ped in pairs( playerClients[ playerSource ] ) do
            if ped then
                local pedVehicle = getPedOccupiedVehicle ( ped );
                local playerVehicle = getPedOccupiedVehicle ( playerSource );
                if playerVehicle and trucks[getElementModel ( playerVehicle )] then
                    if pedVehicle == playerVehicle then
                        local speedx, speedy, speedz = getElementVelocity ( playerSource );
                        local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5);
                        if actualspeed < 0.22 then
                            removePedFromVehicle ( ped );
                            if playerClients[ playerSource ] then
                                for k, ped in pairs( playerClients[ playerSource ] ) do
                                    if ped then
                                        destroyElement( ped );
                                        playerClients[ playerSource ] = nil;
                                    end
                                end
                                for k, blip in pairs( playerBlips[ playerSource ] ) do
                                    if blip then
                                        destroyElement( blip );
                                        playerBlips[ playerSource ] = nil;
                                    end
                                end
                                for k, col in pairs( playerCols[ playerSource ] ) do
                                    if col then
                                        destroyElement( col );
                                        playerCols[ playerSource ] = nil;
                                    end
                                end
                                dx = tonumber(playerJobLocation[ playerSource ]["x"]);
                                dy = tonumber(playerJobLocation[ playerSource ]["y"]);
                                dz = tonumber(playerJobLocation[ playerSource ]["z"]);
                                local tx,ty,tz  = getElementPosition(playerSource);
                                local jobDistance = getDistanceBetweenPoints3D ( dx, dy, dz, tx, ty, tz );     
                                local jobDistanceKM = round(jobDistance/1000,2);
                                local jobReward = round(10+(jobDistanceKM^0.75)*3000);
                                givePlayerMoney ( playerSource, jobReward );
                               
                                for k, jobLocation in pairs( playerJobLocation[ playerSource ] ) do
                                    if jobLocation then
                                        playerJobLocation[ playerSource ] = nil;
                                    end
                                end
                                outputChatBox ( "Job succesful, you earned "..jobReward.." dollar.", playerSource );
                            end
                        else
                            outputChatBox ( "Slow down to drop off the passenger!", playerSource );
                        end
                    else
                        outputChatBox ( "You have lost your passenger!", playerSource );
                    end
                else
                    outputChatBox ( "You do not have a driver vehicle!", playerSource );
                end
            end
        end
    end
end
 
function quitJob ( playerSource )
    if playerClients[ playerSource ] then
        for k, ped in pairs( playerClients[ playerSource ] ) do
            if ped then
                destroyElement( ped );
                playerClients[ playerSource ] = nil;
            end
        end
        for k, blip in pairs( playerBlips[ playerSource ] ) do
            if blip then
                destroyElement( blip );
                playerBlips[ playerSource ] = nil;
            end
        end
        for k, col in pairs( playerCols[ playerSource ] ) do
            if col then
                destroyElement( col );
                playerCols[ playerSource ] = nil;
            end
        end
        if playerJobLocation[ playerSource ] then
            for k, jobLocation in pairs( playerJobLocation[ playerSource ] ) do
                if jobLocation then
                    destroyElement( jobLocation );
                    playerJobLocation[ playerSource ] =
Link to comment
  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
    function()
        truckSkins = { [206]=true, [133]=true }
        trucks = { [515]=true, [514]=true, [403]=true }
        playerClients = { }
        playerCols = { }
        playerBlips = { }
        jobClients = { }
        playerJobLocation = {  };
        local XMLTruckerLocations = xmlLoadFile ( "XML\\trucker_locations.xml" )
        if ( not XMLTruckerLocations ) then
            local XMLTruckerLocations = xmlCreateFile ( "XML\\trucker_locations.xml", "trucker_locations" )
            xmlSaveFile ( XMLTruckerLocations )
        end
       
        local trucker_locations = xmlNodeGetChildren(XMLTruckerLocations)
        truckerLocations = {}
        for i,node in ipairs(trucker_locations) do
            truckerLocations[i] = {}
            truckerLocations[i]["x"] = xmlNodeGetAttribute ( node, "posX" )
            truckerLocations[i]["y"] = xmlNodeGetAttribute ( node, "posY" )
            truckerLocations[i]["z"] = xmlNodeGetAttribute ( node, "posZ" )
            truckerLocations[i]["r"] = xmlNodeGetAttribute ( node, "rot" )
        end
        xmlUnloadFile ( XMLTruckerLocations )
    end
)
 
function enterVehicle ( thePlayer, seat, jacked )
    if ( trucks[getElementModel ( source )] ) and ( not truckSkins[getElementModel ( thePlayer )] ) and (seat == 0) then
        cancelEvent()
        outputChatBox ( "Only truckers drivers can drive Transports!", thePlayer )
    end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle )
 
function startJob ( playerSource )
    local x, y, z = getElementPosition ( playerSource )
        if not playerClients[ playerSource ] then
            local numLocations = #truckerLocations
            if ( numLocations > 0 ) then
                repeatCount = 0;
                repeat
                    local pickupPoint = math.random(numLocations)
                    pickupx = truckerLocations[pickupPoint]["x"]
                    pickupy = truckerLocations[pickupPoint]["y"]
                    pickupz = truckerLocations[pickupPoint]["z"]
                    pickupr = truckerLocations[pickupPoint]["r"]
                    local jobDistance = getDistanceBetweenPoints3D ( x, y, z, pickupx, pickupy, pickupz );
                    repeatCount = repeatCount+1
                until jobDistance > 100 and jobDistance < 800 + repeatCount*100
               
                repeat
                    local id = math.random( 10, 270 )
                    ped = createPed( tonumber( id ), pickupx, pickupy, pickupz )
                    setPedRotation ( ped, pickupr )
                until ped
               
                playerClients[ playerSource ] = {  };
                table.insert( playerClients[ playerSource ], ped );
                table.insert( jobClients, ped );
               
                local pedBlip = createBlipAttachedTo ( ped, 41, 2, 255, 0, 0, 255, 1, 99999.0, playerSource)
                playerBlips[ playerSource ] = {  };
                table.insert( playerBlips[ playerSource ], pedBlip );
               
                pedMarker = createMarker ( pickupx, pickupy, 0, cylinder, 6.5, 255, 255, 0, 150, playerSource)
                playerCols[ playerSource ] = {  };
                table.insert( playerCols[ playerSource ], pedMarker );
                addEventHandler( "onMarkerHit", pedMarker, arrivePickup )
                outputChatBox ( "Pickup the passenger with delivery located at the marker.", playerSource );
            else
                outputChatBox ( "No passenger pickup points specified, contact an admin!", playerSource );
            end
        else
            outputChatBox ( "You already have an assignment!", source );
        end
end
addCommandHandler ("startjob", startJob);
 
function arrivePickup ( playerSource )
    if playerClients[ playerSource ] then
        for k, ped in pairs( playerClients[ playerSource ] ) do
            if ped then
                local x,y,z     = getElementPosition(ped);
                local tx,ty,tz  = getElementPosition(playerSource);
                setPedRotation(ped, findRotation(x,y,tx,ty) );
                local numLocations = #truckerLocations
                if ( numLocations > 0 ) then
                    local playerVehicle = getPedOccupiedVehicle ( playerSource );
                    if playerVehicle and trucks[getElementModel ( playerVehicle )] then
                        local speedx, speedy, speedz = getElementVelocity ( playerSource );
                        local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5);
                        if actualspeed < 0.25 then
                            local occupants = getVehicleOccupants(playerVehicle);
                            local seats = getVehicleMaxPassengers(playerVehicle);
                            local freeSeats = 0;
                            for seat = 0, seats do
                                local occupant = occupants[seat];
                                if not occupant and tonumber(freeSeats) == 0 then
                                    freeSeats = freeSeats + 1;
                                    warpPedIntoVehicle ( ped, playerVehicle, seat );
                                    if playerBlips[ playerSource ] then
                                        for k, blip in pairs( playerBlips[ playerSource ] ) do
                                            if blip then
                                                destroyElement( blip );
                                                playerBlips[ playerSource ] = nil;
                                            end
                                        end
                                    end
                                    if playerCols[ playerSource ] then
                                        for k, col in pairs( playerCols[ playerSource ] ) do
                                            if col then
                                                destroyElement( col );
                                                playerCols[ playerSource ] = nil;
                                            end
                                        end
                                    end
                                    trailer =  createVehicle ( 435,  x-2 ,y-2 ,z+1)
                                    givePoint(playerSource)
                                end
                            end
                            if tonumber(freeSeats) == 0 then
                                outputChatBox ( "You don't have an empty seat for the passenger!", playerSource );
                            end
                        else
                            outputChatBox ( "Slow down to pick up the passenger!", playerSource );
                        end
                    else
                        outputChatBox ( "You do not have a driver vehicle!", playerSource );
                    end
                else
                    outputChatBox ( "No passenger pickup points specified, contact an admin!", playerSource );
                end
            end
        end
    end
end
addEvent("givePoint", true)
function givePoint( playerSource )
     local x,y,z = getElementPosition(ped);
    playerJobLocation[ playerSource ] = {  };
    playerJobLocation[ playerSource ] = { ["x"]=x, ["y"]=y, ["z"]=z };
 
    repeat
        local dropOffPoint = math.random(numLocations)
        dropOffx = truckerLocations[dropOffPoint]["x"]
        dropOffy = truckerLocations[dropOffPoint]["y"]
        dropOffz = truckerLocations[dropOffPoint]["z"]
        local jobDistance = getDistanceBetweenPoints3D ( x, y, z, dropOffx, dropOffy, dropOffz );              
    until jobDistance > 1000 and jobDistance < 35000
 
    local dropOffBlip = createBlip ( dropOffx, dropOffy, dropOffz, 41, 2, 255, 0, 0, 255, 1, 99999.0, playerSource)
    playerBlips[ playerSource ] = {  };
    table.insert( playerBlips[ playerSource ], dropOffBlip );
                                   
    pedMarker = createMarker ( dropOffx, dropOffy, 0, cylinder, 6.5, 255, 255, 0, 150, playerSource)
    playerCols[ playerSource ] = {  };
    table.insert( playerCols[ playerSource ], pedMarker );
    addEventHandler( "onMarkerHit", pedMarker, arriveDropOff )
    outputChatBox ( "Drive your products to the destination marker.", playerSource );
end
addEventHandler("givePoint", getRootElement(), givePoint)
 
function arriveDropOff ( playerSource )
    if playerClients[ playerSource ] then
        for k, ped in pairs( playerClients[ playerSource ] ) do
            if ped then
                local pedVehicle = getPedOccupiedVehicle ( ped );
                local playerVehicle = getPedOccupiedVehicle ( playerSource );
                if playerVehicle and trucks[getElementModel ( playerVehicle )] then
                    if pedVehicle == playerVehicle then
                        local speedx, speedy, speedz = getElementVelocity ( playerSource );
                        local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5);
                        if actualspeed < 0.22 then
                            removePedFromVehicle ( ped );
                            if playerClients[ playerSource ] then
                                for k, ped in pairs( playerClients[ playerSource ] ) do
                                    if ped then
                                        destroyElement( ped );
                                        playerClients[ playerSource ] = nil;
                                    end
                                end
                                for k, blip in pairs( playerBlips[ playerSource ] ) do
                                    if blip then
                                        destroyElement( blip );
                                        playerBlips[ playerSource ] = nil;
                                    end
                                end
                                for k, col in pairs( playerCols[ playerSource ] ) do
                                    if col then
                                        destroyElement( col );
                                        playerCols[ playerSource ] = nil;
                                    end
                                end
                                dx = tonumber(playerJobLocation[ playerSource ]["x"]);
                                dy = tonumber(playerJobLocation[ playerSource ]["y"]);
                                dz = tonumber(playerJobLocation[ playerSource ]["z"]);
                                local tx,ty,tz  = getElementPosition(playerSource);
                                local jobDistance = getDistanceBetweenPoints3D ( dx, dy, dz, tx, ty, tz );     
                                local jobDistanceKM = round(jobDistance/1000,2);
                                local jobReward = round(10+(jobDistanceKM^0.75)*3000);
                                givePlayerMoney ( playerSource, jobReward );
                               
                                for k, jobLocation in pairs( playerJobLocation[ playerSource ] ) do
                                    if jobLocation then
                                        playerJobLocation[ playerSource ] = nil;
                                    end
                                end
                                outputChatBox ( "Job succesful, you earned "..jobReward.." dollar.", playerSource );
                            end
                        else
                            outputChatBox ( "Slow down to drop off the passenger!", playerSource );
                        end
                    else
                        outputChatBox ( "You have lost your passenger!", playerSource );
                    end
                else
                    outputChatBox ( "You do not have a driver vehicle!", playerSource );
                end
            end
        end
    end
end
 
function quitJob ( playerSource )
    if playerClients[ playerSource ] then
        for k, ped in pairs( playerClients[ playerSource ] ) do
            if ped then
                destroyElement( ped );
                playerClients[ playerSource ] = nil;
            end
        end
        for k, blip in pairs( playerBlips[ playerSource ] ) do
            if blip then
                destroyElement( blip );
                playerBlips[ playerSource ] = nil;
            end
        end
        for k, col in pairs( playerCols[ playerSource ] ) do
            if col then
                destroyElement( col );
                playerCols[ playerSource ] = nil;
            end
        end
        if playerJobLocation[ playerSource ] then
            for k, jobLocation in pairs( playerJobLocation[ playerSource ] ) do
                if jobLocation then
                   
Link to comment
Try to change 'playerSource' in the 'givepoint' function to just 'source'. And you don't pass any arguments to that function from client, so remove it from the function arguments too.

OK i got that problem solved, but now i am getting this error for this part of the code.

[2012-07-24 17:22:58] WARNING: [roleplay]\rrtrucker\rrtrucker_server.lua:142: Bad argument @ 'getElementPosition'

[2012-07-24 17:22:58] WARNING: [roleplay]\rrtrucker\rrtrucker_server.lua:151: Bad argument @ 'getDistanceBetweenPoints3D'

serverside:

  
addEvent("givePoint", true) 
function givePoint( playerSource ) 
     
--  playerJobLocation[ playerSource ] = {  }; 
--  playerJobLocation[ playerSource ] = { ["x"]=x, ["y"]=y, ["z"]=z }; 
    local numLocations = #truckerLocations 
    repeat 
        local x,y,z = getElementPosition(playerSource) 
        local dropOffPoint = math.random(numLocations) 
        dropOffx = truckerLocations[dropOffPoint]["x"] 
        dropOffy = truckerLocations[dropOffPoint]["y"] 
        dropOffz = truckerLocations[dropOffPoint]["z"] 
        local jobDistance = getDistanceBetweenPoints3D ( x, y, z, dropOffx, dropOffy, dropOffz )                 
    until jobDistance > 1000 and jobDistance < 35000 
  
    local dropOffBlip = createBlip ( dropOffx, dropOffy, dropOffz, 41, 2, 255, 0, 0, 255, 1, 99999.0, playerSource) 
    playerBlips[ playerSource ] = {  }; 
    table.insert( playerBlips[ playerSource ], dropOffBlip ); 
                                     
    pedMarker = createMarker ( dropOffx, dropOffy, 0, cylinder, 6.5, 255, 255, 0, 150, playerSource) 
    playerCols[ playerSource ] = {  }; 
    table.insert( playerCols[ playerSource ], pedMarker ); 
    addEventHandler( "onMarkerHit", pedMarker, arriveDropOff ) 
    outputChatBox ( "Drive your products to the destination marker.", playerSource ); 
end 
addEventHandler("givePoint", getRootElement(), givePoint) 
  

Link to comment

Solidsnake14 is right and you didn't do enough like I told you. Your problem is wrong argument 'playerSource'. Try this:

addEvent("givePoint", true) 
function givePoint(  ) 
     
--  playerJobLocation[ source ] = {  }; 
--  playerJobLocation[ source ] = { ["x"]=x, ["y"]=y, ["z"]=z }; 
    local numLocations = #truckerLocations 
    repeat 
        local x,y,z = getElementPosition(source) 
        local dropOffPoint = math.random(numLocations) 
        dropOffx = truckerLocations[dropOffPoint]["x"] 
        dropOffy = truckerLocations[dropOffPoint]["y"] 
        dropOffz = truckerLocations[dropOffPoint]["z"] 
        local jobDistance = getDistanceBetweenPoints3D ( x, y, z, dropOffx, dropOffy, dropOffz )                 
    until jobDistance > 1000 and jobDistance < 35000 
  
    local dropOffBlip = createBlip ( dropOffx, dropOffy, dropOffz, 41, 2, 255, 0, 0, 255, 1, 99999.0, source) 
    playerBlips[ source ] = {  }; 
    table.insert( playerBlips[ source ], dropOffBlip ); 
                                     
    pedMarker = createMarker ( dropOffx, dropOffy, 0, cylinder, 6.5, 255, 255, 0, 150, source) 
    playerCols[ source ] = {  }; 
    table.insert( playerCols[ source ], pedMarker ); 
    addEventHandler( "onMarkerHit", pedMarker, arriveDropOff ) 
    outputChatBox ( "Drive your products to the destination marker.", source ); 
end 
addEventHandler("givePoint", getRootElement(), givePoint) 

Link to comment
Solidsnake14 is right and you didn't do enough like I told you. Your problem is wrong argument 'playerSource'. Try this:
addEvent("givePoint", true) 
function givePoint(  ) 
     
--  playerJobLocation[ source ] = {  }; 
--  playerJobLocation[ source ] = { ["x"]=x, ["y"]=y, ["z"]=z }; 
    local numLocations = #truckerLocations 
    repeat 
        local x,y,z = getElementPosition(source) 
        local dropOffPoint = math.random(numLocations) 
        dropOffx = truckerLocations[dropOffPoint]["x"] 
        dropOffy = truckerLocations[dropOffPoint]["y"] 
        dropOffz = truckerLocations[dropOffPoint]["z"] 
        local jobDistance = getDistanceBetweenPoints3D ( x, y, z, dropOffx, dropOffy, dropOffz )                 
    until jobDistance > 1000 and jobDistance < 35000 
  
    local dropOffBlip = createBlip ( dropOffx, dropOffy, dropOffz, 41, 2, 255, 0, 0, 255, 1, 99999.0, source) 
    playerBlips[ source ] = {  }; 
    table.insert( playerBlips[ source ], dropOffBlip ); 
                                     
    pedMarker = createMarker ( dropOffx, dropOffy, 0, cylinder, 6.5, 255, 255, 0, 150, source) 
    playerCols[ source ] = {  }; 
    table.insert( playerCols[ source ], pedMarker ); 
    addEventHandler( "onMarkerHit", pedMarker, arriveDropOff ) 
    outputChatBox ( "Drive your products to the destination marker.", source ); 
end 
addEventHandler("givePoint", getRootElement(), givePoint) 

Thanks, but there are still some errors

[2012-07-24 17:44:21] ERROR: [roleplay]\rrtrucker\rrtrucker_server.lua:237: bad argument #1 to 'pairs' (table expected, got nil)

[2012-07-24 17:46:38] ERROR: [roleplay]\rrtrucker\rrtrucker_server.lua:199: attempt to index field '?' (a nil value)

im going to try to find out why these happen

Link to comment
Solidsnake14 is right and you didn't do enough like I told you. Your problem is wrong argument 'playerSource'. Try this:
addEvent("givePoint", true) 
function givePoint(  ) 
     
--  playerJobLocation[ source ] = {  }; 
--  playerJobLocation[ source ] = { ["x"]=x, ["y"]=y, ["z"]=z }; 
    local numLocations = #truckerLocations 
    repeat 
        local x,y,z = getElementPosition(source) 
        local dropOffPoint = math.random(numLocations) 
        dropOffx = truckerLocations[dropOffPoint]["x"] 
        dropOffy = truckerLocations[dropOffPoint]["y"] 
        dropOffz = truckerLocations[dropOffPoint]["z"] 
        local jobDistance = getDistanceBetweenPoints3D ( x, y, z, dropOffx, dropOffy, dropOffz )                 
    until jobDistance > 1000 and jobDistance < 35000 
  
    local dropOffBlip = createBlip ( dropOffx, dropOffy, dropOffz, 41, 2, 255, 0, 0, 255, 1, 99999.0, source) 
    playerBlips[ source ] = {  }; 
    table.insert( playerBlips[ source ], dropOffBlip ); 
                                     
    pedMarker = createMarker ( dropOffx, dropOffy, 0, cylinder, 6.5, 255, 255, 0, 150, source) 
    playerCols[ source ] = {  }; 
    table.insert( playerCols[ source ], pedMarker ); 
    addEventHandler( "onMarkerHit", pedMarker, arriveDropOff ) 
    outputChatBox ( "Drive your products to the destination marker.", source ); 
end 
addEventHandler("givePoint", getRootElement(), givePoint) 

Thanks, but there are still some errors

[2012-07-24 17:44:21] ERROR: [roleplay]\rrtrucker\rrtrucker_server.lua:237: bad argument #1 to 'pairs' (table expected, got nil)

[2012-07-24 17:46:38] ERROR: [roleplay]\rrtrucker\rrtrucker_server.lua:199: attempt to index field '?' (a nil value)

im going to try to find out why these happen

I CANT TELL YOU GUYS HOW GREAT YOU ARE, I GOT IT WORKING!

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