Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
test
Schema = { rateItems = {} } local function CalcRateArray(array) local array_rates = {} local total_rate = 0 for _, v in ipairs(array) do array_rates[#array_rates + 1] = v[2] total_rate = total_rate + v[2] end array_rates[0] = total_rate for idx = 1, #array_rates do array_rates[idx] = array_rates[idx - 1] + array_rates[idx] / total_rate end Schema.total_rate = total_rate return array_rates end function Schema.GetRandomRateItems() local randf = math.random() for idx = 1, #Schema.rateItems do if (randf < Schema.rateItems[idx][2]) then return Schema.rateItems[idx][1] end end return false end local items = { ['Sword'] = 50, ['Bandage'] = 80, ['Apple'] = 95 } function InitializedPlugins() Schema.rateItems = {} for itemID, v in pairs(items) do Schema.rateItems[#Schema.rateItems + 1] = {itemID, v} end local array_rates = CalcRateArray(Schema.rateItems) for idx = 1, #array_rates do Schema.rateItems[idx] = {Schema.rateItems[idx][1], array_rates[idx]} end array_rates = nil end InitializedPlugins() for k, v in ipairs(Schema.rateItems) do print(k, v[1], v[2]) end
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Kegs Scores ... FOOOOOOTBALLLLLL
test
Lua Angle Cheatsheet
Lua Timer
Convert Large Item Amounts to Item Stacks in Minecraft
VERSION
Convert MySQL 'framed' table into CSV
5+5 == 10
مكسر
missing element
Please log in to post a comment.