GetRandomVehicle: Difference between revisions
Jump to navigation
Jump to search
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...") |
Abdul KariM (talk | contribs) (→Code) |
||
Line 8: | Line 8: | ||
==Code== | ==Code== | ||
< | <syntaxhighlight lang="lua"> | ||
function getRandomVehicle ( ) | function getRandomVehicle ( ) | ||
Line 27: | Line 26: | ||
return Table[ math.random ( #Table ) ] | return Table[ math.random ( #Table ) ] | ||
end | end | ||
</syntaxhighlight> | |||
</syntaxhighlight> | |||
==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