summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRubenwardy <anjayward@gmail.com>2013-11-12 19:50:25 +0000
committerRubenwardy <anjayward@gmail.com>2013-11-12 19:50:25 +0000
commit4fe55f3a1490fa90b329af66942712a5ff9f829d (patch)
tree554916f159ca57a68680b2dd769c5e1e5b59e1da
parent6387bd1d9e128c23bd47b1bbf0544362f8fdbfba (diff)
Update
-rw-r--r--api.lua18
-rw-r--r--triggers.lua44
2 files changed, 26 insertions, 36 deletions
diff --git a/api.lua b/api.lua
index c399770..444b4ba 100644
--- a/api.lua
+++ b/api.lua
@@ -35,11 +35,10 @@ end
-- A table of award definitions
awards.def = {}
-function awards.tbv(tb,value)
- awards.tbv_default(tb,value,{})
-end
-
-function awards.tbv_default(tb,value,default)
+function awards.tbv(tb,value,default)
+ if not default then
+ default = {}
+ end
if not tb or type(tb) ~= "table" then
if not value then
value = "[NULL]"
@@ -58,6 +57,15 @@ function awards.tbv_default(tb,value,default)
end
end
+function awards.assertPlayer(playern)
+ awards.tbv(awards.players, playern)
+ awards.tbv(awards.players[playern], "name", playern)
+ awards.tbv(awards.players[playern], "unlocked")
+ awards.tbv(awards.players[playern], "place")
+ awards.tbv(awards.players[playern], "count")
+ awards.tbv(awards.players[playern], "deaths", 0)
+end
+
-- Load files
dofile(minetest.get_modpath("awards").."/triggers.lua")
dofile(minetest.get_modpath("awards").."/config.txt")
diff --git a/triggers.lua b/triggers.lua
index 0121768..66fbc54 100644
--- a/triggers.lua
+++ b/triggers.lua
@@ -27,13 +27,9 @@ minetest.register_on_dignode(function(pos, oldnode, digger)
if (not playern or not nodedug or not mod or not item) then
return
end
-
- -- Run checks
- awards.tbv(awards.players, playern )
- awards.tbv(awards.players[playern], "count" )
- awards.tbv(awards.players[playern], "name", playern )
- awards.tbv(awards.players[playern].count, mod)
- awards.tbv(awards.players[playern].count[mod], item, 0 )
+ awards.assertPlayer(playern)
+ awards.tbv(awards.players[playern].count, mod)
+ awards.tbv(awards.players[playern].count[mod], item, 0 )
-- Increment counder
awards.players[playern].count[mod][item]=awards.players[playern].count[mod][item]+1
@@ -47,14 +43,12 @@ minetest.register_on_dignode(function(pos, oldnode, digger)
local res = nil
if type(awards.onDig[i]) == "function" then
-- Run trigger callback
- print(i.." is a function")
res = awards.onDig[i](player,data)
elseif type(awards.onDig[i]) == "table" then
-- Handle table trigger
- print(i.." is a table")
if not awards.onDig[i].node or not awards.onDig[i].target or not awards.onDig[i].award then
-- table running failed!
- print("onDig trigger "..i.." is invalid!")
+ print("[ERROR] awards - onDig trigger "..i.." is invalid!")
else
-- run the table
local tnodedug = string.split(awards.onDig[i].node, ":")
@@ -91,15 +85,13 @@ minetest.register_on_placenode(function(pos,node,digger)
if (not playern or not nodedug or not mod or not item) then
return
end
- awards.tbv(awards.players, playern )
- awards.tbv(awards.players[playern], "place" )
- awards.tbv(awards.players[playern], "name", playern )
- awards.tbv(awards.players[playern].place, mod)
- awards.tbv(awards.players[playern].place[mod], item, 0 )
+ awards.assertPlayer(playern)
+ awards.tbv(awards.players[playern].place, mod)
+ awards.tbv(awards.players[playern].place[mod], item, 0 )
-- Increment counder
awards.players[playern].place[mod][item] = awards.players[playern].place[mod][item]+1
- print(" - "..mod..":"..item.." 's count is now "..(awards.players[playern].place[mod][item]))
+ print(" - "..mod..":"..item.." 's place count is now "..(awards.players[playern].place[mod][item]))
-- Run callbacks and triggers
local player = digger
@@ -108,14 +100,12 @@ minetest.register_on_placenode(function(pos,node,digger)
local res = nil
if type(awards.onPlace[i]) == "function" then
-- Run trigger callback
- print(i.." is a function")
res = awards.onPlace[i](player,data)
elseif type(awards.onPlace[i]) == "table" then
-- Handle table trigger
- print(i.." is a table")
if not awards.onPlace[i].node or not awards.onPlace[i].target or not awards.onPlace[i].award then
-- table running failed!
- print("onPlace trigger "..i.." is invalid!")
+ print("[ERROR] awards - onPlace trigger "..i.." is invalid!")
else
-- run the table
local tnodedug = string.split(awards.onPlace[i].node, ":")
@@ -141,9 +131,8 @@ minetest.register_on_dieplayer(function(player)
return
end
local playern = player:get_player_name()
- awards.tbv(awards.players, playern )
- awards.tbv(awards.players[playern], "name", playern )
- awards.tbv(awards.players[playern], "deaths", 0 )
+ awards.assertPlayer(playern)
+
-- Increment counter
awards.players[player:get_player_name()].deaths = awards.players[player:get_player_name()].deaths + 1
@@ -154,14 +143,12 @@ minetest.register_on_dieplayer(function(player)
local res=nil
if type(awards.onDeath[i]) == "function" then
-- Run trigger callback
- print(i.." is a function")
res=awards.onDeath[i](player,data)
elseif type(awards.onDeath[i]) == "table" then
-- handle table here
- print(i.." is a table")
if not awards.onDeath[i].target or not awards.onDeath[i].award then
-- table running failed!
- print("onDeath trigger "..i.." is invalid!")
+ print("[ERROR] awards - onDeath trigger "..i.." is invalid!")
else
-- run the table
if not data.deaths then
@@ -180,12 +167,7 @@ end)
minetest.register_on_newplayer(function(player)
local playern = player:get_player_name()
- awards.tbv(awards.players, playern)
- awards.tbv(awards.players[playern], "name", playern)
- awards.tbv(awards.players[playern], "unlocked")
- awards.tbv(awards.players[playern], "place")
- awards.tbv(awards.players[playern], "count")
- awards.tbv(awards.players[playern], "deaths", 0)
+ awards.assertPlayer(playern)
end)
minetest.register_on_shutdown(function()