Jump to content

[HELP] Bus Driver Job


Emanuel

Recommended Posts

Hello ! I need you help in this script. First of all, I am not a good scripter, that's why I am asking you why this is not working properly. When two players are playing, one can steal bus stops from other. Also, when one leaves his bus, the other one will not see the markers. Can you help me, and explain everything as I was the dumbest person in the world ?

-----------------------------------------------<< 
-- MTA : Multi Theft Auto : Emanuel's Server 
-- Date: 21 July 2015 
-- Resource: [MTA][Jobs]/[MTA]BusDriver/server.lua 
-- Type: Server Side 
-- Author: Emanuel Camacho 
-----------------------------------------------<< 
local busses = {[431] = true, [437] = true} 
local rootElement = getRootElement() 
  
local markers = { 
[1] = {-1798.63940, 83.94303, 15.10938}, 
[2] = {-1800.16284, 102.19742, 15.10938}, 
[3] = {-1800.60095, 126.91389, 15.10938}, 
} 
  
function getNewBusLocation( thePlayer, ID ) 
    local x, y, z = markers[ID][1], markers[ID][2], markers[ID][3] 
    triggerClientEvent(thePlayer,"setNextBusStopPosition",thePlayer,x,y,z) 
end 
  
function onVehicleEnter(client) 
    if not busses[getElementModel(source)] then return end 
    if not getPlayerTeam(client) then return end 
    if getTeamName(getPlayerTeam(client)) == "Bus Driver" then 
        local x, y, z = getNewBusLocation(client, 1) 
        setElementData(client,"busData",1) 
    end 
end 
addEventHandler("onVehicleEnter",rootElement,onVehicleEnter) 
  
addEvent("updateBusStop",true) 
addEventHandler("updateBusStop",rootElement, 
function (client) 
    if not isPedInVehicle(client) then return end 
    if not busses[getElementModel(getPedOccupiedVehicle(client))] then return end 
    givePlayerMoney(client, 100) 
    if #markers == tonumber(getElementData(client,"busData")) then 
        setElementData(client,"busData",1) 
    else 
        setElementData(client,"busData",tonumber(getElementData(client,"busData"))+1) 
    end 
    getNewBusLocation(client, tonumber(getElementData(client,"busData"))) 
end) 

-----------------------------------------------<< 
-- MTA : Multi Theft Auto : Emanuel's Server 
-- Date: 21 July 2015 
-- Resource: [MTA][Jobs]/[MTA]BusDriver/client.lua 
-- Type: Client Side 
-- Author: Emanuel Camacho 
-----------------------------------------------<< 
local client = getLocalPlayer( ) 
local rootElement = getRootElement() 
local marker = nil 
local blip = nil 
  
function createNextStop ( x, y, z ) 
    marker = createMarker(tostring(x), tostring(y), tostring(z)-1, "cylinder", 3.5, 255, 255, 0, 170) 
    blip = createBlipAttachedTo( marker, 0, 2, 255, 255, 0, 255 ) 
    addEventHandler("onClientMarkerHit",marker,onBusStopHit) 
end 
  
addEvent("setNextBusStopPosition",true) 
addEventHandler("setNextBusStopPosition", rootElement, createNextStop ) 
  
function onBusStopHit( hitPlayer ) 
    if not hitPlayer == localPlayer then return end 
    triggerServerEvent("updateBusStop",localPlayer,localPlayer) 
    if isElement(blip) then destroyElement(blip) end 
    if isElement(marker) then 
        removeEventHandler("onClientMarkerHit",marker,onBusStopHit) 
        destroyElement(marker)  
    end 
end 
  
function leavingVehicle() 
    if isElement(marker) then 
        removeEventHandler("onClientMarkerHit",marker,onBusStopHit) 
        destroyElement(marker)  
    end 
    if isElement(blip) then destroyElement(blip) end 
end 
addEventHandler("onClientVehicleExit",rootElement, leavingVehicle ) 

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