Jump to content

Script Vehiculos


Sasu

Recommended Posts

Server:

markerp = createMarker( 1556.9852294922, -1608.1356201172, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
  marker2p = createMarker( 1570.1909179688, -1610.1462402344, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
  marker3p = createMarker( 1584.61328125, -1608.2557373047, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
  marker4p = createMarker( 1595.1407470703, -1607.5220947266, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
  marker5p = createMarker( 1544.63916016, -1609.2932128906, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
     
    local vehicles = {} 
      
    function spawnVehP(id) 
    theTeam = getPlayerTeam( source ) 
    theTeamName = getTeamName( theTeam ) 
    if ( theTeamName == "Policia" ) or ( theTeamName == "F.B.I" ) then 
        local x, y, z = getElementPosition(source) 
        if isElement(vehicles[source]) then destroyElement(vehicles[source]) end 
        vehicles[source] = createVehicle(id, x + 1, y, z) 
        warpPedIntoVehicle(source, vehicles[source]) 
        else 
        outChatBox("Sólo los agentes de Policía, el FBI o Elite pueden obtener vehículos aquí!", source, 255, 0, 0) 
        end 
    end 
    addEvent("CreVehicle",true) 
    addEventHandler("CreVehicle", root, spawnVehP) 
      
    addEventHandler("onPlayerQuit", root, 
    function() 
         if isElement(vehicles[source]) then 
              destroyElement(vehicles[source]) 
              vehicles[source] = nil 
         end 
    end) 
     
    function showGUIp(hitPlayer) 
    setElementFrozen(source, true) 
triggerClientEvent (hitPlayer,"showGUI2p",getRootElement(),hitPlayer) 
end 
addEventHandler("onMarkerHit",markerp,showGUIp) 
  
    function showGUIp(hitPlayer) 
    setElementFrozen(source, true) 
triggerClientEvent (hitPlayer,"showGUI2p",getRootElement(),hitPlayer) 
end 
addEventHandler("onMarkerHit",marker2p,showGUIp) 
  
    function showGUIp(hitPlayer) 
    setElementFrozen(source, true) 
triggerClientEvent (hitPlayer,"showGUI2p",getRootElement(),hitPlayer) 
end 
addEventHandler("onMarkerHit",marker3p,showGUIp) 
  
    function showGUIp(hitPlayer) 
    setElementFrozen(source, true) 
triggerClientEvent (hitPlayer,"showGUI2p",getRootElement(),hitPlayer) 
end 
addEventHandler("onMarkerHit",marker4p,showGUIp) 
  
    function showGUIp(hitPlayer) 
    setElementFrozen(source, true) 
triggerClientEvent (hitPlayer,"showGUI2p",getRootElement(),hitPlayer) 
end 
addEventHandler("onMarkerHit",marker5p,showGUIp) 

Client:

Wnd = guiCreateWindow ( 0.2, 0.2, 0.25, 0.5, "Vehiculos Policiales", true ) 
guiSetAlpha( Wnd, 1 ) 
button = guiCreateButton ( 0.01, 0.8, 0.99, 0.15, "Cerrar", true, Wnd ) 
label = guiCreateLabel ( 0.1, 0.1, 0.9, 0.1, "Double click para obtener un vehiculo", true, Wnd ) 
showCursor(false) 
guiSetVisible( Wnd, false ) 
guiWindowSetSizable( Wnd, false ) 
guiWindowSetMovable( Wnd, false ) 
  
    vehicles = 
            { 
            {"HPV1000", 523}, 
            {"Police LS", 596}, 
            {"Police LV", 598}, 
            {"Police Ranger", 599}, 
            } 
      
    grid = guiCreateGridList(0.01, 0.2, 0.99, 0.5, true, Wnd) 
    guiGridListAddColumn(grid, "Vehicles", 0.85) 
      
    for i,veh in ipairs(vehicles) do 
         row = guiGridListAddRow(grid) 
         -- 
         guiGridListSetItemText(grid, row, 1, tostring(veh[1]), false, false) 
         guiGridListSetItemData(grid, row, 1, tostring(veh[2])) 
    end 
      
    function use() 
         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("CreVehicle", localPlayer, model) 
              end 
         end 
    end 
    addEventHandler("onClientDoubleClick", root, use, true) 
     
    function close() 
    if (source == button) then 
    guiSetVisible(Wnd,false) 
    showCursor(false) 
    end 
    end 
    addEventHandler("onClientGUIClick", button, close) 
     
function showGUI2p() 
guiSetVisible(Wnd,true) 
showCursor(true) 
end 
addEvent("showGUI2p",true) 
addEventHandler("showGUI2p", getRootElement(), showGUI2p) 

Que esta mal en esto. Intento pero no me sale. Lo que pasa es que cuando elijo un vehiculo(policia) no me aparece nada. Alguien que me pueda ayudar a corregir.

Link to comment

lo e testeado funciona bien , espero averte ayudado tambien habia un error en el outputChatBox no salia la frase ya lo aregle tambien...

server

    markerp = createMarker( 1556.9852294922, -1608.1356201172, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
      marker2p = createMarker( 1570.1909179688, -1610.1462402344, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
      marker3p = createMarker( 1584.61328125, -1608.2557373047, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
      marker4p = createMarker( 1595.1407470703, -1607.5220947266, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
      marker5p = createMarker( 1544.63916016, -1609.2932128906, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
  
  
        local vehicles = {} 
          
        function spawnVehP(id) 
        theTeam = getPlayerTeam( source ) 
        theTeamName = getTeamName( theTeam ) 
        if ( theTeamName == "Policia" ) or ( theTeamName == "F.B.I" ) then 
            local x, y, z = getElementPosition(source) 
            if isElement(vehicles[source]) then destroyElement(vehicles[source]) end 
            vehicles[source] = createVehicle(id, x + 1, y, z) 
            warpPedIntoVehicle(source, vehicles[source]) 
            else 
             outputChatBox("Solo los agentes de Policia, el FBI o Elite pueden obtener vehiculos aqui!", source, 255, 0, 0 , true) 
            end 
        end 
        addEvent("CreVehicle",true) 
        addEventHandler("CreVehicle", root, spawnVehP) 
          
        addEventHandler("onPlayerQuit", root, 
        function() 
             if isElement(vehicles[source]) then 
                  destroyElement(vehicles[source]) 
                  vehicles[source] = nil 
             end 
        end) 
        
        function showGUIp(hitPlayer) 
        setElementFrozen(source, true) 
    triggerClientEvent (hitPlayer,"showGUI2p",getRootElement(),hitPlayer) 
    end 
    addEventHandler("onMarkerHit",markerp,showGUIp) 
      
        function showGUIp(hitPlayer) 
        setElementFrozen(source, true) 
    triggerClientEvent (hitPlayer,"showGUI2p",getRootElement(),hitPlayer) 
    end 
    addEventHandler("onMarkerHit",marker2p,showGUIp) 
      
        function showGUIp(hitPlayer) 
        setElementFrozen(source, true) 
    triggerClientEvent (hitPlayer,"showGUI2p",getRootElement(),hitPlayer) 
    end 
    addEventHandler("onMarkerHit",marker3p,showGUIp) 
      
        function showGUIp(hitPlayer) 
        setElementFrozen(source, true) 
    triggerClientEvent (hitPlayer,"showGUI2p",getRootElement(),hitPlayer) 
    end 
    addEventHandler("onMarkerHit",marker4p,showGUIp) 
      
        function showGUIp(hitPlayer) 
        setElementFrozen(source, true) 
    triggerClientEvent (hitPlayer,"showGUI2p",getRootElement(),hitPlayer) 
    end 
    addEventHandler("onMarkerHit",marker5p,showGUIp) 

client

    Wnd = guiCreateWindow ( 0.2, 0.2, 0.25, 0.5, "Vehiculos Policiales", true ) 
    guiSetAlpha( Wnd, 1 ) 
    button = guiCreateButton ( 0.01, 0.8, 0.99, 0.15, "Cerrar", true, Wnd ) 
    label = guiCreateLabel ( 0.1, 0.1, 0.9, 0.1, "Double click para obtener un vehiculo", true, Wnd ) 
    showCursor(false) 
    guiSetVisible( Wnd, false ) 
    guiWindowSetSizable( Wnd, false ) 
    guiWindowSetMovable( Wnd, false ) 
      
             vehicles = 
                { 
                {"HPV1000", 523}, 
                {"Police LS", 596}, 
                {"Police LV", 598}, 
                {"Police Ranger", 599} 
                } 
                 
      
        grid = guiCreateGridList(0.01, 0.2, 0.99, 0.5, true, Wnd) 
        guiGridListAddColumn(grid, "Vehicles", 0.85) 
          
        for i,veh in ipairs(vehicles) do 
             row = guiGridListAddRow(grid) 
             -- 
             guiGridListSetItemText(grid, row, 1, tostring(veh[1]), false, false) 
             guiGridListSetItemData(grid, row, 1, tostring(veh[2])) 
        end 
          
        function use() 
             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("CreVehicle", localPlayer, model) 
                  end 
             end 
        end 
        addEventHandler("onClientDoubleClick", root, use, true) 
        
        function close() 
        if (source == button) then 
        guiSetVisible(Wnd,false) 
        showCursor(false) 
        end 
        end 
        addEventHandler("onClientGUIClick", button, close) 
        
    function showGUI2p() 
    guiSetVisible(Wnd,true) 
    showCursor(true) 
    end 
    addEvent("showGUI2p",true) 
    addEventHandler("showGUI2p", getRootElement(), showGUI2p) 

Link to comment
En vez de crear una funcion para cada marker, podrias usar una misma funcion para todos los markers.

Perdona solidsnake me intereso eso que dijiste , serial ago asi ?

      markerp = createMarker( 1556.9852294922, -1608.1356201172, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
      marker2p = createMarker( 1570.1909179688, -1610.1462402344, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
      marker3p = createMarker( 1584.61328125, -1608.2557373047, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
      marker4p = createMarker( 1595.1407470703, -1607.5220947266, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
      marker5p = createMarker( 1544.63916016, -1609.2932128906, 12.3828125, "cylinder", 2, 0, 0, 255, 255 ) 
  
  
        local vehicles = {} 
          
        function spawnVehP(id) 
        theTeam = getPlayerTeam( source ) 
        theTeamName = getTeamName( theTeam ) 
        if ( theTeamName == "Policia" ) or ( theTeamName == "F.B.I" ) then 
            local x, y, z = getElementPosition(source) 
            if isElement(vehicles[source]) then destroyElement(vehicles[source]) end 
            vehicles[source] = createVehicle(id, x + 1, y, z) 
            warpPedIntoVehicle(source, vehicles[source]) 
            else 
             outputChatBox("Solo los agentes de Policia, el FBI o Elite pueden obtener vehiculos aqui!", source, 255, 0, 0 , true) 
            end 
        end 
        addEvent("CreVehicle",true) 
        addEventHandler("CreVehicle", root, spawnVehP) 
          
        addEventHandler("onPlayerQuit", root, 
        function() 
             if isElement(vehicles[source]) then 
                  destroyElement(vehicles[source]) 
                  vehicles[source] = nil 
             end 
        end) 
        
        function showGUIp(hitPlayer) 
        setElementFrozen(source, true) 
    triggerClientEvent (hitPlayer,"showGUI2p",getRootElement(),hitPlayer) 
end 
    addEventHandler("onMarkerHit",markerp,showGUIp) 
    addEventHandler("onMarkerHit",marker2p,showGUIp) 
    addEventHandler("onMarkerHit",marker3p,showGUIp) 
    addEventHandler("onMarkerHit",marker4p,showGUIp) 
    addEventHandler("onMarkerHit",marker5p,showGUIp) 

Link to comment
  • Recently Browsing   0 members

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