Jump to content

How to make a mathrandom betwen some numbers


Axel

Recommended Posts

Posted

I do not know if you guys will understand me right so..

I want to make a mathrandom betwen 2,5 numbers. What i mean is not the numbers betwen the 2-5- i mean the 2 and 5 numbers. i used :

vehid = math.random(411,558) 
vehicle = createVehicle(vehid,0,0,-50) 

And it gives me some cars i don't want to(including heli)

Posted
idlist = { 411, 558, 423, 435 } -- table of your ids to select from 
vehid = idlist[math.random(#idlist)] 
vehicle = createVehicle(vehid,0,0,-50) 

Posted

Thanks, i tested and it works. I tryed once with {{154},{155}} and failed and i thought i can't do it like that..

Posted

Now i am trying it somewhere else and it does not work..

  
hookeridlist = { 85, 87, 85, 90, 152, 169, 178, 238, 244, 256, 257, 264, 68,} 
hookerids = hookeridlist[math.random(#hookeridlist)] 
  
addEvent("haveHookerJob",true) 
function haveHookerJob() 
setElementModel(source,hookerids) 
end 
addEventHandler("haveHookerJob",root,haveHookerJob) 

Posted

It is used in a job system.. when i click on the gui button it should change my skin to one of those random skins, but it does not..

Posted

maybe because it gets random skin only once, not every time "haveHookerJob" event is called.

you should move "hookerids = hookeridlist[math.random(#hookeridlist)]" line into the handler function.

Posted
  
hookeridlist = { 85, 87, 85, 90, 152, 169, 178, 238, 244, 256, 257, 264, 68,} 
  

->

  
hookeridlist = { 85, 87, 85, 90, 152, 169, 178, 238, 244, 256, 257, 264, 68} 
  

Posted
  
hookeridlist = { 85, 87, 85, 90, 152, 169, 178, 238, 244, 256, 257, 264, 68,} 
  

->

  
hookeridlist = { 85, 87, 85, 90, 152, 169, 178, 238, 244, 256, 257, 264, 68} 
  

no difference, lua allows commas there.

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...