Jump to content

Porque no funciona?


Recommended Posts

Hola tengo este trabajo para mi server RPG de trucker! pues el trabajo deberia funcionar! su funcion seria esta! El jugador hace spawn en la clase camionero! y al subirse a un camion le deben salir varios blip en el mapa! donde podra ir a cojer una carga! una vez llegado al blip estara un marke pero ni salen los blips ni los marke... ¿Cual es el problema?

truckstation = {} 
truckstation[1]={2035.5, -2220.3, 12, 8, "Los Santos Airport"} -- LSA TRUCKPOINT
truckstation[2]={2275.7, 30.6, 25.5, 8, "Palomino Creek"} -- PALOMINO CREEK TRUCKPOINT
truckstation[3]={1349.8, 360.5, 18.5, 8, "Montgomery"} -- MONTGOMERY TRUCKPOINT
truckstation[4]={-128.3, -360.9, 0.5, 8, "Blueberry"} -- BLUEBERRY TRUCKPOINT
truckstation[5]={796.7, -606.6, 15.5, 8, "Dillimore"} -- DILLIMORE TRUCKPOINT
truckstation[6]={-2476.22, 786.53, 34, 8, "SupaSave - San Fierro"} -- SUPASAVE IN SF TRUCKPOINT
truckstation[7]={-1650.54,44.54,2, 8, "San Fierro Harbor"} -- SF TRUCKPOINT
truckstation[8]={-2265.2, 2316.1, 3.8, 8, "Bayside"} -- BAYSIDE TRUCKPOINT
truckstation[9]={-1264.1, 2701.7, 49.0, 8, "El Quebrados"} -- EL QUEBRADOS TRUCKPOINT
truckstation[10]={-221.3, 2601.5, 61.7, 8, "Las Payasadas"} -- LAS PAYASADAS TRUCKPOINT
truckstation[11]={-369.5, 2222.7, 41.5, 8, "E. C. Del Diablo"} -- EL CASTILLO DEL DIABLO TRUCKPOINT
truckstation[12]={-859.4, 1556.3, 23.0, 8, "Las Barrancas"} -- LAS BARRANCAS TRUCKPOINT
truckstation[13]={-33.8, 1174.9, 18.3, 8, "Fort Carson"} -- FORT CARSON TRUCKPOINT
truckstation[14]={270.9, 1411.2, 9.5, 8, "F.C. Oil Refinery"} -- FORT CARSON OILRAFFENERY TRUCKPOINT
truckstation[15]={829.7, 851.5, 11.0, 8, "Las Venturas Mine"} -- LV MINE TRUCKPOINT
truckstation[16]={-559.77, -78.13, 62, 8, "The Panopticon"} -- The Panopticon TRUCKPOINT
truckstation[17]={-1238.86, 17.28, 13, 8, "Easterbay Airport S.F."} -- SF AIRPORT TRUCKPOINT
truckstation[18]={-1904.44, -1718.3, 20, 8, "Angel Pine Junkyard"} -- ANGEL PINE JUNKYARD TRUCKPOINT
truckstation[19]={-1966.51, -2436.94, 29, 8, "Angel Pine Sawmill"} -- ANGEL PINE SAWMILL TRUCKPOINT
truckstation[20]={-2316.96,-1633.2, 482, 8, "Mount Chilliad"} -- Mount Chilliad Truckpoint
truckstation[21]={-1137.8, -1042.4, 127, 8, "The Truths Farm"} -- The Truths Farm Truckpoint
truckstation[22]={1367.25, -1637.54, 12, 8, "Commerce"} -- Commerce Truckpoint
truckstation[23]={2197.68, -2647.74, 13, 8, "Los Santos Docks"} -- LS Docks truckpoint
truckstation[24]={2773.09, -1609.98, 9, 8, "East Beach"} -- East Beach truckpoint
truckstation[25]={2819.34, 956.77, 9, 8, "Linden Side"} -- Linden side truckpoint
-- truckstation[26]={2789.12, 2598.15, 9, 8, "Creek"} -- Creek truckpoint(Removed due to it being in GJMC base)
truckstation[26]={1746.27, 2224.24, 9, 8, "Redsands West"} -- redsands west truckpoint
truckstation[27]={1074.25, 1877.63, 9, 8, "Whitewood Estates"} -- whitewood estates truckpoint
truckstation[28]={1419.32, 1053.19, 9, 8, "LVA Freight Depot"} -- LVA Depot truckpoint
truckstation[29]={-1285.53, 2494.01, 87.06, 8, "Aldea Malvada"} -- Teirra Roboda truckpoint
 
local trucks = {[403]=true,[514]=true,[515]=true}
 
transportation = {}
transportation[1] = {"Automobiles"}
transportation[2] = {"Food"}
transportation[3] = {"Drugs"}
transportation[4] = {"Parts"}
transportation[5] = {"Groceries"}
transportation[6] = {"Parcels"}
transportation[7] = {"Meat Products"}
transportation[8] = {"Stone"}
transportation[9] = {"Gravel"}
transportation[10] = {"Toys"}
transportation[11] = {"Clothing"}
transportation[12] = {"Immigrants"}
transportation[13] = {"Electronics"}
transportation[14] = {"Frozen Food"}
transportation[15] = {"Boxes"}
transportation[16] = {"Steel Cables"}
transportation[17] = {"Pallets"}
transportation[18] = {"Recycled Goods"}
transportation[19] = {"Woodchip"}
transportation[20] = {"Food For Jolardy"}
 
local trucker_save = 0
 
local truckAbleData = {["Camionero"]=true, ["All Load Trucking"]=true, ["Trucker"]=true}
 
local mission = 0
 
-- === TRUCKERGUI
truckerGUI = guiCreateWindow(0.2242,0.3369,0.5461,0.3594,"Estacion de Entregas - Panel",true)   guiSetAlpha(truckerGUI,1)   guiWindowSetSizable(truckerGUI,false)
truckergridlist = guiCreateGridList(0.0129,0.0734,0.9742,0.7908,true,truckerGUI)    guiGridListSetSelectionMode(truckergridlist,0)
    trucker_freight = guiGridListAddColumn(truckergridlist,"Carga",0.2)
    trucker_destination = guiGridListAddColumn(truckergridlist,"Destino",0.2)
    trucker_distance = guiGridListAddColumn(truckergridlist,"Distancia",0.2)
    trucker_money = guiGridListAddColumn(truckergridlist,"Dinero",0.2)
    trucker_illegal = guiGridListAddColumn(truckergridlist,"Ilegal",0.1)
trucker_acceptBTN = guiCreateButton(0.0157,0.8859,0.2804,0.0842,"Aceptar",true,truckerGUI)
trucker_closeBTN = guiCreateButton(0.7053,0.8859,0.2804,0.0842,"Cerrar",true,truckerGUI)
guiSetVisible(truckerGUI, false)
 
function truckerFunctions()
    if source == trucker_acceptBTN then
        local selected = guiGridListGetSelectedItem(truckergridlist)
        hideTruckStations()
        if selected >= 0 then
            local destination = guiGridListGetItemText(truckergridlist, selected, trucker_destination)
            local truckM = guiGridListGetItemText(truckergridlist, selected, trucker_money)
            local illegal = guiGridListGetItemText(truckergridlist, selected, trucker_illegal)
            if destination and destination ~= "" and truckM and truckM ~= "" then
                trucker_save = tonumber(truckM)
                for i, v in pairs(truckstation) do
                    if truckstation[i][5] == destination then
                        local marker = createMarker(truckstation[i][1], truckstation[i][2], truckstation[i][3], "cylinder", truckstation[i][4], 255, 100, 100, 30)  setElementData(marker, "trucker", true)
                        if isPedInVehicle(getLocalPlayer()) then
                            addEventHandler("onClientMarkerHit", marker, showTruckerGUI)
                            createBlipAttachedTo(marker, 42, 1)
                            triggerServerEvent("attachTrailerNow", getPedOccupiedVehicle(getLocalPlayer()), getLocalPlayer())
                            guiSetVisible(truckerGUI, false)   
                            showCursor(false)
                            if illegal == "Yes" then
                                triggerServerEvent("setTruckerWanted", getLocalPlayer(), getLocalPlayer())
                            end
                            break
                        end
                    end
                end
            end
        end
    end 
    if source == trucker_closeBTN then
        guiSetVisible(truckerGUI, false)
        showCursor(false)
        showTruckStations()
    end
end
addEventHandler("onClientGUIClick", trucker_acceptBTN, truckerFunctions)
addEventHandler("onClientGUIClick", trucker_closeBTN, truckerFunctions)
-- ===
 
addEventHandler("onClientPlayerVehicleExit", getLocalPlayer(), function(vehicle, seat)
    if truckAbleData[getElementData(source, "class")] then
        if (mission == 1) then
            if not isElement(colExitTruck) then
                local x,y,z = getElementPosition(vehicle)
                colExitTruck = createColTube(x, y, z-5, 50.0, 50.0)
               
                outputChatBox("Oh, Se a desprendido tu carga! no te alejes mucho o la perderas!", 0, 200, 0)
               
                colSaveTruck = createColTube(x, y, z-1.5, 1.53, 2.5)
                attachElements(colSaveTruck, vehicle, 0, 1.5, -1)
            end
            else
            hideTruckStations()
        end
    end
end)
 
addEventHandler("onClientPlayerVehicleEnter", getLocalPlayer(), function(vehicle, seat)
    if truckAbleData[getElementData(source, "class")] then
        if trucks[getElementModel(vehicle)] and seat == 0 then
            if (mission == 1) then
                if isElement(colExitTruck) and (trailerIsLost == false) then
                    if isElementWithinColShape(vehicle, colSaveTruck) then
                        destroyElement(colExitTruck)
                        destroyElement(colSaveTruck)
                        outputChatBox("Tu carga se perdera vuelva rapido!", 255, 255, 0)
                    else
                        abortMission()
                        destroyElement(colSaveTruck)
                        destroyElement(colExitTruck)
                        outputChatBox("Usted no está en el vehículo original en el que empezó. Misión abortada!", 255, 255, 0)
                    end
                end
                --hideTruckStations()
            else
                showTruckStations()
            end
        end
    end
end)
 
-- addEventHandler("onClientColShapeHit", getLocalPlayer(), function()
    -- if (colSaveTruck) then
        -- if (mission == 1) then
            -- destroyElement(colSaveTruck)
        -- end
    -- else
        -- abortMission()
        -- destroyElement(colSaveTruck)
        -- outputChatBox("You changed trucks! Mission aborted!", 255, 255, 0)
    -- end
-- end)
 
addEventHandler("onClientPlayerWasted", getLocalPlayer(), function()
    hideTruckStations()
    guiSetVisible(truckerGUI, false)    showCursor(false)
    if save_trailer then
        triggerServerEvent("killTrailer", save_trailer, localPlayer)   
        save_trailer = nil
    end
    if mission == 1 then
        abortMission()
    end
    hideTruckStations()
end)
 
addEventHandler("onClientPlayerQuit", getLocalPlayer(), function()
    if save_trailer then
        triggerServerEvent("killTrailer", save_trailer, localPlayer)
        save_trailer = nil
    end
end)
 
 
--=========== FUNCTIONS
function showTruckerGUI(trucker, dimension)
    if trucker == getLocalPlayer() and isPedInVehicle(getLocalPlayer()) and trucks[getElementModel(getPedOccupiedVehicle(getLocalPlayer()))] then
    trailer = nil
    local trailer = getVehicleTowedByVehicle(getPedOccupiedVehicle(getLocalPlayer()))
        if isPedInVehicle(localPlayer) then
            if mission == 1 and not trailer then
                if isElement(save_trailer) then
                    triggerServerEvent("destroyTrailerNow",save_trailer,localPlayer) save_trailer = nil
                    showTruckStations()
                end
            end
            if trailer and trailer == save_trailer then
                setTimer(fadeScreenOut, 2000, 1)
                fadeCamera(false,1)
                outputChatBox("Has entregado correctamente la entrega y que ganó $"..trucker_save, 255,255,255)
                exports.SAcommands:giveMoney(getLocalPlayer(),trucker_save)
                mission = 0
            elseif trailer then
                triggerServerEvent("destroyTrailerNow",trailer,localPlayer)
            elseif mission == 0 then
                triggerEvent("onClientGUIRequest",resourceRoot,"trucker.truckergui","Estacion de Entregas - Panel")
            end
            trucker_save = 0
            else
            outputChatBox("Debe estar en su camión para abrir el menú!", 0, 200, 0)
        end
    end
end
 
function fadeScreenOut()
    showTruckStations()
    triggerServerEvent("destroyTrailerNow",save_trailer,localPlayer)   
    save_trailer = nil
    fadeCamera(true, 1)
    triggerEvent("onClientGUIRequest",resourceRoot,"trucker.truckergui","Estacion de Entregas - Panel")
end
 
function showActualTruckerGUI (id)
    if isPedInVehicle(localPlayer) then
        if id == "trucker.truckergui" then
            fillTruckerList()
            guiSetVisible(truckerGUI, true) showCursor(true)
            setTimer(setElementFrozen, 500, 1, getPedOccupiedVehicle(getLocalPlayer()),true)
            setTimer(setElementFrozen, 1500, 1, getPedOccupiedVehicle(getLocalPlayer()),false)
        end
    end
end
addEventHandler("onClientGUIShow",resourceRoot,showActualTruckerGUI)
 
function fillTruckerList()
    guiGridListClear(truckergridlist)
    for i, place in pairs(truckstation) do
        local x, y, z = getElementPosition(getLocalPlayer())
        local distance = getDistanceBetweenPoints3D(x, y, z, truckstation[i][1], truckstation[i][2], truckstation[i][3])
        if distance > 50 then
            local distance = math.round(distance, 0, "ceil")
            local row = guiGridListAddRow(truckergridlist)
            if getDistanceBetweenPoints3D(x, y, z, truckstation[17][1], truckstation[17][2], truckstation[17][3]) < 20 then
                freight = "Drugs"
            else
                local number = math.random(1,20)
                freight = transportation[number][1]
           
Link to comment

Con 400 lineas de código, solo con el cliente, con tan pocos detalles del error y sin saber que arroja el debugscript es bastante complicado encontrar el bug. Yo por mas que lo miro no encuentro nada fuera de orden, sin contar la inmensidad de variables con la que funciona un trabajo. Por lo general yo hago una depuración del código haciendo salidas de texto para ver si una linea de código entra a una función cuando debería hacerlo, y desde ahí veo que hacer para solucionarlo.

Link to comment

Con 400 lineas de código, solo con el cliente, con tan pocos detalles del error y sin saber que arroja el debugscript es bastante complicado encontrar el bug. Yo por mas que lo miro no encuentro nada fuera de orden, sin contar la inmensidad de variables con la que funciona un trabajo. Por lo general yo hago una depuración del código haciendo salidas de texto para ver si una linea de código entra a una función cuando debería hacerlo, y desde ahí veo que hacer para solucionarlo.

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...