function sabotage.traitor_formspec(pos)
   local meta = minetest.get_meta(pos)
   local timer = meta:get_int('timer') or 0
   local chance = meta:get_int('chance') or 1
   local damage = meta:get_int('damage') or 1
   local xp = meta:get_int('xp') or 0
   local terminate = meta:get_string('terminate')
   local formspec = 'formspec_version[3]'
   if terminate == 'true' then
      formspec = formspec..
      'size[10,8]'..
      'textarea[.5,.5;9,6;;;Sabotage the crew, and risk life and limb.\n'..
      'If you fail in sabotaging you could take up '..damage..' damage. '..
      'If the crew fails to repair the node before the timer runs out you will win the level, '..
      'however if they are successful they will win.'..
      '\n\nRisk Factor: '..chance..'/10 \nPotential Health Impact: '..damage..' \nFailure Timer: '..timer..' seconds \n'..xp..' XP awarded to crew if node is repaired.]'..
      'button_exit[3.5,7;3,.75;sabotage;Do It]'
   else
      formspec = formspec..
      'size[10,8]'..
      'textarea[.5,.5;9,6;;;Sabotage the crew, and risk life and limb.\n'..
      'If you fail in sabotaging you could take up '..damage..' damage. '..
      '\n\nRisk Factor: '..chance..'/10 \nPotential Health Impact: '..damage..' \nFailure Timer: '..timer..' seconds \n'..xp..' XP awarded to crew if node is repaired.]'..
      'button_exit[3.5,7;3,.75;sabotage;Do It]'
   end
   return formspec
end

function sabotage.builder_formspec(pos)
   local meta = minetest.get_meta(pos)
   local timer = meta:get_int('timer') or 120
   local chance = meta:get_int('chance') or 1
   local damage = meta:get_int('damage') or 1
   local alert = meta:get_string('alert') or ''
   local level = meta:get_int('level') or 1
   local xp = meta:get_int('xp') or 0
   local terminate = meta:get_string('terminate')
   local formspec =
      'formspec_version[3]'..
      'size[16,9]'..
      'textarea[1,.5;14,3.5;;;You can set many different aspects of sabotage, hopefully the following information clarifies what all the different settings/options do.\n '..
      'Alert Text: This text will be displayed to all players on the level when the node is sabotaged. Use it to tell players where to look, or to say what was sabotaged. A HUD will also be displayed with the node description and a timer if one is set.\n'.. -- try and clarify math.random(10) + luck >= chance
      'Chance: The chance that a sabotage attempt will fail. A random number 1-10 will be rolled, and the traitors luck level will be added, if the resulting value is greater or equal to the chance the sabotaging will be successful.\n'..
      'Damage: The max amount of damage the traitor might incur while trying to sabotage a node. This uses the same math as the chance, but with a different random number.\n'..
      'Timer: (Optional) if you choose to use a timer the sabotaged node will be available to fix for a set time.\n'..
      'Sabotage level: This controls which tasks can be completed or nodes can be interacted with. Levels can be 1-4, and configurable nodes can have levels defined. If the node\'s level is below the sabotage level it can be interacted with while the node is sabotaged. This can be used to restrict access to areas during sabotage, or to prevent tasks from being completed.\n'..
      'XP: (Optional) The amount of XP that should be awarded the team upon successful \'repairing\' of the sabotaged node.\n'..
      'End Match: Check this box to end the match when the node is repaired or the timer runs out. The traitor will win if the node hasn\'t been repaired, and the team will win if they repair the node.]'..
      'textarea[1,5;14,1;alert;Alert Text:;'..alert..']'..
      'field[1,6.5;2,.75;chance;Chance:;'..chance..']'..
      'field[4,6.5;2,.75;damage;Damage:;'..damage..']'..
      'field[7,6.5;2,.75;timer_input;Timer:;'..timer..']'..
      'field[10,6.5;2,.75;level;Sabotage level:;'..level..']'..
      'field[13,6.5;2,.75;xp;XP:;'..xp..']'..
      'checkbox[1,8;terminate;End Match;'..terminate..']'..
      'button_exit[6.5,7.5;3,1;save;Save]'
   return formspec
end

function sabotage.player_formspec(pos)
   local meta = minetest.get_meta(pos)
   local chance = meta:get_int('chance') or 1
   local damage = meta:get_int('damage') or 1
   local xp = meta:get_int('xp') or 0
   local formspec =
      'formspec_version[3]'..
      'size[10,8]'..
      'textarea[.5,.5;9,6;;;Careful now, you could get hurt messing around here, '..
      'but you could save the lives of the entire party. Ultimately it\'s your choice.\n'..
      '\nRisk Factor: '..chance..'/10 \nPotential Health Impact: '..damage..'\nXP awarded: '..xp..']'..
      'button_exit[1.5,7;3,.75;repair;Attempt Repairs]'..
      'button_exit[5.5,7;3,.75;leave;Cower in Fear]'
   return formspec
end
