forked from nalc/awards
Fix bugs in craft trigger, and add an award to use it
This commit is contained in:
parent
628e485900
commit
f3f6af9e66
14
init.lua
14
init.lua
@ -36,7 +36,7 @@ awards.register_achievement("award_lightitup",{
|
|||||||
trigger = {
|
trigger = {
|
||||||
type = "place",
|
type = "place",
|
||||||
node = "default:torch",
|
node = "default:torch",
|
||||||
target = 100
|
target = 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ awards.register_achievement("award_obsessed_with_obsidian",{
|
|||||||
trigger = {
|
trigger = {
|
||||||
type = "dig",
|
type = "dig",
|
||||||
node = "default:obsidian",
|
node = "default:obsidian",
|
||||||
target = 50
|
target = 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -291,6 +291,16 @@ awards.register_achievement("award_marchand_de_sable", {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
awards.register_achievement("awards_crafter_of_sticks", {
|
||||||
|
title = S("Crafter of Sticks"),
|
||||||
|
description = S("Create 100 Sticks"),
|
||||||
|
trigger = {
|
||||||
|
type = "craft",
|
||||||
|
item = "default:stick",
|
||||||
|
target = 100
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
-- Join
|
-- Join
|
||||||
awards.register_achievement("award_join2", {
|
awards.register_achievement("award_join2", {
|
||||||
title = S("Frequent Visitor"),
|
title = S("Frequent Visitor"),
|
||||||
|
33
triggers.lua
33
triggers.lua
@ -56,12 +56,22 @@ awards.register_trigger("join", function(def)
|
|||||||
table.insert(awards.on.join, tmp)
|
table.insert(awards.on.join, tmp)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
awards.register_trigger("craft", function(def)
|
||||||
|
local tmp = {
|
||||||
|
award = def.name,
|
||||||
|
item = def.trigger.item,
|
||||||
|
target = def.trigger.target
|
||||||
|
}
|
||||||
|
table.insert(awards.on.craft, tmp)
|
||||||
|
end)
|
||||||
|
|
||||||
-- Backwards compatibility
|
-- Backwards compatibility
|
||||||
awards.register_onDig = awards.register_on_dig
|
awards.register_onDig = awards.register_on_dig
|
||||||
awards.register_onPlace = awards.register_on_place
|
awards.register_onPlace = awards.register_on_place
|
||||||
awards.register_onDeath = awards.register_on_death
|
awards.register_onDeath = awards.register_on_death
|
||||||
awards.register_onChat = awards.register_on_chat
|
awards.register_onChat = awards.register_on_chat
|
||||||
awards.register_onJoin = awards.register_on_join
|
awards.register_onJoin = awards.register_on_join
|
||||||
|
awards.register_onCraft = awards.register_on_craft
|
||||||
|
|
||||||
-- Trigger Handles
|
-- Trigger Handles
|
||||||
minetest.register_on_dignode(function(pos, oldnode, digger)
|
minetest.register_on_dignode(function(pos, oldnode, digger)
|
||||||
@ -193,29 +203,30 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv
|
|||||||
awards.tbv(awards.players[playern].craft[mod], item, 0)
|
awards.tbv(awards.players[playern].craft[mod], item, 0)
|
||||||
|
|
||||||
-- Increment counter
|
-- Increment counter
|
||||||
awards.players[playern].craft[mod][item]=awards.players[playern].craft[mod][item] + 1
|
awards.players[playern].craft[mod][item] = awards.players[playern].craft[mod][item] + 1
|
||||||
|
|
||||||
-- Run callbacks and triggers
|
-- Run callbacks and triggers
|
||||||
local data=awards.players[playern]
|
local data = awards.players[playern]
|
||||||
for i=1,# awards.onCraft do
|
for i=1, #awards.on.craft do
|
||||||
local res = nil
|
local res = nil
|
||||||
if type(awards.onCraft[i]) == "function" then
|
local entry = awards.on.craft[i]
|
||||||
|
if type(entry) == "function" then
|
||||||
-- Run trigger callback
|
-- Run trigger callback
|
||||||
res = awards.onDig[i](player,data)
|
res = entry(player,data)
|
||||||
elseif type(awards.onCraft[i]) == "table" then
|
elseif type(entry) == "table" then
|
||||||
-- Handle table trigger
|
-- Handle table trigger
|
||||||
if not awards.onCraft[i].item or not awards.onCraft[i].target or not awards.onCraft[i].award then
|
if not entry.item or not entry.target or not entry.award then
|
||||||
-- table running failed!
|
-- table running failed!
|
||||||
print("[ERROR] awards - onCraft trigger "..i.." is invalid!")
|
print("[ERROR] awards - onCraft trigger "..i.." is invalid!")
|
||||||
else
|
else
|
||||||
-- run the table
|
-- run the table
|
||||||
local titemcrafted = string.split(awards.onCraft[i].item, ":")
|
local titemcrafted = string.split(entry.item, ":")
|
||||||
local tmod=titemcrafted[1]
|
local tmod=titemcrafted[1]
|
||||||
local titem=titemcrafted[2]
|
local titem=titemcrafted[2]
|
||||||
if tmod==nil or titem==nil or not data.craft[tmod] or not data.craft[tmod][titem] then
|
if not tmod==nil or not titem or not data.craft[tmod] or not data.craft[tmod][titem] then
|
||||||
-- table running failed!
|
-- table running failed!
|
||||||
elseif data.craft[tmod][titem] > awards.onCraft[i].target-1 then
|
elseif data.craft[tmod][titem] > entry.target-1 then
|
||||||
res=awards.onCraft[i].award
|
res=awards.on.craft[i].award
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user