Jump to content

math.random. How use it without intervals


KM_Rose

Recommended Posts

Posted

Hi all.

I know how use this math.random , i'm using it on pickups for chage the skin

Example:

math.random ( 56, 60 )

(skins id 56...60)

But i want know if i can use it selecting independents skins:

For example: i don't want skins 56...60, i want random between skin: 56, skin:58 and skin: 60...

how could i use it??

some like this?? math.random ( 56. 58. 60 ) :(

Sorry my bad english, i use examples because i don't speak english so good...

some help?

Posted

Is easy. Use this:

local skinSelect = math.random(0,2) 
if skinSelect == 0 then 
 skin = 56 
elseif skinSelect == 1 then 
 skin = 58 
elseif skinSelect == 2 then 
 skin = 60 
end 
  
setPedSkin (ped,skin)--USE A PED ELEMENT! 

Posted

more efficient way:

  
allowedElements = { 56, 58, 60, 65, 67, 80, 91, 105 } 
  
random = allowedElements[math.random(1, #allowedElements)] 
setElementModel (ped, random) -- you should use it instead of setPedSkin ! 
  

Posted

setElementModel can be used not only on peds and players, but also on objects and vehicles. setPedSkin is deprecated.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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