Jump to content

Bus job (need a bit of your help)


rafull6

Recommended Posts

Hey guys. Today I've downloaded one nice resource from community. It is BUS JOB https://community.multitheftauto.com/index.php?p=resources&s=details&id=2588.

Here is my problem: this script work's perfectly except one thing. When you driving to the markets alone (there is no truck workers on the server except you) it's pretty good, but when there is two or more truck drivers - markets appear once for all drivers, and if one of the drivers takes the marker, it's disappears for other truck drivers. So, drivers are stealing from each other this markers. That's sucks. Please help me to fix this problem so, that each player would have personal markers, that will be visible only for him.

Here is the code:

Server:

  
local rootElement = getRootElement() 
  
local trucks = {[403] = true, [514] = true, [515] = true} 
  
local truckTable = { 
[1]={1812.65198, -1889.86047, 13.41406}, 
[2]={1825.22791, -1635.03711, 13.38281}, 
[3]={1855.01685, -1430.47449, 13.39063}, 
[4]={1732.81580, -1296.87122, 13.44294}, 
[5]={1473.19226, -1295.77124, 13.48315}, 
[6]={1443.60376, -1498.26660, 13.37650}, 
[7]={1426.37280, -1716.12439, 13.38281}, 
[8]={1315.06909, -1656.43799, 13.38281}, 
[9]={1359.06250, -1432.39734, 13.38281}, 
[10]={1169.82983, -1392.34473, 13.41728}, 
[11]={930.76508, -1392.92627, 13.26561}, 
[12]={815.24756, -1317.91345, 13.44460}, 
[13]={585.04199, -1320.53748, 13.40609}, 
[14]={526.99365, -1624.20361, 16.63225}, 
} 
  
function getNewTruckLocation(thePlayer, ID) 
local x, y, z = truckTable[ID][1], truckTable[ID][2], truckTable[ID][3] 
triggerClientEvent(thePlayer,"truck_set_location",thePlayer,x,y,z) 
end 
  
function onVehicleEnter(thePlayer) 
if not trucks[getElementModel(source)] then return end 
if not getPlayerTeam(thePlayer) then return end 
if getTeamName(getPlayerTeam(thePlayer)) == "Truckers" then 
local x, y, z = getNewTruckLocation(thePlayer, 1) 
setElementData(thePlayer,"truckData",1) 
  end 
end 
addEventHandler("onVehicleEnter",rootElement,onVehicleEnter) 
  
addEvent("truck_finish",true) 
addEventHandler("truck_finish",rootElement, 
function (client) 
if not isPedInVehicle(client) then return end 
if not trucks[getElementModel(getPedOccupiedVehicle(client))] then return end 
givePlayerMoney(client, 100) 
if #truckTable == tonumber(getElementData(client,"truckData")) then 
setElementData(client,"truckData",1) 
else 
setElementData(client,"truckData",tonumber(getElementData(client,"truckData"))+1) 
end 
getNewTruckLocation(client, tonumber(getElementData(client,"truckData"))) 
end) 
  

Server

  
local client = getLocalPlayer( ) 
local rootElement = getRootElement() 
local truckmarker = nil 
local truckblip = nil 
  
addEvent("truck_set_location",true) 
addEventHandler("truck_set_location",rootElement, 
function (x, y, z) 
truckmarker = createMarker(tostring(x), tostring(y), tostring(z)-1, "cylinder", 10, 184, 57, 14, 170) 
truckblip = createBlipAttachedTo( truckmarker, 19 ) 
addEventHandler("onClientMarkerHit",truckmarker,onTruckStopHit) 
end) 
  
function onTruckStopHit(hitPlayer) 
if not hitPlayer == client then return end 
triggerServerEvent("truck_finish",client,client) 
if isElement(truckblip) then destroyElement(truckblip) end 
if isElement(truckmarker) then 
removeEventHandler("onClientMarkerHit",truckmarker,onTruckStopHit) 
destroyElement(truckmarker)  
  end 
end 
  
addEventHandler("onClientVehicleExit",rootElement, 
function () 
if isElement(marker) then 
removeEventHandler("onClientMarkerHit",truckmarker,onTruckStopHit) 
destroyElement(truckmarker)  
end 
if isElement(truckblip) then destroyElement(truckblip) end 
end) 
  

Link to comment

Maybe this?

  
local client = getLocalPlayer( ) 
local rootElement = getRootElement() 
local truckmarker = nil 
local truckblip = nil 
  
addEvent("truck_set_location",true) 
addEventHandler("truck_set_location",rootElement, 
function (x, y, z) 
truckmarker = createMarker(tostring(x), tostring(y), tostring(z)-1, "cylinder", 10, 184, 57, 14, 170) 
truckblip = createBlipAttachedTo( truckmarker, 19 ) 
addEventHandler("onClientMarkerHit",truckmarker,onTruckStopHit) 
end) 
  
function onTruckStopHit(hitPlayer) 
if not hitPlayer == client then return end 
triggerServerEvent("truck_finish",client,client) 
if isElement(truckblip) then destroyElement(truckblip) end 
if isElement(truckmarker) then 
removeEventHandler("onClientMarkerHit",truckmarker,onTruckStopHit) 
  end 
end 
  
addEventHandler("onClientVehicleExit",rootElement, 
function () 
if isElement(marker) then 
removeEventHandler("onClientMarkerHit",truckmarker,onTruckStopHit) 
destroyElement(truckmarker)  
end 
if isElement(truckblip) then destroyElement(truckblip) end 
end) 
  

Link to comment

Server

addEvent( "truck_finish",true ) 
  
local trucks = { 
    [403] = true, 
    [514] = true, 
    [515] = true 
} 
  
local truckTable = { 
    [1]     ={ 1812.65198, -1889.86047, 13.41406 }, 
    [2]     ={ 1825.22791, -1635.03711, 13.38281 }, 
    [3]     ={ 1855.01685, -1430.47449, 13.39063 }, 
    [4]     ={ 1732.81580, -1296.87122, 13.44294 }, 
    [5]     ={ 1473.19226, -1295.77124, 13.48315 }, 
    [6]     ={ 1443.60376, -1498.26660, 13.37650 }, 
    [7]     ={ 1426.37280, -1716.12439, 13.38281 }, 
    [8]     ={ 1315.06909, -1656.43799, 13.38281 }, 
    [9]     ={ 1359.06250, -1432.39734, 13.38281 }, 
    [10]    ={ 1169.82983, -1392.34473, 13.41728 }, 
    [11]    ={ 930.76508, -1392.92627, 13.26561 }, 
    [12]    ={ 815.24756, -1317.91345, 13.44460 }, 
    [13]    ={ 585.04199, -1320.53748, 13.40609 }, 
    [14]    ={ 526.99365, -1624.20361, 16.63225 } 
} 
  
function getNewTruckLocation( thePlayer, ID ) 
    local x, y, z = truckTable[ ID ][1], truckTable[ ID ][2], truckTable[ ID ][3] 
    triggerClientEvent( thePlayer,"truck_set_location",thePlayer,x,y,z ) 
end 
  
function onVehicleEnter( thePlayer ) 
    if not trucks[ getElementModel( source ) ] or  
    getPlayerTeam( thePlayer ) then  
        return  
    end 
    if getTeamName( getPlayerTeam( thePlayer ) ) == "Truckers" then 
        getNewTruckLocation( thePlayer, 1 ) 
        setElementData( thePlayer,"truckData",1 ) 
    end 
end 
addEventHandler( "onVehicleEnter",root,onVehicleEnter ) 
  
addEventHandler( "truck_finish",root, 
    function ( ) 
        if not isPedInVehicle( source ) or 
        not trucks[ getElementModel( getPedOccupiedVehicle( source ) ) ] then 
            return end 
        end 
        givePlayerMoney( source, 100 ) 
        if #truckTable == tonumber( getElementData( source,"truckData" ) ) then 
            setElementData( source,"truckData",1 ) 
        else 
            setElementData( source,"truckData",tonumber( getElementData( source,"truckData" ) ) +1 ) 
        end 
        getNewTruckLocation( source, tonumber( getElementData( source,"truckData" ) ) ) 
    end 
) 

Client

  
local truckmarker,truckblip 
  
addEvent( "truck_set_location",true ) 
  
addEventHandler( "truck_set_location",root, 
    function ( x, y, z ) 
        truckmarker = createMarker( x ,y,z-1, "cylinder", 10, 184, 57, 14, 170 ) 
        truckblip = createBlipAttachedTo( truckmarker, 19 ) 
        addEventHandler( "onClientMarkerHit",truckmarker,onTruckStopHit ) 
    end 
) 
  
function onTruckStopHit( hitPlayer ) 
    if not hitPlayer == localPlayer then  
        return  
    end 
    triggerServerEvent( "truck_finish",localPlayer ) 
    if isElement( truckblip ) then  
        destroyElement( truckblip )  
    end 
    if isElement( truckmarker ) then 
        removeEventHandler( "onClientMarkerHit",truckmarker,onTruckStopHit ) 
        destroyElement( truckmarker )  
    end 
end 
  
addEventHandler( "onClientVehicleExit",root, 
    function ( ) 
        if isElement( truckmarker ) then 
            removeEventHandler( "onClientMarkerHit",truckmarker,onTruckStopHit ) 
            destroyElement( truckmarker )  
        end 
        if isElement( truckblip ) then  
            destroyElement( truckblip ) 
        end 
    end 
) 

Try this , but i not understand what you mean :/

Write steps.

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