Jump to content

Ayuda Spawn Bike


Infarto

Recommended Posts

Intenta Así

Client side:

local marker1 = createMarker(1183.80, -1311.5, 12.60, 'cylinder', 3, 48, 150, 214, 140) 
  
local markers = {marker1} 
  
local vehicles = {"BMX", "Bike", "Mountain bike", "Faggio"} 
  
function createVehGui () 
    MainGui = guiCreateWindow(408,203,240,349,"Bikes",false) 
    guiWindowSetSizable ( MainGui, false ) 
    VehGrid = guiCreateGridList(14,32,180,256,false,MainGui) 
    guiGridListSetSelectionMode(VehGrid,2) 
    _bikes = guiGridListAddColumn(VehGrid,"Elige",0.85) 
    Spawn = guiCreateButton(15,305,96,35,"Aceptar",false,MainGui) 
    guiSetFont(Spawn,"clear-normal") 
    Cancel = guiCreateButton(128,305,96,35,"Salir",false,MainGui) 
    guiSetFont(Cancel,"clear-normal") 
    for index, vehicle in ipairs(vehicles) do 
        local row = guiGridListAddRow (VehGrid) 
        guiGridListSetItemText ( VehGrid, row, _bikes, tostring(vehicle), false, false ) 
    end 
end 
  
for i,marker in ipairs ( markers ) do 
addEventHandler ( "onClientMarkerHit", marker, 
    function ( hitElement ) 
        if ( hitElement == localPlayer ) then 
              if getElementType( hitElement ) == "player" and not isPedInVehicle(hitElement) then 
                createVehGui ( hitElement ) 
                if ( MainGui ~= nil ) then 
                    guiSetVisible ( MainGui, true ) 
                    showCursor ( true ) 
                    guiSetInputEnabled ( true ) 
                    setElementFrozen ( hitElement, false ) 
                end 
        end 
    end 
end 
) 
end 
  
addEventHandler("onClientGUIClick", root,  
function () 
        if (source == Spawn) then 
            local row,col = guiGridListGetSelectedItem(VehGrid) 
            if (row and col and row ~= -1 and col ~= -1) then 
                local vehicleName = guiGridListGetItemText(VehGrid, row, 1) 
                if vehicleName == "BMX" then 
                    triggerServerEvent("spawnvehicle",localPlayer,481) 
                elseif vehicleName == "Bike" then 
                    triggerServerEvent("spawnvehicle",localPlayer,509) 
                elseif vehicleName == "Mountain bike" then 
                    triggerServerEvent("spawnvehicle",localPlayer,510)  
                elseif vehicleName == "Faggio" then 
                    triggerServerEvent("spawnvehicle",localPlayer,462)  
                end 
            else 
                outputChatBox("Error: Please, select a vehicle of list.",255,0,0) 
            end 
            elseif (source == Cancel) then 
                triggerEvent("closeWindow", root ) 
        end 
end 
) 
  
addEventHandler("onClientGUIDoubleClick", root,  
function () 
        if ( source == VehGrid ) then 
                local row,col = guiGridListGetSelectedItem(VehGrid) 
            if (row and col and row ~= -1 and col ~= -1) then 
                local vehicleName = guiGridListGetItemText(VehGrid, row, 1) 
                if vehicleName == "BMX" then 
                    triggerServerEvent("spawnvehicle",localPlayer,481) 
                elseif vehicleName == "Bike" then 
                    triggerServerEvent("spawnvehicle",localPlayer,481) 
                elseif vehicleName == "Mountain bike" then 
                    triggerServerEvent("spawnvehicle",localPlayer,510)  
                elseif vehicleName == "Faggio" then 
                    triggerServerEvent("spawnvehicle",localPlayer,462)  
                end 
            end 
        end 
end 
) 
for i,marker in ipairs ( markers ) do 
addEventHandler("onClientMarkerLeave", marker, 
function () 
        triggerEvent("closeWindow", root ) 
end 
) 
end 
  
  
addEvent("closeWindow", true) 
addEventHandler("closeWindow", root,  
function () 
            guiSetVisible(MainGui, false) 
            showCursor(false) 
            guiSetInputEnabled(false) 
            setElementFrozen(localPlayer, false) 
end 
) 
  

Server side:

local vehicles = { } 
  
addEvent ( "spawnvehicle", true ) 
addEventHandler ( "spawnvehicle", root, 
    function ( vehID ) 
     if ( isElement ( vehicles [ source ] ) ) then 
            destroyElement ( vehicles [ source ] ) 
        end  
     vehicles [ source ] = createVehicle ( vehID, getElementPosition ( source ) ) 
        if ( vehicles [ source ] ) then 
            setVehicleColor ( vehicles [ source ], 255, 255, 255 ) 
        end 
      setTimer ( warpPedIntoVehicle, 200, 1, source, vehicles [ source ] ) 
        triggerClientEvent ( source, "closeWindow", root ) 
end 
) 

Link to comment
  • Recently Browsing   0 members

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