1

I'm taking all my friend's weapon stats list for an RP he's running and turning it into a generator, but I'm having issues excluding certain values based on others. For example, I don't want a secondary auto rifle. Is there a way I can exclude certain values based on another output?

local myclasses = { 'Primary', 'Secondary', 'Heavy' }
local myprimaries = { 'Auto Rifle', 'Scout Rifle', 'Pulse Rifle', 'Sniper     Rifle', 'Hand Cannon' }
local mysecondaries = { 'Shotgun', 'Sidearm', 'SMG/SEG' }
print( myclasses[ math.random(#myclasses) ] )
if 'Primary' then
  print( myprimaries[ math.random(#myprimaries) ] )
elseif 'Secondary' then
  print( mysecondaries[ math.random(#mysecondaries) ] )
end

1 Answer 1

3

The problem is with the condition:

if 'Primary' then

will always evaluated as true, because any value evaluated as true except false and nil.

What you want is:

local rand_class = myclasses[math.random(#myclasses)]
print(rand_class)
if rand_class == 'Primary' then
  print( myprimaries[math.random(#myprimaries)] )
elseif rand_class == 'Secondary' then
  print( mysecondaries[math.random(#mysecondaries)] )
end

And don't forget to seed the random.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.