Jump to content

Que me falla


Arsilex

Recommended Posts

addCommandHandler( "nearbycars", 
    function( player, commandName ) 
        if hasObjectPermissionTo( player, "command.createshop", false ) or hasObjectPermissionTo( player, "command.deleteshop", false ) then 
            local x, y, z = getElementPosition( player ) 
            local dimension = getElementDimension( player ) 
            local interior = getElementInterior( player ) 
             
            outputChatBox( "Coches cercanos:", player, 255, 255, 0 ) 
            for key, value in pairs( vehicles ) do 
                if isElement( key ) and getElementDimension( key ) == dimension and getElementInterior( key ) == interior then 
                    local distance = getDistanceBetweenPoints3D( x, y, z, getElementPosition( key ) ) 
                    if distance < 20 then 
                        outputChatBox( "  Coches " .. value .. " - Cercanos: " .. tostring( vehicleID ) .. ".", player, 255, 255, 0 ) 
                    end 
                end 
            end 
        end 
    end 
) 

Link to comment
local vehicleIDs = { } 
local vehicles = { } 
  
addEventHandler( "onResourceStart", resourceRoot, 
    function( ) 
        -- Looking at it from a technical point of view, loading vehicles on a non-existant table makes only limited sense 
        if not exports.sql:create_table( 'vehicles',  
            { 
                { name = 'vehicleID', type = 'int(10) unsigned', auto_increment = true, primary_key = true }, 
                { name = 'model', type = 'int(10) unsigned' }, 
                { name = 'posX', type = 'float' }, 
                { name = 'posY', type = 'float' }, 
                { name = 'posZ', type = 'float' }, 
                { name = 'rotX', type = 'float' }, 
                { name = 'rotY', type = 'float' }, 
                { name = 'rotZ', type = 'float' }, 
                { name = 'interior', type = 'tinyint(3) unsigned', default = 0 }, 
                { name = 'dimension', type = 'int(10) unsigned', default = 0 }, 
                { name = 'respawnPosX', type = 'float' }, 
                { name = 'respawnPosY', type = 'float' }, 
                { name = 'respawnPosZ', type = 'float' }, 
                { name = 'respawnRotX', type = 'float' }, 
                { name = 'respawnRotY', type = 'float' }, 
                { name = 'respawnRotZ', type = 'float' }, 
                { name = 'respawnInterior', type = 'int(10) unsigned', default = 0 }, 
                { name = 'respawnDimension', type = 'int(10) unsigned', default = 0 }, 
                { name = 'numberplate', type = 'varchar(8)' }, 
                { name = 'health', type = 'int(10) unsigned', default = 1000 }, 
                { name = 'color1', type = 'tinyint(3) unsigned', default = 0 }, 
                { name = 'color2', type = 'tinyint(3) unsigned', default = 0 }, 
                { name = 'characterID', type = 'int(11)', default = 0 }, 
                { name = 'locked', type = 'tinyint(3) unsigned', default = 0 }, 
                { name = 'engineState', type = 'tinyint(3) unsigned', default = 0 }, 
                { name = 'lightsState', type = 'tinyint(3) unsigned', default = 0 }, 
                { name = 'tintedWindows', type = 'tinyint(3) unsigned', default = 0 }, 
                { name = 'fuel', type = 'float unsigned', default = 100 }, 
                { name = 'ruedas', type = 'int(10) unsigned' }, 
            } ) then cancelEvent( ) return end 
         
        -- load all vehicles 
        local result = exports.sql:query_assoc( "SELECT * FROM vehicles ORDER BY vehicleID ASC" ) 
        if result then 
            for key, data in ipairs( result ) do 
                local vehicle = createVehicle( data.model, data.posX, data.posY, data.posZ, data.rotX, data.rotY, data.rotZ, numberplate ) 
                 
                -- tables for ID -> vehicle and vehicle -> data 
                vehicleIDs[ data.vehicleID ] = vehicle 
                vehicles[ vehicle ] = { vehicleID = data.vehicleID, respawnInterior = data.respawnInterior, respawnDimension = data.respawnDimension, characterID = data.characterID, engineState = not doesVehicleHaveEngine( vehicle ) or data.engineState == 1, tintedWindows = data.tintedWindows == 1, fuel = data.fuel, ruedas = data.ruedas } 
                 
                -- some properties 
                setElementHealth( vehicle, data.health ) 
                if data.health <= 300 then 
                    setVehicleDamageProof( vehicle, true ) 
                    vehicles[ vehicle ].engineState = false 
                end 
                setVehicleColor( vehicle, data.color1, data.color2, data.color1, data.color2 ) -- most vehicles don't use second/third color anyway 
                setVehicleRespawnPosition( vehicle, data.respawnPosX, data.respawnPosY, data.respawnPosZ, data.respawnRotX, data.respawnRotY, data.respawnRotZ ) 
                setElementInterior( vehicle, data.interior ) 
                setElementDimension( vehicle, data.dimension ) 
                setVehicleLocked( vehicle, data.locked == 1 ) 
                setVehicleEngineState( vehicle, data.engineState == 1 ) 
                setVehicleOverrideLights( vehicle, data.lightsState + 1 ) 
                setElementData( vehicle, "fuel", data.fuel ) 
                getVehicleUpgrades( vehicle, data.ruedas == 1085 ) 
            end 
        end 
         
        -- bind a key for everyone 
        for key, value in ipairs( getElementsByType( "player" ) ) do 
            bindKey( value, "num_3", "down", "lockvehicle" ) 
            bindKey( value, "num_1", "down", "toggleengine" ) 
            bindKey( value, "num_2", "down", "togglelights" ) 
        end 
         
        -- 
         
        -- Fuel update 
        setTimer( 
            function( ) 
                for vehicle, data in pairs( vehicles ) do 
                    if not isElement( vehicle ) or getElementType( vehicle ) ~= "vehicle" then 
                        vehicles[ vehicle ] = nil 
                    elseif data.engineState and data.fuel and not isVehicleEmpty( vehicle ) and doesVehicleHaveEngine( vehicle ) and doesVehicleHaveFuel( vehicle ) then 
                        local vx, vy, vz = getElementVelocity( vehicle ) 
                        local speed = math.sqrt( vx * vx + vy * vy ) 
                        local loss = ( speed > 0.65 and 2 * speed or speed ) * 0.1 + 0.005 
                         
                        data.fuel = math.max( data.fuel - loss, 0 ) 
                        if math.floor( data.fuel + 0.5 ) ~= getElementData( vehicle, "fuel" ) then 
                            setElementData( vehicle, "fuel", math.floor( data.fuel + 0.5 ) ) 
                        end 
                         
                        if data.fuel == 0 then 
                            setVehicleEngineState( vehicle, false ) 
                            for seat = 0, getVehicleMaxPassengers( vehicle ) do 
                                local player = getVehicleOccupant( vehicle, seat ) 
                                if player then 
                                    triggerClientEvent( player, "gui:hint", player, "Sin gasolina", "Tu " .. getVehicleName( vehicle ) .. " No arranca sin gasolina!\nPara que no te vuelva a pasar esto recarga cada un tiempo.", 3 ) 
                                end 
                            end 
                        end 
                    end 
                end 
            end, 
            2000, 
            0 
        ) 
    end 
) 

me parece que alli es donde se define e.e

Link to comment
  • Recently Browsing   0 members

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