Jump to content

Ayuda con math.random


Arsilex

Recommended Posts

hola queria saber si me puden ayudar con un problema con math.random

tengo el siguente script

addEventHandler ( 'onClientResourceStart', resourceRoot, 
    function ( ) 
        for _, car in ipairs ( getElementsByType 'vehicle' ) do 
           Color1 = setVehicleColor ( car,   128, 255, 0 ); 
           Color2 = setVehicleColor ( car,   43, 25, 255 ); 
        end 
    end 
) 

lo que quero que al empezar un mapa DM/DD se pongan esos dos colores a los coches usando math.random

si me pueden ayudar les estaria muy agradecido gracias por adelantado

Link to comment

-- server side:

local colors = 
    { 
        { 128, 255, 0 }, 
        { 43, 25, 255 } 
    } 
  
addEventHandler ( 'onResourceStart', resourceRoot, 
    function ( ) 
        for _, car in ipairs ( getElementsByType 'vehicle' ) do 
           setVehicleColor ( car, unpack ( colors[ math.random ( #colors ) ] ) ) 
        end 
    end 
) 

Link to comment
local colors = 
    { 
        { 128, 255, 0 }, 
        { 43, 25, 255 } 
    } 
addEvent ( 'onMapStarting', true ) 
addEventHandler ( 'onMapStarting', root, 
    function ( ) 
        for _, car in ipairs ( getElementsByType 'vehicle' ) do 
           setVehicleColor ( car, unpack ( colors[ math.random ( #colors ) ] ) ) 
        end 
    end 
) 

Link to comment

Talvez es porque los vehiculos aun no estan creados, usa esto:

local colors = 
    { 
        { 128, 255, 0 }, 
        { 43, 25, 255 } 
    } 
addEventHandler ( 'onVehicleEnter', root, 
    function ( ) 
        setVehicleColor ( source, unpack ( colors[ math.random ( #colors ) ] ) ) 
    end 
) 

Link to comment

--server-side

local colors = 
    { 
        { 128, 255, 0 }, 
        { 43, 25, 255 }, 
        { 255, 2, 255 }, 
        { 0, 255, 247 }, 
        { 201, 255, 0 }, 
        { 255, 0, 0 }, 
        { 0, 81, 255 }, 
        { 252, 255, 36 }, 
        { 87, 16, 154 }, 
        { 255, 94, 0 } 
    } 
  
addEventHandler ( 'onVehicleEnter', root, 
    function ( ) 
        setVehicleColor ( source, unpack ( colors[ math.random ( #colors ) ] ) ) 
    end 
) 

--meta

     "AsuS" description="changes car color " version="1" type="script" />  
     

Link to comment

Claro que no va a funcionar con eso, porque no entras en un vehiculo, cambia el modelo nada mas, usa esto:

local colors = 
    { 
        { 128, 255, 0 }, 
        { 43, 25, 255 }, 
        { 255, 2, 255 }, 
        { 0, 255, 247 }, 
        { 201, 255, 0 }, 
        { 255, 0, 0 }, 
        { 0, 81, 255 }, 
        { 252, 255, 36 }, 
        { 87, 16, 154 }, 
        { 255, 94, 0 } 
    } 
  
addEventHandler ( 'onVehicleEnter', root, 
    function ( ) 
        setVehicleColor ( source, unpack ( colors[ math.random ( #colors ) ] ) ) 
    end 
) 
  
addEvent ( "onPlayerPickUpRacePickup", true ) 
addEventHandler ( "onPlayerPickUpRacePickup", root, 
    function ( pickupID, pickupType, vehicleModel ) 
        if ( pickupType == "vehiclechange" ) then 
            local theVehicle = getPedOccupiedVehicle ( source ) 
            setVehicleColor ( theVehicle, unpack ( colors[ math.random ( #colors ) ] ) ) 
        end 
    end 
) 

Link to comment
  • Recently Browsing   0 members

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