Fix bug in skills mod and add quests.get_formspec

master
cale 2016-08-20 13:00:27 +02:00 committed by rubenwardy
parent df6e8c8dad
commit 3034fc0876
2 changed files with 42 additions and 31 deletions

View File

@ -78,7 +78,7 @@ function quests.finish_goal(player, quest, goal)
end
end
end
if goal.reward then
minetest.get_player_by_name(player):get_inventory():add_item("main", goal.reward)
cmsg.push_message_player(minetest.get_player_by_name(player), goal.ending or "[quest] You completed a goal and you got a reward!")
@ -186,35 +186,39 @@ function quests.format_goal(player, quest, goal)
end
end
function quests.get_formspec(name)
local player_quests = quests.player_quests[name]
if not player_quests or #player_quests == 0 then
local s = quests.show_quests_form
s = string.format(s, "You have not got any quests yet.")
return s
end
local s = quests.show_quests_form
local txt = ""
for _, quest in pairs(player_quests) do
if quest.done then
txt = txt .. " -> " .. (quest.title or "[NO TITLE]") .. " (Completed)\n"
else
txt = txt .. " -> " .. (quest.title or "[NO TITLE]") .. "\n"
for _, goal in pairs(quest.goals) do
if not goal.requires or goal.requires.done then
txt = txt .. quests.format_goal(name, quest, goal)
end
end
end
end
s = string.format(s, minetest.formspec_escape(txt))
return s
end
minetest.register_chatcommand("quests", {
params = "",
description = "Shows your quests",
privs = {},
func = function(name, text)
local player_quests = quests.player_quests[name]
if not player_quests or #player_quests == 0 then
local s = quests.show_quests_form
s = string.format(s, "You have not got any quests yet.")
minetest.show_formspec(name, "quests:show_quests", s)
return
end
local s = quests.show_quests_form
local txt = ""
for _, quest in pairs(player_quests) do
if quest.done then
txt = txt .. " -> " .. (quest.title or "[NO TITLE]") .. " (Completed)\n"
else
txt = txt .. " -> " .. (quest.title or "[NO TITLE]") .. "\n"
for _, goal in pairs(quest.goals) do
if not goal.requires or goal.requires.done then
txt = txt .. quests.format_goal(name, quest, goal)
end
end
end
end
s = string.format(s, minetest.formspec_escape(txt))
minetest.show_formspec(name, "quests:show_quests", s)
minetest.show_formspec(name, "quests:show_quests", quests.get_formspec(name))
return true, ""
end,
})
@ -246,11 +250,17 @@ minetest.register_on_newplayer(function(player)
--tutorial
local name = player:get_player_name()
local quest = quests.new(name, "Tutorial", "Hey you!\nI didnt see you before. Are you new here?\nOh, Ok.\nI will help you to find the city \"NAME HERE\".\nYou will be save there.\n But first you need some basic equipment!")
local q1 = quests.add_dig_goal(quest, "Harvest dirt", {"default:dirt"}, 10, "You need to harvest some Dirt to get stones!")
local q2 = quests.add_dig_goal(quest, "Harvest Grass", {"default:plant_grass", "default:plant_grass_2", "default:plant_grass_3", "default:plant_grass_4", "default:plant_grass_5"}, 12, "Now you need to get some Grass to craft strings.")
local q3 = quests.add_dig_goal(quest, "Harvest Leaves", {"default:leaves_1", "default:leaves_2", "default:leaves_3" ,"default:leaves_4"}, 6, "Harvest some leaves to craft twigs.")
local q4 = quests.add_place_goal(quest, "Place Workbench", {"default:workbench"}, 1, "You should craft a workbench and place it in front of you!", "Great! The tutorial ends here. If you want to know how to craft things just goto the RPGtest wiki.\nBut I think cdqwertz will add a crafting guide soon.")
local q1 = quests.add_dig_goal(quest, "Harvest dirt",
{"default:dirt", "default:grass"}, 10, "You need to harvest some Dirt to get stones!")
local q2 = quests.add_dig_goal(quest, "Harvest Grass",
{"default:plant_grass", "default:plant_grass_2", "default:plant_grass_3", "default:plant_grass_4", "default:plant_grass_5"}, 12, "Now you need to get some Grass to craft strings.")
local q3 = quests.add_dig_goal(quest, "Harvest Leaves",
{"default:leaves_1", "default:leaves_2", "default:leaves_3" ,"default:leaves_4"}, 6, "Harvest some leaves to craft twigs.")
local q4 = quests.add_place_goal(quest, "Place Workbench",
{"default:workbench"}, 1,
"You should craft a workbench and place it in front of you!",
"Great! The tutorial ends here.")
q3.reward = "default:wood 3"

View File

@ -9,6 +9,7 @@ minetest.register_on_newplayer(function(player)
for s,a in pairs(skills.all_skills) do
skills.lvls[player:get_player_name()][s] = 1
end
skills.save_skills()
end)
function skills.get_dmg(lvl)
@ -301,7 +302,7 @@ minetest.override_item("default:stone_with_diamond", {
minetest.override_item("default:stone", {
on_dig = function(pos, node, player)
if skills.lvls[player:get_player_name()]["miner"] then
if skills.lvls[player:get_player_name()] and skills.lvls[player:get_player_name()]["miner"] then
if skills.lvls[player:get_player_name()]["miner"] > 1 then
if math.random(0, 20) == 1 then
xp.add_xp(player,10)