GetRandomVehicle

From Multi Theft Auto: Wiki
Revision as of 12:05, 10 June 2016 by Abdul KariM (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Syntax

vehicle getRandomVehicle (  )


Returns

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


Code

Click to collapse [-]
Server- and/or clientside Script

[lua]

   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

</syntaxhighlight>


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