functions.lua 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. function tasks.check_xp(map_id, needed_xp)
  2. if needed_xp <= 0 then
  3. lobby.team_win(map_id)
  4. end
  5. end
  6. function tasks.add_xp(pos, node, puncher, swap_to)
  7. local ghost = puncher:get_attribute('ghost')
  8. if ghost == 'false' then
  9. local meta = minetest.get_meta(pos)
  10. local timer_length = tonumber(meta:get_string('timer')) or 60
  11. local earned_xp = tonumber(meta:get_string('xp')) or 1
  12. local wield = puncher:get_wielded_item()
  13. local wield_name = wield:get_name()
  14. if wield_name == '' then
  15. local name = puncher:get_player_name()
  16. local timer = minetest.get_node_timer(pos)
  17. local map_id = lobby.game[name]
  18. local traitor = lobby.traitors[map_id]
  19. minetest.swap_node(pos, {name = swap_to, param2 = node.param2})
  20. local meta = minetest.get_meta(pos)
  21. meta:set_string('formspec', '')
  22. timer:start(timer_length)
  23. if map_id ~= 'lobby' then
  24. if name ~= traitor then
  25. local game_data = lobby.savedata.data[map_id]
  26. lobby.xp[map_id] = lobby.xp[map_id] + earned_xp
  27. local needed_xp = game_data['xp'] - lobby.xp[map_id]
  28. minetest.chat_send_player(name, 'You just earned '..earned_xp..' XP for your team.\nYou need '..needed_xp..' more XP to defeat the imposter.')
  29. tasks.check_xp(map_id, needed_xp)
  30. else
  31. minetest.chat_send_player(name, 'You\'re the traitor, you can do tasks, but you won\'t earn XP. Try killing the other players.')
  32. end
  33. end
  34. end
  35. end
  36. end
  37. function tasks.only_add_xp(xp, name) -- This function only adds XP, you are responsible for modifying the task node yourself.
  38. local player = minetest.get_player_by_name(name)
  39. local ghost = player:get_attribute('ghost')
  40. if ghost == 'false' then
  41. local map_id = lobby.game[name]
  42. local traitor = lobby.traitors[map_id]
  43. if map_id ~= 'lobby' then
  44. if name ~= traitor then
  45. local game_data = lobby.savedata.data[map_id]
  46. lobby.xp[map_id] = lobby.xp[map_id] + xp
  47. local needed_xp = game_data['xp'] - lobby.xp[map_id]
  48. minetest.chat_send_player(name, 'You just earned '..xp..' XP for your team.\nYou need '..needed_xp..' more XP to defeat the imposter.')
  49. tasks.check_xp(map_id, needed_xp)
  50. else
  51. minetest.chat_send_player(name, 'You\'re the traitor, you can do tasks, but you won\'t earn XP. Try killing the other players.')
  52. end
  53. end
  54. end
  55. end
  56. tasks.formspec_configuration =
  57. 'size[6,3]'..
  58. 'label[.5,.25;Please enter data in this format: \nXP, Timer_Duration, Task_name]'..
  59. 'field[1,1.5;5,1;input;;]'..
  60. 'button_exit[2,2;2,1;save;Submit]'