forked from nalc/awards
Move unrelated things from trigger.lua
This commit is contained in:
parent
dee1880fd3
commit
f430b4eb68
25
api.lua
25
api.lua
|
@ -61,6 +61,22 @@ function awards.register_trigger(name, func)
|
|||
end
|
||||
end
|
||||
|
||||
function awards.run_trigger_callbacks(player, data, trigger, table_func)
|
||||
for i = 1, #awards.on[trigger] do
|
||||
local res = nil
|
||||
local entry = awards.on[trigger][i]
|
||||
if type(entry) == "function" then
|
||||
res = entry(player, data)
|
||||
elseif type(entry) == "table" and entry.award then
|
||||
res = table_func(entry)
|
||||
end
|
||||
|
||||
if res then
|
||||
awards.unlock(player:get_player_name(), res)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function awards.register_on_unlock(func)
|
||||
table.insert(awards.on_unlock, func)
|
||||
end
|
||||
|
@ -367,3 +383,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
end)
|
||||
|
||||
awards.init()
|
||||
|
||||
minetest.register_on_newplayer(function(player)
|
||||
local playern = player:get_player_name()
|
||||
awards.assertPlayer(playern)
|
||||
end)
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
awards.save()
|
||||
end)
|
||||
|
|
|
@ -26,6 +26,7 @@ function awards.assertPlayer(playern)
|
|||
awards.tbv(awards.players[playern], "unlocked")
|
||||
awards.tbv(awards.players[playern], "place")
|
||||
awards.tbv(awards.players[playern], "count")
|
||||
awards.tbv(awards.players[playern], "craft")
|
||||
awards.tbv(awards.players[playern], "deaths", 0)
|
||||
awards.tbv(awards.players[playern], "joins", 0)
|
||||
awards.tbv(awards.players[playern], "chats", 0)
|
||||
|
|
26
triggers.lua
26
triggers.lua
|
@ -73,22 +73,6 @@ awards.register_onChat = awards.register_on_chat
|
|||
awards.register_onJoin = awards.register_on_join
|
||||
awards.register_onCraft = awards.register_on_craft
|
||||
|
||||
function awards.run_trigger_callbacks(player, data, trigger, table_func)
|
||||
for i = 1, #awards.on[trigger] do
|
||||
local res = nil
|
||||
local entry = awards.on[trigger][i]
|
||||
if type(entry) == "function" then
|
||||
res = entry(player, data)
|
||||
elseif type(entry) == "table" and entry.award then
|
||||
res = table_func(entry)
|
||||
end
|
||||
|
||||
if res then
|
||||
awards.unlock(player:get_player_name(), res)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Trigger Handles
|
||||
minetest.register_on_dignode(function(pos, oldnode, digger)
|
||||
if not digger or not pos or not oldnode then
|
||||
|
@ -184,7 +168,6 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv
|
|||
return
|
||||
end
|
||||
awards.assertPlayer(playern)
|
||||
awards.tbv(awards.players[playern], "craft")
|
||||
awards.tbv(awards.players[playern].craft, mod)
|
||||
awards.tbv(awards.players[playern].craft[mod], item, 0)
|
||||
|
||||
|
@ -273,12 +256,3 @@ minetest.register_on_chat_message(function(name, message)
|
|||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
minetest.register_on_newplayer(function(player)
|
||||
local playern = player:get_player_name()
|
||||
awards.assertPlayer(playern)
|
||||
end)
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
awards.save()
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue
Block a user