GetRandomVehicle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "==Syntax== <syntaxhighlight lang="lua">vehicle getRandomVehicle ( )</syntaxhighlight> ===Returns=== Returns math.random Vehicle From Table if it was Argument true , And vice false ==Code== <sectio...")
 
Line 8: Line 8:


==Code==
==Code==
<section name="Server- and/or clientside Script" class="both" show="true">
<syntaxhighlight lang="lua">
[lua]
     function getRandomVehicle (  )
     function getRandomVehicle (  )
   
   
Line 27: Line 26:
     return Table[ math.random ( #Table ) ]
     return Table[ math.random ( #Table ) ]
     end
     end
</syntaxhighlight>
</syntaxhighlight></section>
 
 


==Example==
==Example==

Revision as of 12:06, 10 June 2016

Syntax

vehicle getRandomVehicle (  )


Returns

Returns math.random Vehicle From Table if it was Argument true , And vice false


Code

    function getRandomVehicle (  )
 
    local Table = { }
 
    for i , v in ipairs ( getElementsByType ( "vehicle" ) ) do
 
    table.insert ( Table , v )
 
    end
   
    if #Table == 0 then error "Server Not Vehicle"
 
    return false
 
        end 
    return Table[ math.random ( #Table ) ]
    end

Example

This example Warp player into Random Vehicle

addCommandHandler("WarpVeh",
 
    function ( p )
 
    Veh = getRandomVehicle (   )
 
    if Veh then
 
    warpPedIntoVehicle ( p , Veh )
 
    end
end
    ) ;
   
-- F8 Say : WarpVeh


Example 2

This example blow Random Vehicle

addCommandHandler("blowVeh",
 
    function ( p )
 
    Veh = getRandomVehicle (   )
 
    if Veh then
 
    blowVehicle ( Veh )
 
    end
end
    ) ; 
 
--F8 Say : blowVeh

Example 3

This example outputChatBox get name Vehicle Random

outputChatBox ( getVehicleName ( getRandomVehicle (   ) ) )

Author: Abdul_KariM

skype : kreee89