forked from nalc/awards
add onDeath
This commit is contained in:
parent
6b031a601d
commit
4cf05cbc47
10
api.lua
10
api.lua
@ -46,6 +46,12 @@ function awards.register_achievement(name,data_table)
|
|||||||
target=data_table['trigger']['target'],
|
target=data_table['trigger']['target'],
|
||||||
}
|
}
|
||||||
table.insert(awards.onPlace,tmp)
|
table.insert(awards.onPlace,tmp)
|
||||||
|
elseif data_table['trigger']['type']=="death" then
|
||||||
|
local tmp={
|
||||||
|
award=name,
|
||||||
|
target=data_table['trigger']['target'],
|
||||||
|
}
|
||||||
|
table.insert(awards.onDeath,tmp)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -60,6 +66,10 @@ function awards.register_onPlace(func)
|
|||||||
table.insert(awards.onPlace,func);
|
table.insert(awards.onPlace,func);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function awards.register_onDeath(func)
|
||||||
|
table.insert(awards.onDeath,func);
|
||||||
|
end
|
||||||
|
|
||||||
function awards.give_achievement(name,award)
|
function awards.give_achievement(name,award)
|
||||||
local data=player_data[name]
|
local data=player_data[name]
|
||||||
|
|
||||||
|
10
init.lua
10
init.lua
@ -81,4 +81,14 @@ awards.register_achievement("award_mine4",{
|
|||||||
node="default:stone",
|
node="default:stone",
|
||||||
target=10000,
|
target=10000,
|
||||||
},
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
-- First Death
|
||||||
|
awards.register_achievement("award_death1",{
|
||||||
|
title = "First Death",
|
||||||
|
description = "Oh well, it does not matter you have more lives than a cat",
|
||||||
|
trigger={
|
||||||
|
type="death",
|
||||||
|
target=1,
|
||||||
|
},
|
||||||
})
|
})
|
@ -19,13 +19,15 @@ The API
|
|||||||
* trigger [optional] [table]
|
* trigger [optional] [table]
|
||||||
* type - "dig" or "place"
|
* type - "dig" or "place"
|
||||||
* (for dig/place type) node - the nodes name
|
* (for dig/place type) node - the nodes name
|
||||||
* (for dig/place type) target - how many to dig / place
|
* (for all types) target - how many to dig / place
|
||||||
* awards.give_achievement(name,award)
|
* awards.give_achievement(name,award)
|
||||||
* -- gives an award to a player
|
* -- gives an award to a player
|
||||||
* awards.register_onDig(func(player,data))
|
* awards.register_onDig(func(player,data))
|
||||||
* -- return award name or null
|
* -- return award name or null
|
||||||
* awards.register_onPlace(func(player,data))
|
* awards.register_onPlace(func(player,data))
|
||||||
* -- return award name or null
|
* -- return award name or null
|
||||||
|
* awards.register_onDeath(func(player,data))
|
||||||
|
* -- return award name or null
|
||||||
|
|
||||||
|
|
||||||
Player Data
|
Player Data
|
||||||
|
39
triggers.lua
39
triggers.lua
@ -149,12 +149,47 @@ minetest.register_on_placenode(function(pos, newnode, placer)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_newplayer(function(player)
|
minetest.register_on_dieplayer(function(player)
|
||||||
minetest.chat_send_player(player:get_player_name(),"[Awards] Registering you now...")
|
player_data[player:get_player_name()]['deaths']=player_data[player:get_player_name()]['deaths']+1
|
||||||
|
|
||||||
|
-- Set up the variables
|
||||||
|
local playern=player:get_player_name()
|
||||||
|
local data=player_data[playern]
|
||||||
|
|
||||||
|
-- Roll through the onDeath functions
|
||||||
|
for i=1,# awards.onDeath do
|
||||||
|
local res=nil
|
||||||
|
if type(awards.onDeath[i]) == "function" then
|
||||||
|
-- run the function
|
||||||
|
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!
|
||||||
|
else
|
||||||
|
-- run the table
|
||||||
|
|
||||||
|
if not data['deaths'] then
|
||||||
|
-- table running failed!
|
||||||
|
elseif data['deaths'] > awards.onDeath[i]['target']-1 then
|
||||||
|
res=awards.onDeath[i]['award']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if res~=nil then
|
||||||
|
awards.give_achievement(playern,res)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_newplayer(function(player)
|
||||||
--Player data root
|
--Player data root
|
||||||
player_data[player:get_player_name()]={}
|
player_data[player:get_player_name()]={}
|
||||||
player_data[player:get_player_name()]['name']=player:get_player_name()
|
player_data[player:get_player_name()]['name']=player:get_player_name()
|
||||||
|
player_data[player:get_player_name()]['deaths']=0
|
||||||
|
|
||||||
--The player counter
|
--The player counter
|
||||||
player_data[player:get_player_name()]['count']={}
|
player_data[player:get_player_name()]['count']={}
|
||||||
|
Loading…
Reference in New Issue
Block a user