Lucky-Ore/init.lua

139 lines
3.4 KiB
Lua
Raw Normal View History

2016-11-24 17:58:29 -05:00
--the ore
2016-11-24 16:12:14 -05:00
minetest.register_node("lucky_ore:ore", {
description = "Lucky Ore",
2016-11-24 16:12:14 -05:00
tiles = {
{
name = "lucky_ore.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
2016-11-24 18:30:33 -05:00
length = 0.4,
2016-11-24 16:12:14 -05:00
},
},
{
name = "lucky_ore.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
2016-11-24 18:30:33 -05:00
length = 0.4,
2016-11-24 16:12:14 -05:00
},
},
},
paramtype = "light",
light_source = 5,
2016-11-24 16:18:20 -05:00
groups = {cracky = 3},
2016-11-24 17:58:29 -05:00
after_destruct = function(pos, oldnode)
local item = minetest.add_entity(pos, "lucky_ore:item")
end
})
--calculate the table items for slot machine-esk item display
local count = 0
local lucky_table = {}
for item,def in pairs(minetest.registered_items) do
count = count + 1
lucky_table[count] = item
end
2016-11-24 18:30:33 -05:00
--the explosion for loses
local def = {
name = "lucky_ore:explosion",
description = "Ore Explosion (you hacker you!)",
radius = 3,
tiles = {
side = "default_dirt.png",
top = "default_dirt.png",
bottom = "default_dirt.png",
burning = "default_dirt.png"
},
}
tnt.register_tnt(def)
2016-11-24 17:58:29 -05:00
--the entity which shows all the items
minetest.register_entity("lucky_ore:item",{
hp_max = 1,
visual="wielditem",
visual_size={x=.33,y=.33},
collisionbox = {0,0,0,0,0,0},
physical=false,
textures={"air"},
2016-11-24 18:30:33 -05:00
count = 0, --start at zero since counter adds before showing item
timer = 0,
expire = 0,
counting = true,
2016-11-24 17:58:29 -05:00
on_activate = function(self, staticdata)
self.origin = self.object:getpos()
2016-11-24 18:45:44 -05:00
self.object:set_armor_groups({immortal = 1})
2016-11-24 17:58:29 -05:00
self.texture = ItemStack("default:dirt_with_grass"):get_name()
self.nodename = "default:dirt_with_grass"
self.object:set_properties({textures={self.texture}})
self.sound = minetest.sound_play("lucky_ore_slot", {
max_hear_distance = 30,
gain = 10.0,
object = self.object,
loop = true,
})
2016-11-24 18:30:33 -05:00
self.object:set_properties({automatic_rotate=1})
self.expire = math.random(5,10)
2016-11-24 17:58:29 -05:00
end,
on_step = function(self,dtime)
2016-11-24 18:30:33 -05:00
self.timer = self.timer + dtime
self.object:setvelocity({x=0,y=0,z=0})
self.object:setpos(self.origin)
2016-11-24 18:30:33 -05:00
--if it's past expiration then stop and do some particles and showcase
if self.timer >= self.expire then
--turn off the counting sound
if self.counting == true then
minetest.sound_stop(self.sound)
self.sound = nil
self.counting = false
end
--turn on the win sound
if self.counting == false and self.sound == nil then
self.sound = minetest.sound_play("lucky_ore_win", {
max_hear_distance = 30,
gain = 10.0,
object = self.object,
})
end
if self.timer >= self.expire + 2 then
minetest.sound_stop(self.sound)
--the fake win
if math.random() > 0.5 then
tnt.boom(self.object:getpos(), def)
self.object:remove()
else
minetest.add_item(self.object:getpos(), lucky_table[self.count])
self.object:remove()
end
end
else --show all the items and cycle
self.count = self.count + 1
if self.count > count then
self.count = 1
end
self.texture = ItemStack(lucky_table[self.count]):get_name()
self.nodename = lucky_table[self.count]
self.object:set_properties({textures={self.texture}})
2016-11-24 17:58:29 -05:00
end
2016-11-24 18:30:33 -05:00
2016-11-24 17:58:29 -05:00
end,
2016-11-24 16:12:14 -05:00
})
2016-11-24 17:58:29 -05:00
2016-11-24 18:34:20 -05:00
--ore generation
minetest.register_ore({
ore_type = "scatter",
2016-11-24 18:38:17 -05:00
ore = "lucky_ore:ore",
2016-11-24 18:34:20 -05:00
wherein = "default:stone",
clust_scarcity = 8 * 8 * 8,
clust_num_ores = 9,
clust_size = 3,
y_min = -31000,
y_max = 31000,
})