Jump to content

Duda con Aviones por nivel


Destroyer.-

Recommended Posts

Hola, tengo una duda estoy haciendo un piloto que vaya desbloqueando por cada nivel un nuevo avion, la cosa es que nose como hacerlo que desde una tabla me tome los niveles (tercer argumento de la tabla ) creo que con un for pero no estoy seguro

client

  
----Client Side------ 
  
    Window2 = guiCreateWindow ( 0.2, 0.2, 0.25, 0.5, "Spawn Medico", true ) 
    buttonmev = guiCreateButton ( 0.5, 0.8, 0.45, 0.15, "Close", true, Window2 ) 
    button2 = guiCreateButton ( 0.01, 0.8, 0.45, 0.15, "Spawn", true, Window2 ) 
    label2 = guiCreateLabel ( 0.1, 0.1, 0.9, 0.1, "Elige el Vehiculo", true, Window2 ) 
    showCursor(false) 
    guiSetVisible( Window2, false ) 
    guiWindowSetSizable( Window2, false ) 
  
vehicles2 = 
                { 
                {"Dodo LVL 0", 593, 0}, 
                {"Stuntplane LVL 40", 513, 40}, 
                {"Beagle LVL 100", 511, 100}, 
                {"Nevada LVL 150", 553, 150}, 
                {"Andromeda LVL 200", 592, 200}, 
                {"Shamal LVL 300", 519, 300}, 
                } 
          
        grid = guiCreateGridList(0.01, 0.2, 0.99, 0.5, true, Window2) 
        guiGridListAddColumn(grid, "Vehicles", 0.85) 
          
        for i,veh in ipairs(vehicles2) do 
             row = guiGridListAddRow(grid) 
             -- 
              
             guiGridListSetItemText(grid, row, 1, tostring(veh[1]), false, false) 
             guiGridListSetItemData(grid, row, 1, tostring(veh[2])) 
         
        end 
    function useMec() 
     
    nivel = tonumber((getElementData(source,"nivelp") or 1)) 
        local row, col = guiGridListGetSelectedItem(grid)   
        if (row and col and row ~= -1 and col ~= -1) then 
            local model = tonumber(guiGridListGetItemData(grid, row, 1)) 
            if model ~= "" then 
                triggerServerEvent("vehiclepiloto", localPlayer, model) 
                guiSetVisible(Window2,false) 
            showCursor(false) 
         
  
    end 
    end 
    end 
    addEventHandler("onClientGUIClick", button2, useMec, false) 
  
  

Server

  
function spawnVehPiloto(id) 
        local x, y, z = getElementPosition(source) 
        if isElement(vehicles2[source]) then destroyElement(vehicles2[source]) end 
        vehicles2[source] = createVehicle(id, x + 2, y, z) 
        warpPedIntoVehicle(source, vehicles2[source]) 
    end 
    addEvent("vehiclepiloto",true) 
    addEventHandler("vehiclepiloto", root, spawnVehPiloto) 
      
    addEventHandler("onPlayerQuit", root, 
    function() 
         if isElement(vehicles2[source]) then 
              destroyElement(vehicles2[source]) 
              vehicles2[source] = nil 
         end 
    end) 
  

Gracias :?

Link to comment

Claro que se puede, Usa un if para verificar si el jugador tiene ese nivel.

En vez de hacer el for fuera de alguna función, Podrías hacer que solo se añadan las cosas a la grid solo cuando se abra la gui así:

function abreguid(  ) 
    guiGridListClear(grid) 
    test() 
end 
function test(  ) 
    for i,veh in ipairs(vehicles2) do 
             row = guiGridListAddRow(grid) 
            local nivel = tonumber((getElementData(source,"nivelp") or 1)) 
            if veh[3] >= nivel then -- o usa == 
                guiGridListSetItemText(grid, row, 1, tostring(veh[1]), false, false) 
                guiGridListSetItemData(grid, row, 1, tostring(veh[2])) 
            end 
        end 
end 

No he testeado.

Link to comment
Claro que se puede, Usa un if para verificar si el jugador tiene ese nivel.

En vez de hacer el for fuera de alguna función, Podrías hacer que solo se añadan las cosas a la grid solo cuando se abra la gui así:

function abreguid(  ) 
    guiGridListClear(grid) 
    test() 
end 
function test(  ) 
    for i,veh in ipairs(vehicles2) do 
             row = guiGridListAddRow(grid) 
            local nivel = tonumber((getElementData(source,"nivelp") or 1)) 
            if veh[3] >= nivel then -- o usa == 
                guiGridListSetItemText(grid, row, 1, tostring(veh[1]), false, false) 
                guiGridListSetItemData(grid, row, 1, tostring(veh[2])) 
            end 
        end 
end 

No he testeado.

No me funciono no aparece ningun avion, igual lo que yo busco es que aparescan los aviones pero que no deje spawnearlos

Link to comment
  • Recently Browsing   0 members

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