Jump to content

[HELP] Request help


K4stic

Recommended Posts

I cleaned and fixed your script, should work just fine now.

-- client side:

local marker = nil 
local blip = nil 
local marker0 = createMarker ( 1809.6, -1897.8, 12.6, "Cylinder", 2, 255, 255, 0, 100 ) 
local skins = { "Bus Driver 1 (skin: 253)", "Bus Driver 2 (skin: 255)" } 
  
windowjob = guiCreateWindow(0.335,0.14,0.3963,0.6817,"Bus Driver Job",true) 
guiSetVisible(windowjob, false) 
infomemo = guiCreateMemo(0.0347,0.0611,0.9369,0.3667,"The role of the Bus driver is to drive to vatious populous locations around the city\nWhen you enter a bus,you will be given a stop to drive to,marked by a waypoint blip\nWhen you arrive stop,you will then paid and given a new stop to drive to.\nPick up players to earn additional cash.\nThe bus stops will be given to you in a set order along a route.",true,windowjob) 
skinsgrid = guiCreateGridList(0.0347,0.4841,0.9369,0.313,true,windowjob) 
guiGridListSetSelectionMode(skinsgrid,2) 
_skins = guiGridListAddColumn(skinsgrid,"Skins",0.95) 
takebtn = guiCreateButton(0.2492,0.8289,0.5047,0.0562,"Accept",true,windowjob) 
closebtn = guiCreateButton(0.2492,0.9095,0.5047,0.0562,"Cancel",true,windowjob) 
infolbl = guiCreateLabel(0.2681,0.4279,0.4637,0.0538,"Choose your skin :",true,windowjob) 
guiLabelSetColor(infolbl,0,0,255) 
guiLabelSetVerticalAlign(infolbl,"center") 
guiLabelSetHorizontalAlign(infolbl,"center",false) 
guiSetFont(infolbl,"default-bold-small") 
  
for index, skin in ipairs ( skins ) do 
    local row = guiGridListAddRow ( skinsgrid ) 
    guiGridListSetItemText ( skinsgrid, row, _skins, tostring ( skin ), false, false ) 
end 
  
addEventHandler ( "onClientGUIClick", guiRoot, 
    function ( ) 
        if ( source == takebtn ) then 
            local row, col = guiGridListGetSelectedItem ( skinsgrid ) 
            if ( row and col and row ~= -1 and col ~= -1 ) then 
                local skinName = guiGridListGetItemText ( skinsgrid, row, 1 ) 
                if ( skinName == "Bus Driver 1 (skin: 253)" ) then 
                    triggerServerEvent ( "setBUS", localPlayer, 253 ) 
                elseif ( skinName == "Bus Driver 2 (skin: 255)" ) then 
                    triggerServerEvent ( "setBUS", localPlayer, 255 ) 
                end 
                guiSetVisible ( windowjob, false ) 
                showCursor ( false ) 
            else 
                outputChatBox ( "Please, select a skin of the list.", 255, 0, 0 ) 
            end 
        elseif ( source == closebtn ) then 
            guiSetVisible ( windowjob, false ) 
            showCursor ( false ) 
        end 
    end 
) 
  
function BUSjob ( hitElement ) 
    if ( getElementType ( hitElement ) == "player" ) and ( hitElement == localPlayer ) then 
        if ( not guiGetVisible ( windowjob ) ) then 
            guiSetVisible ( windowjob, true ) 
            showCursor ( true ) 
        end 
    end 
end 
addEventHandler ( "onClientMarkerHit", marker0, BUSjob ) 
  
function BUSjobleave ( leaveElement ) 
     if ( getElementType ( leaveElement ) == "player" ) and ( leaveElement == localPlayer ) then 
        if guiGetVisible ( windowjob ) then 
            guiSetVisible ( windowjob, false ) 
            showCursor ( false ) 
        end 
    end 
end 
addEventHandler ( "onClientMarkerLeave", marker0, BUSjobleave ) 
  
addEvent ( "bus_set_location", true ) 
addEventHandler ( "bus_set_location", root, 
    function ( x, y, z ) 
        marker = createMarker ( x, y, z - 1, "cylinder", 3.5, 255, 255, 0, 170 ) 
        blip = createBlipAttachedTo ( marker, 51 ) 
        addEventHandler ( "onClientMarkerHit", marker, onBusStopHit ) 
    end 
) 
  
function onBusStopHit ( hitPlayer ) 
    if ( getElementType ( hitPlayer ) == "player" ) and ( hitPlayer == localPlayer ) then 
        triggerServerEvent ( "bus_finish", localPlayer ) 
        if isElement ( blip ) then 
            destroyElement ( blip ) 
        end 
        if isElement ( marker ) then 
            removeEventHandler ( "onClientMarkerHit", marker, onBusStopHit ) 
            destroyElement ( marker ) 
        end 
    end 
end 
  
addEventHandler ( "onClientVehicleExit", root, 
    function ( thePlayer ) 
        if ( thePlayer == localPlayer ) then 
            if isElement ( blip ) then 
                destroyElement ( blip ) 
            end 
            if isElement ( marker ) then 
                removeEventHandler ( "onClientMarkerHit", marker, onBusStopHit ) 
                destroyElement ( marker ) 
            end 
        end 
    end 
) 

-- server side:

local busses = 
    { 
        [ 431 ] = true, 
        [ 437 ] = true 
    } 
local busSkins = 
    { 
        [ 255 ] = true, 
        [ 253 ] = true 
    } 
  
local busTable = 
    { 
        { 1743.1, -1857.6, 12.4 }, 
        { 1043.1, -1983.7, 11.9 }, 
        { 1670.9, -2251.2, 12.4 }, 
        { 1277.2, -2053.4, 57.8 }, 
        { 1478.3, -1729.5, 12.4 }, 
        { 1467.9, -1157.9, 22.7 }, 
        { 1787, -1175.7, 22.5 }, 
        { 1854.2, -1394.7, 12.4 }, 
        { 2227.4, -1381.3, 22.8 }, 
        { 2740.5, -1447.3, 29.3 }, 
        { 2160.2, -1001.7, 61.1 }, 
        { 1990.1, -1355.8, 22.8 }, 
        { 1436.1, -1437.7,12.4 }, 
        { 659.5, -1392.1, 12.6 }, 
        { 358.1, -1649.4, 31.6 }, 
        { 206.3, -1464, 11.9 }, 
        { 442, -1235.5, 48.6 }, 
        { 1394.3, -934, 34.5 }, 
        { 2182.6, -1104.7, 23.9 }, 
        { 2819.9, -2034.2, 10 }, 
        { 2215.2, -1908.8, 12.4 }, 
        { 1818.6, -1907.8, 12.4 }, 
        { 2115.7, -1481.2, 22.8 }, 
        { 2091.7, -1764.8, 12.4 }, 
        { 2332.1, -1969.7, 12.1 }, 
        { 2468.6, -1729.2, 12.4 }, 
        { 2532.6, -1924.4, 12.4 }, 
        { 2766.5, -1952.1, 12.4 }, 
        { 2514.8, -1296.6, 33.7 }, 
        { 1065.1, -1568.9, 12.1 }, 
        { 673.2, -1583.6, 12.8 }, 
        { 527, -1544.2, 13.8 } 
    } 
  
function getRandombusTable ( ) 
    return unpack ( busTable [ math.random ( #busTable ) ] ) 
end 
  
function createbusTeam ( ) 
    theTeam = createTeam ( "Bus Drivers", 218, 134, 32 ) 
end 
addEventHandler ( "onResourceStart", resourceRoot, createbusTeam ) 
  
addEventHandler ( "onVehicleStartEnter", root, 
    function ( player, seat, jacked, door ) 
        if ( busses [ getElementModel ( source ) ] ) and ( not busSkins [ getElementModel ( player ) ] ) and ( seat == 0 ) then 
            cancelEvent ( ) 
        end 
    end 
) 
  
function joinBUS ( skin ) 
    setPlayerTeam ( source, theTeam ) 
    setElementModel ( source, skin ) 
    setElementData ( source, "Occupation", "Bus Drivers", true ) 
end 
addEvent ( "setBUS", true ) 
addEventHandler ( "setBUS", root, joinBUS ) 
  
function getNewBusLocation ( thePlayer ) 
    local x, y, z = getRandombusTable ( ) 
    triggerClientEvent ( thePlayer, "bus_set_location", thePlayer, x, y, z ) 
end 
  
function onVehicleEnter ( thePlayer ) 
    if ( not busses [ getElementModel ( source ) ] ) then 
        return 
    end 
  
    if ( not getPlayerTeam ( thePlayer ) ) then 
        return 
    end 
  
    if ( getTeamName ( getPlayerTeam ( thePlayer ) ) == "Bus Drivers" ) then 
        getNewBusLocation ( thePlayer ) 
    end 
end 
addEventHandler ( "onVehicleEnter", root, onVehicleEnter ) 
  
addEvent ( "bus_finish", true ) 
addEventHandler("bus_finish", root, 
    function ( ) 
        if ( not isPedInVehicle ( source ) ) then 
            return 
        end 
  
        local vehicle = getPedOccupiedVehicle ( source ) 
        if ( not busses [ getElementModel ( vehicle ) ] ) then 
            return 
        end 
  
        local money = math.random ( 150, 300 ) 
        givePlayerMoney ( source, money ) 
        setElementFrozen ( vehicle, true ) 
        fadeCamera ( source, false, 1, 0, 0, 0 ) 
        setTimer ( 
            function ( ) 
                fadeCamera ( source, true, 1 ) 
                setElementFrozen ( vehicle, false ) 
            end 
            ,1000, 1 
        ) 
        getNewBusLocation ( source ) 
    end 
) 

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