Imported from ContentDB ZIP
This commit is contained in:
commit
d5bad74e5c
0
modpack.txt
Normal file
0
modpack.txt
Normal file
1
treasurer
Submodule
1
treasurer
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 0ddcd5c545391785577cdb1566eace367b0019ed
|
2
trm_default_example/depends.txt
Normal file
2
trm_default_example/depends.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
treasurer
|
||||||
|
default
|
102
trm_default_example/init.lua
Normal file
102
trm_default_example/init.lua
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
--[[
|
||||||
|
This is an example Treasure Registration Mod (TRM) for the default mod.
|
||||||
|
It is meant to use together with the default mod and the treasurer mod.
|
||||||
|
|
||||||
|
This TRM registers a bunch of items found in the default mod.
|
||||||
|
|
||||||
|
Note that the probabilities may not be very well balanced,
|
||||||
|
this file is just there as an example. It, however, can
|
||||||
|
still be used in actual gameplay.
|
||||||
|
|
||||||
|
A TRM is really nothing more than a list of item names, probabilities,
|
||||||
|
preciousnesses, and optionally a given amount and tool wear.
|
||||||
|
The only function ever called is treasurer.register_treasure.
|
||||||
|
See also treasurer’s documentation for more info.
|
||||||
|
]]
|
||||||
|
|
||||||
|
--[[ The following entries all use a rarity value and a count value in range
|
||||||
|
format.
|
||||||
|
Note that the range format is a table with two value, the first being
|
||||||
|
the minimum and the second being the maximum value.
|
||||||
|
]]
|
||||||
|
--[[ The next entry means: this treasure consists of 1 to 10 gold ingots and has
|
||||||
|
a rarity of 0.01 and a preciousness of 7 (out of 10) ]]
|
||||||
|
treasurer.register_treasure("default:gold_ingot",0.01,7,{1,10})
|
||||||
|
-- The following entries are similar
|
||||||
|
treasurer.register_treasure("default:bronze_ingot",0.02,5,{1,16})
|
||||||
|
treasurer.register_treasure("default:copper_ingot",0.06,3,{1,17})
|
||||||
|
treasurer.register_treasure("default:steel_ingot",0.09,4,{1,20})
|
||||||
|
treasurer.register_treasure("default:clay_brick",0.1,5,{2,12})
|
||||||
|
treasurer.register_treasure("default:coal_lump",0.2,2,{3,10})
|
||||||
|
treasurer.register_treasure("default:obsidian_shard",0.05,5,{3,20})
|
||||||
|
treasurer.register_treasure("default:obsidian_shard",0.0005,5,{21,90})
|
||||||
|
treasurer.register_treasure("default:mese_crystal",0.008,9,{1,5})
|
||||||
|
treasurer.register_treasure("default:diamond",0.001,9,{1,3})
|
||||||
|
|
||||||
|
--[[ here is a constant (=non-random) count given
|
||||||
|
with a rarity of 0.0001, exactly 4 diamonds spawn]]
|
||||||
|
treasurer.register_treasure("default:diamond",0.0001,9,4)
|
||||||
|
|
||||||
|
-- an example of a treasure with preciousness of 10
|
||||||
|
treasurer.register_treasure("default:diamond_block",0.00002,10,1)
|
||||||
|
|
||||||
|
-- by the way, as you see, it is not forbidden to register the same item twice.
|
||||||
|
|
||||||
|
treasurer.register_treasure("default:paper",0.1,2,{3,6})
|
||||||
|
treasurer.register_treasure("default:stick",0.1,2,{1,15})
|
||||||
|
treasurer.register_treasure("default:stick",0.05,2,{16,33})
|
||||||
|
treasurer.register_treasure("default:book",0.1,4,{1,2})
|
||||||
|
|
||||||
|
treasurer.register_treasure("default:mese_crystal_fragment",0.01,3,{1,9})
|
||||||
|
treasurer.register_treasure("default:sapling",0.05,2,{1,20})
|
||||||
|
treasurer.register_treasure("default:junglesapling",0.03,3,{1,5})
|
||||||
|
treasurer.register_treasure("default:apple",0.2,2,{1,7})
|
||||||
|
|
||||||
|
treasurer.register_treasure("default:shovel_wood",0.02,2)
|
||||||
|
treasurer.register_treasure("default:shovel_stone",0.050,3)
|
||||||
|
treasurer.register_treasure("default:shovel_steel",0.07,5)
|
||||||
|
treasurer.register_treasure("default:shovel_bronze",0.006,6)
|
||||||
|
treasurer.register_treasure("default:shovel_mese",0.0012,8)
|
||||||
|
treasurer.register_treasure("default:shovel_diamond",0.0008,9)
|
||||||
|
|
||||||
|
treasurer.register_treasure("default:axe_wood",0.02,2)
|
||||||
|
treasurer.register_treasure("default:axe_stone",0.045,3)
|
||||||
|
treasurer.register_treasure("default:axe_steel",0.05,5)
|
||||||
|
treasurer.register_treasure("default:axe_bronze",0.005,6)
|
||||||
|
treasurer.register_treasure("default:axe_mese",0.0002,8)
|
||||||
|
treasurer.register_treasure("default:axe_diamond",0.000125,9)
|
||||||
|
|
||||||
|
--[[ Here are some examples for wear. wear is the 5th parameter
|
||||||
|
the format of wear is identical to the format of count
|
||||||
|
note that the 3rd parameter (count) is nil which causes the script to use the default value
|
||||||
|
We could as well have written an 1 here.
|
||||||
|
]]
|
||||||
|
treasurer.register_treasure("default:axe_wood",0.04,1,nil,{100,10000}) -- wear = randomly between 100 and 10000
|
||||||
|
treasurer.register_treasure("default:axe_stone",0.09,2,nil,{500,11000})
|
||||||
|
treasurer.register_treasure("default:axe_steel",0.1,4,nil,{600,18643})
|
||||||
|
treasurer.register_treasure("default:axe_bronze",0.01,5,nil,{750,20000})
|
||||||
|
treasurer.register_treasure("default:axe_mese",0.0002,7,nil,{1000,22000})
|
||||||
|
treasurer.register_treasure("default:axe_diamond",0.0001,8,nil,{2000,30000})
|
||||||
|
|
||||||
|
treasurer.register_treasure("default:pick_wood",0.005,2)
|
||||||
|
treasurer.register_treasure("default:pick_stone",0.018,3)
|
||||||
|
treasurer.register_treasure("default:pick_steel",0.02,5)
|
||||||
|
treasurer.register_treasure("default:pick_bronze",0.004,6)
|
||||||
|
treasurer.register_treasure("default:pick_mese",0.008,8)
|
||||||
|
treasurer.register_treasure("default:pick_diamond",0.005,9)
|
||||||
|
|
||||||
|
treasurer.register_treasure("default:sword_wood",0.001,2)
|
||||||
|
treasurer.register_treasure("default:sword_stone",0.016,3)
|
||||||
|
treasurer.register_treasure("default:sword_steel",0.02,5)
|
||||||
|
treasurer.register_treasure("default:sword_bronze",0.015,6)
|
||||||
|
treasurer.register_treasure("default:sword_mese",0.007,8)
|
||||||
|
treasurer.register_treasure("default:sword_diamond",0.0035,9)
|
||||||
|
|
||||||
|
treasurer.register_treasure("default:rail",0.01,5,15)
|
||||||
|
treasurer.register_treasure("default:rail",0.02,5,{1,5})
|
||||||
|
treasurer.register_treasure("default:fence_wood",0.1,4,{1,7})
|
||||||
|
|
||||||
|
-- If the count is omitted, it deaults to 1.
|
||||||
|
treasurer.register_treasure("default:sign_wall",0.1,4)
|
||||||
|
treasurer.register_treasure("default:ladder",0.1,3,{1,2})
|
||||||
|
treasurer.register_treasure("default:torch",0.2,2,{1,5})
|
2
tsm_chests_example/depends.txt
Normal file
2
tsm_chests_example/depends.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
treasurer
|
||||||
|
default
|
1
tsm_chests_example/description.txt
Normal file
1
tsm_chests_example/description.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Generates some chests in the underground with random treasures.
|
142
tsm_chests_example/init.lua
Normal file
142
tsm_chests_example/init.lua
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
--[[
|
||||||
|
This is an example treasure spawning mod (TSM) for the default mod.
|
||||||
|
It needs the mods “treasurer” and “default” to work.
|
||||||
|
For an example, it is kinda advanced.
|
||||||
|
|
||||||
|
A TSM’s task is to somehow bring treasures (which are ItemStacks) into the world.
|
||||||
|
This is also called “spawning treasures”.
|
||||||
|
How it does this task is completely free to the programmer of the TSM.
|
||||||
|
|
||||||
|
This TSM spawns the treasures by placing chests (default:chest) between 20 and 200 node lengths below the water surface. This cau
|
||||||
|
The chests are provided by the default mod, therefore this TSM depends on the default mod.
|
||||||
|
The treasures are requested from the treasurer mod. The TSM asks the treasurer mod for some treasures.
|
||||||
|
|
||||||
|
However, the treasurer mod comes itself with no treasures whatsoever. You need another mod which tells the treasurer what treasures to add. These mods are called “treasure registration mods” (TRMs).
|
||||||
|
For this, there is another example mod, called “trm_default_example”, which registers a bunch of items of the default mod, like default:gold_ingot.
|
||||||
|
]]
|
||||||
|
|
||||||
|
--[[ here are some configuration variables ]]
|
||||||
|
|
||||||
|
local chests_per_chunk = 15 -- number of chests per chunk. 15 is a bit high, an actual mod might have a lower number
|
||||||
|
local h_min = -200 -- minimum chest spawning height, relative to water_level
|
||||||
|
local h_max = -20 -- maximum chest spawning height, relative to water_level
|
||||||
|
local t_min = 1 -- minimum amount of treasures found in a chest
|
||||||
|
local t_max = 6 -- maximum amount of treasures found in a chest
|
||||||
|
|
||||||
|
--[[ here comes the generation code
|
||||||
|
the interesting part which involes treasurer comes way below
|
||||||
|
]]
|
||||||
|
minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
|
-- get the water level and convert it to a number
|
||||||
|
local water_level = minetest.setting_get("water_level")
|
||||||
|
if water_level == nil or type(water_level) ~= "number" then
|
||||||
|
water_level = 1
|
||||||
|
else
|
||||||
|
water_level = tonumber(water_level)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- chests minimum and maximum spawn height
|
||||||
|
local height_min = water_level + h_min
|
||||||
|
local height_max = water_level + h_max
|
||||||
|
|
||||||
|
if(maxp.y < height_min or minp.y > height_max) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local y_min = math.max(minp.y, height_min)
|
||||||
|
local y_max = math.min(maxp.y, height_max)
|
||||||
|
for i=1, chests_per_chunk do
|
||||||
|
local pos = {x=math.random(minp.x,maxp.x),z=math.random(minp.z,maxp.z), y=minp.y}
|
||||||
|
local env = minetest.env
|
||||||
|
|
||||||
|
-- Find ground level
|
||||||
|
local ground = nil
|
||||||
|
local top = y_max
|
||||||
|
if env:get_node({x=pos.x,y=y_max,z=pos.z}).name ~= "air" and env:get_node({x=pos.x,y=y_max,z=pos.z}).name ~= "default:water_source" and env:get_node({x=pos.x,y=y_max,z=pos.z}).name ~= "default:lava_source" then
|
||||||
|
for y=y_max,y_min,-1 do
|
||||||
|
local p = {x=pos.x,y=y,z=pos.z}
|
||||||
|
if env:get_node(p).name == "air" or env:get_node(p).name == "default:water_source" or env:get_node(p) == "default:lava_source" then
|
||||||
|
top = y
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for y=top,y_min,-1 do
|
||||||
|
local p = {x=pos.x,y=y,z=pos.z}
|
||||||
|
if env:get_node(p).name ~= "air" and env:get_node(p).name ~= "default:water_source" and env:get_node(p).name ~= "default:lava_source" then
|
||||||
|
ground = y
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if(ground~=nil) then
|
||||||
|
local chest_pos = {x=pos.x,y=ground+1, z=pos.z}
|
||||||
|
local nn = minetest.get_node(chest_pos).name -- chest node name (before it becomes a chest)
|
||||||
|
if nn == "air" or nn == "default:water_source" then
|
||||||
|
-->>>> chest spawning starts here <<<<--
|
||||||
|
|
||||||
|
-- first: spawn the chest
|
||||||
|
local chest = {}
|
||||||
|
chest.name = "default:chest"
|
||||||
|
|
||||||
|
-- secondly: rotate the chest
|
||||||
|
-- find possible faces
|
||||||
|
local xp, xm, zp, zm
|
||||||
|
xp = minetest.get_node({x=pos.x+1,y=ground+1, z=pos.z})
|
||||||
|
xm = minetest.get_node({x=pos.x-1,y=ground+1, z=pos.z})
|
||||||
|
zp = minetest.get_node({x=pos.x,y=ground+1, z=pos.z+1})
|
||||||
|
zm = minetest.get_node({x=pos.x,y=ground+1, z=pos.z-1})
|
||||||
|
|
||||||
|
local facedirs = {}
|
||||||
|
if(xp.name=="air" or xp.name=="default:water_source") then
|
||||||
|
table.insert(facedirs, minetest.dir_to_facedir({x=-1,y=0,z=0}))
|
||||||
|
end
|
||||||
|
if(xm.name=="air" or xm.name=="default:water_source") then
|
||||||
|
|
||||||
|
table.insert(facedirs, minetest.dir_to_facedir({x=1,y=0,z=0}))
|
||||||
|
end
|
||||||
|
if(zp.name=="air" or zp.name=="default:water_source") then
|
||||||
|
table.insert(facedirs, minetest.dir_to_facedir({x=0,y=0,z=-1}))
|
||||||
|
end
|
||||||
|
if(zm.name=="air" or zm.name=="default:water_source") then
|
||||||
|
table.insert(facedirs, minetest.dir_to_facedir({x=0,y=0,z=1}))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- choose a random face (if possible)
|
||||||
|
if(#facedirs == 0) then
|
||||||
|
minetest.set_node({x=pos.x,y=ground+1, z=pos.z+1},{name=nn})
|
||||||
|
chest.param2 = minetest.dir_to_facedir({x=0,y=0,z=1})
|
||||||
|
else
|
||||||
|
chest.param2 = facedirs[math.floor(math.random(#facedirs))]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Lastly: place the chest
|
||||||
|
minetest.set_node(chest_pos,chest)
|
||||||
|
|
||||||
|
--->>>>>>>>>> At this point we are finally going to involve Treasurer. <<<<<<<<<<<<<<--
|
||||||
|
-- determine a random amount of treasures
|
||||||
|
local treasure_amount = math.ceil(math.random(t_min, t_max))
|
||||||
|
|
||||||
|
-- calculate preciousness of treasures based on height. higher = more precious
|
||||||
|
local height = math.abs(h_min) - math.abs(h_max)
|
||||||
|
local y_norm = (ground+1) - h_min
|
||||||
|
local scale = 1 - (y_norm/height)
|
||||||
|
local minp = scale*4 -- minimal preciousness: 0..4
|
||||||
|
local maxp = scale*4+2.1 -- maximum preciousness: 2.1..6.1
|
||||||
|
|
||||||
|
-- now use these values to finally request the treasure(s)
|
||||||
|
local treasures = treasurer.select_random_treasures(treasure_amount,minp,maxp)
|
||||||
|
-- That’s it!
|
||||||
|
|
||||||
|
-- Get the inventory of the chest to place the treasures in
|
||||||
|
local meta = minetest.get_meta(chest_pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
|
||||||
|
--[[ Now that we got both our treasures and the chest’s inventory,
|
||||||
|
let’s place the treasures one for one into it. ]]
|
||||||
|
for i=1,#treasures do
|
||||||
|
inv:set_stack("main",i,treasures[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
1
tsm_gift_example/depends.txt
Normal file
1
tsm_gift_example/depends.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
treasurer
|
1
tsm_gift_example/description.txt
Normal file
1
tsm_gift_example/description.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Gives new players a few random treasures.
|
53
tsm_gift_example/init.lua
Normal file
53
tsm_gift_example/init.lua
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
--[[
|
||||||
|
This is a very basic example treasure spawning mod (TSM).
|
||||||
|
It needs the mod “treasurer” to work.
|
||||||
|
|
||||||
|
A TSM’s task is to somehow bring treasures (which are ItemStacks) into the world.
|
||||||
|
This is also called “spawning treasures”.
|
||||||
|
How it does this task is completely free to the programmer of the TSM.
|
||||||
|
|
||||||
|
This TSM gives one treasure (as returned from Treasurer) a new or respawning
|
||||||
|
player.
|
||||||
|
The treasure is requested from the treasurer mod.
|
||||||
|
|
||||||
|
However, the treasurer mod comes itself with no treasures whatsoever. You need
|
||||||
|
another mod which tells the treasurer what treasures to add. These mods are
|
||||||
|
called “treasure registration mods” (TRMs). For this, there is another example mod,
|
||||||
|
called “trm_default_example”, which registers a bunch of items of the default
|
||||||
|
mod, like default:gold_ingot.
|
||||||
|
|
||||||
|
See also the README file of Treasurer.
|
||||||
|
|
||||||
|
For an advanced example, try tsm_default_example, which spawns treasures
|
||||||
|
into chests.
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- This function will later be registered to the corresponding callbacks
|
||||||
|
function welcome_gift(player)
|
||||||
|
--[[ Request one random treasure from Treasurer. Remember that we receive a table
|
||||||
|
which could be empty.]]
|
||||||
|
local treasures = treasurer.select_random_treasures(1)
|
||||||
|
--[[ (We could have ommited the parameter above, because the function returns
|
||||||
|
1 treasure when called without any parameters) ]]
|
||||||
|
|
||||||
|
-- Get the inventory (InvRef) of the player
|
||||||
|
local inventory = player:get_inventory()
|
||||||
|
|
||||||
|
-- Check if we got an non-empty table. (If we don’t do this, we risk a crash!)
|
||||||
|
if(#treasures >= 1) then
|
||||||
|
-- Add the only treasure to the player’s main inventory
|
||||||
|
inventory:add_item("main",treasures[1])
|
||||||
|
-- That’s it!
|
||||||
|
end
|
||||||
|
--[[ If the returned table was empty, there’s nothing we can do here.
|
||||||
|
The player gets no gifts. The table may be empty because no TRM was activated.
|
||||||
|
Mods must be prepared for this.
|
||||||
|
]]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- The gift will be given on these events: new player creation, joining server, respawning
|
||||||
|
-- Therefore, we have to call these functions:
|
||||||
|
minetest.register_on_newplayer(welcome_gift)
|
||||||
|
minetest.register_on_joinplayer(welcome_gift)
|
||||||
|
minetest.register_on_respawnplayer(welcome_gift)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user