mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-27 17:43:53 +01:00
worldeditadditions.parse.chance: add API function
This commit is contained in:
parent
efd8a8682e
commit
4ec04c03b3
13
worldeditadditions/utils/parse/chance.lua
Normal file
13
worldeditadditions/utils/parse/chance.lua
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
--- Parses a chance value, and returns the 1-in-N value thereof.
|
||||||
|
-- @param str string The string to parse.
|
||||||
|
-- @returns number|nil The 1-in-N chance if parsing was successful, otherwise nil.
|
||||||
|
function worldeditadditions.parse.chance(str)
|
||||||
|
if tonumber(str) ~= nil then return tonumber(str) end
|
||||||
|
if str:sub(#str) == "%" then
|
||||||
|
local result = tonumber(str:sub(1, #str-1))
|
||||||
|
if result == nil then return nil end
|
||||||
|
return 1 / (result / 100) -- Convert percentage to 1-in-N chance
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
@ -1,5 +1,6 @@
|
|||||||
worldeditadditions.parse = {}
|
worldeditadditions.parse = {}
|
||||||
|
|
||||||
dofile(worldeditadditions.modpath.."/utils/parse/weighted_nodes.lua")
|
dofile(worldeditadditions.modpath.."/utils/parse/chance.lua")
|
||||||
dofile(worldeditadditions.modpath.."/utils/parse/map.lua")
|
dofile(worldeditadditions.modpath.."/utils/parse/map.lua")
|
||||||
dofile(worldeditadditions.modpath.."/utils/parse/seed.lua")
|
dofile(worldeditadditions.modpath.."/utils/parse/seed.lua")
|
||||||
|
dofile(worldeditadditions.modpath.."/utils/parse/weighted_nodes.lua")
|
||||||
|
Loading…
Reference in New Issue
Block a user