2015-07-13 616 views
1

我把我所有的朋友的武器統計列表中的一個RP運行並將其轉換爲一個生成器,但我遇到的問題排除了基於其他值的問題。例如,我不想要輔助自動步槍。有沒有一種方法可以根據另一個輸出排除某些值?從表中選擇一個隨機值,基於另一個隨機值

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 

回答

3

問題是與條件:

if 'Primary' then 

將賦值爲真,因爲任何價值判斷爲真時,除了falsenil

你想要的是:

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 

而且不要忘了種子隨機。

+0

會做。萬分感謝。 – Ruckified