Traitor/mods/tasks/functions.lua

93 lines
3.5 KiB
Lua
Raw Normal View History

2020-12-21 07:39:29 -08:00
function tasks.check_xp(map_id, needed_xp)
if needed_xp <= 0 then
lobby.team_win(map_id)
end
end
function tasks.add_xp(pos, node, puncher, swap_to)
2021-03-15 08:45:36 -07:00
local player_attributes = puncher:get_meta()
local ghost = player_attributes:get_string('ghost')
local meta = minetest.get_meta(pos)
local timer_length = tonumber(meta:get_string('timer')) or 60
local earned_xp = tonumber(meta:get_string('xp')) or 1
local wield = puncher:get_wielded_item()
local wield_name = wield:get_name()
if wield_name ~= 'creative:tool_breaking' then
local name = puncher:get_player_name()
local timer = minetest.get_node_timer(pos)
2020-12-21 07:39:29 -08:00
local map_id = lobby.game[name]
local traitor = lobby.traitors[map_id]
2021-03-15 08:45:36 -07:00
minetest.swap_node(pos, {name = swap_to, param2 = node.param2})
local meta = minetest.get_meta(pos)
meta:set_string('formspec', '')
timer:start(timer_length)
2020-12-27 09:19:36 -08:00
if map_id ~= 'lobby' then
if name ~= traitor then
2021-03-15 08:45:36 -07:00
if ghost == 'true' then
earned_xp = math.floor(earned_xp/2)
map_id = string.sub(map_id, 0, -7)
end
2020-12-27 09:19:36 -08:00
local game_data = lobby.savedata.data[map_id]
2021-03-15 08:45:36 -07:00
lobby.xp[map_id] = lobby.xp[map_id] + earned_xp
2020-12-27 09:19:36 -08:00
local needed_xp = game_data['xp'] - lobby.xp[map_id]
2021-03-15 08:45:36 -07:00
minetest.chat_send_player(name, 'You just earned '..earned_xp..' XP for your team.\nYou need '..needed_xp..' more XP to defeat the imposter.')
2020-12-27 09:19:36 -08:00
tasks.check_xp(map_id, needed_xp)
else
minetest.chat_send_player(name, 'You\'re the traitor, you can do tasks, but you won\'t earn XP. Try killing the other players.')
end
2021-03-15 08:45:36 -07:00
elseif map_id == 'lobby' then
lobby.give_xp(puncher, 1)
end
end
end
function tasks.only_add_xp(xp, name) -- This function only adds XP, you are responsible for modifying the task node yourself.
local player = minetest.get_player_by_name(name)
local player_attributes = player:get_meta()
local ghost = player_attributes:get_string('ghost')
local map_id = lobby.game[name]
local traitor = lobby.traitors[map_id]
if map_id ~= 'lobby' then
if name ~= traitor then
if ghost == 'true' then
xp = math.floor(xp/2)
map_id = string.sub(map_id, 0, -7)
print (xp..' is xp, level is '..map_id)
end
local game_data = lobby.savedata.data[map_id]
lobby.xp[map_id] = lobby.xp[map_id] + xp
local needed_xp = game_data['xp'] - lobby.xp[map_id]
minetest.chat_send_player(name, 'You just earned '..xp..' XP for your team.\nYou need '..needed_xp..' more XP to defeat the imposter.')
tasks.check_xp(map_id, needed_xp)
else
minetest.chat_send_player(name, 'You\'re the traitor, you can do tasks, but you won\'t earn XP. Try killing the other players.')
2020-12-21 07:39:29 -08:00
end
2021-03-15 08:45:36 -07:00
elseif map_id == 'lobby' then
lobby.give_xp(player, 1)
2020-12-21 07:39:29 -08:00
end
end
2021-02-17 06:14:23 -08:00
function tasks.is_integer(input)
local number = tonumber(input)
if number then
if math.floor(number) == number then
return true
end
end
end
function tasks.valid_input(string)
local variables = string:split(', ')
local xp = variables[1]
local timer = variables[2]
if tasks.is_integer(xp) and tasks.is_integer(timer) then
return true
end
end
2021-01-04 18:31:58 -08:00
tasks.formspec_configuration =
'size[6,3]'..
'label[.5,.25;Please enter data in this format: \nXP, Timer_Duration, Task_name]'..
'field[1,1.5;5,1;input;;]'..
'button_exit[2,2;2,1;save;Submit]'