init.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. lottclasses = {}
  2. minetest.register_privilege("GAMEwizard", {
  3. description = "A wizard player",
  4. give_to_singleplayer = false,
  5. give_to_admin = true,
  6. })
  7. minetest.register_privilege("GAMEmale", {
  8. description = "A male player",
  9. give_to_singleplayer = false,
  10. })
  11. minetest.register_privilege("GAMEfemale", {
  12. description = "A female player",
  13. give_to_singleplayer = false,
  14. })
  15. minetest.register_privilege("GAMEdwarf", {
  16. description = "A dwarf player",
  17. give_to_singleplayer = false,
  18. })
  19. minetest.register_privilege("GAMEelf", {
  20. description = "An elf player",
  21. give_to_singleplayer = false,
  22. })
  23. minetest.register_privilege("GAMEman", {
  24. description = "A human player",
  25. give_to_singleplayer = false,
  26. })
  27. minetest.register_privilege("GAMEorc", {
  28. description = "An orc player",
  29. give_to_singleplayer = false,
  30. })
  31. minetest.register_privilege("GAMEhobbit", {
  32. description = "A hobbit player",
  33. give_to_singleplayer = false,
  34. })
  35. dofile(minetest.get_modpath("lottclasses").."/change-privs.lua")
  36. dofile(minetest.get_modpath("lottclasses").."/allies.lua")
  37. local race_chooser = "size[8,6]"..
  38. "background[8,6;1,1;gui_formbg.png;true]"..
  39. "label[0,0;" .. minetest.colorize("#A52A2A", "Please select the race you wish to be") .. "]"..
  40. "image[0.25,1.4;0.75,0.75;dwarf.png]"..
  41. "button_exit[1,1.5;2,0.5;dwarf;Dwarf]"..
  42. "image[4.75,1.4;0.75,0.75;elf.png]"..
  43. "button_exit[5.5,1.5;2,0.5;elf;Elf]"..
  44. "image[0.25,2.4;0.75,0.75;man.png]"..
  45. "button_exit[1,2.5;2,0.5;man;Man]"..
  46. "image[4.75,2.4;0.75,0.75;orc.png]"..
  47. "button_exit[5.5,2.5;2,0.5;orc;Orc]"..
  48. "image[0.25,3.4;0.75,0.75;hobbit.png]"..
  49. "button_exit[1,3.5;2,0.5;hobbit;Hobbit]"..
  50. "dropdown[5.5,3.4;2;gender;Male,Female;1]"
  51. local fly_stuff = "button[1,4.75;2,0.5;fast;Fast]" ..
  52. "button[3,4.75;2,0.5;fly;Fly]" ..
  53. "button[5,4.75;2,0.5;noclip;Noclip]" ..
  54. "button[2.5,5.5;3,0.5;fast_fly_noclip;Fast, Fly & Noclip]"
  55. local function give_stuff_dwarf(player)
  56. local inv = player:get_inventory()
  57. inv:add_item('main', 'default:pick_steel')
  58. inv:add_item('main', 'lottweapons:steel_warhammer')
  59. inv:add_item('main', 'farming:bread 5')
  60. inv:add_item('main', 'default:torch 8')
  61. inv:add_item('main', 'lottinventory:crafts_book')
  62. inv:add_item('main', 'lottachievements:achievement_book')
  63. end
  64. local function give_stuff_elf(player)
  65. local inv = player:get_inventory()
  66. inv:add_item('main', 'default:pick_steel')
  67. inv:add_item('main', 'lottthrowing:bow_wood')
  68. inv:add_item('main', 'lottthrowing:arrow 25')
  69. inv:add_item('main', 'farming:bread 5')
  70. inv:add_item('main', 'lottblocks:elf_torch 8')
  71. inv:add_item('main', 'lottinventory:crafts_book')
  72. inv:add_item('main', 'lottachievements:achievement_book')
  73. end
  74. local function give_stuff_man(player)
  75. local inv = player:get_inventory()
  76. inv:add_item('main', 'default:pick_bronze')
  77. inv:add_item('main', 'default:sword_bronze')
  78. inv:add_item('main', 'farming:bread 5')
  79. inv:add_item('main', 'default:torch 8')
  80. inv:add_item('main', 'lottinventory:crafts_book')
  81. inv:add_item('main', 'lottachievements:achievement_book')
  82. end
  83. local function give_stuff_orc(player)
  84. local inv = player:get_inventory()
  85. inv:add_item('main', 'lottweapons:orc_sword')
  86. inv:add_item('main', 'default:pick_steel')
  87. inv:add_item('main', 'lottfarming:orc_food 5')
  88. inv:add_item('main', 'lottblocks:orc_torch 8')
  89. inv:add_item('main', 'lottinventory:crafts_book')
  90. inv:add_item('main', 'lottachievements:achievement_book')
  91. end
  92. local function give_stuff_hobbit(player)
  93. local inv = player:get_inventory()
  94. inv:add_item('main', 'default:pick_stone')
  95. inv:add_item('main', 'farming:hoe_steel')
  96. inv:add_item('main', 'lottfarming:tomatoes_seed 2')
  97. inv:add_item('main', 'lottfarming:potato_seed 3')
  98. inv:add_item('main', 'lottfarming:pipe')
  99. inv:add_item('main', 'lottfarming:pipeweed_cooked 8')
  100. inv:add_item('main', 'lottinventory:crafts_book')
  101. inv:add_item('main', 'lottachievements:achievement_book')
  102. end
  103. local function give_stuff_wizard(player)
  104. local inv = player:get_inventory()
  105. inv:add_item('main', 'default:pick_steel')
  106. inv:add_item('main', 'default:axe_steel')
  107. inv:add_item('main', 'default:shovel_steel')
  108. inv:add_item('main', 'default:sword_steel')
  109. inv:add_item('main', 'lottinventory:master_book')
  110. inv:add_item('main', 'lottachievements:achievement_book')
  111. end
  112. local immune_spawn_amt = tonumber(minetest.settings:get("immune_spawn")) or 300
  113. minetest.settings:set("immune_spawn", immune_spawn_amt)
  114. local immune_amt = tonumber(minetest.settings:get("immune_spawn"))
  115. minetest.register_on_newplayer(function(player)
  116. local name = player:get_player_name()
  117. local privs = minetest.get_player_privs(name)
  118. if minetest.get_player_privs(name).GAMEwizard then
  119. give_stuff_wizard(player)
  120. end
  121. -- Starter mob immunity to counter unfavourable spawns
  122. if minetest.setting_getbool("disable_immune_spawn") then
  123. return
  124. end
  125. if minetest.setting_getbool("enable_damage") then
  126. player:set_attribute("lott:immunity", immune_amt)
  127. armor:set_player_armor(player)
  128. minetest.after(5, function()
  129. if player == nil then return end
  130. minetest.chat_send_player(name, minetest.colorize("green", "Starter mob immunity granted for "..immune_amt/ 60 .." minutes! Travel to a safe area!"))
  131. end)
  132. for i = 1, immune_amt do
  133. minetest.after(i, function()
  134. if player == nil then return end
  135. if not player:get_attribute("lott:immunity") then return end
  136. player:set_attribute("lott:immunity", tonumber(player:get_attribute("lott:immunity")) - 1)
  137. end)
  138. end
  139. minetest.after(immune_amt+1, function()
  140. player:set_attribute("lott:immunity", nil)
  141. minetest.chat_send_player(name, minetest.colorize("orange", "Your starter mob immunity has expired!"))
  142. armor:set_player_armor(player)
  143. end)
  144. end
  145. end)
  146. minetest.register_on_joinplayer(function(player)
  147. local name = player:get_player_name()
  148. local privs = minetest.get_player_privs(name)
  149. if minetest.get_player_privs(name).GAMEwizard then
  150. multiskin[name].skin = "wizard_skin.png"
  151. elseif minetest.get_player_privs(name).GAMEmale then
  152. if minetest.get_player_privs(name).GAMEdwarf then
  153. multiskin[name].skin = "dwarf_skin.png"
  154. elseif minetest.get_player_privs(name).GAMEelf then
  155. multiskin[name].skin = "elf_skin.png"
  156. elseif minetest.get_player_privs(name).GAMEman then
  157. multiskin[name].skin = "man_skin.png"
  158. elseif minetest.get_player_privs(name).GAMEorc then
  159. multiskin[name].skin = "orc_skin.png"
  160. elseif minetest.get_player_privs(name).GAMEhobbit then
  161. multiskin[name].skin = "hobbit_skin.png"
  162. end
  163. elseif minetest.get_player_privs(name).GAMEfemale then
  164. if minetest.get_player_privs(name).GAMEdwarf then
  165. multiskin[name].skin = "dwarf_skinf.png"
  166. elseif minetest.get_player_privs(name).GAMEelf then
  167. multiskin[name].skin = "elf_skinf.png"
  168. elseif minetest.get_player_privs(name).GAMEman then
  169. multiskin[name].skin = "man_skinf.png"
  170. elseif minetest.get_player_privs(name).GAMEorc then
  171. multiskin[name].skin = "orc_skin.png"
  172. elseif minetest.get_player_privs(name).GAMEhobbit then
  173. multiskin[name].skin = "hobbit_skinf.png"
  174. end
  175. else
  176. minetest.after(1, function()
  177. if minetest.is_singleplayer() then
  178. minetest.show_formspec(name, "race_selector", race_chooser .. fly_stuff)
  179. else
  180. minetest.show_formspec(name, "race_selector", race_chooser)
  181. end
  182. end)
  183. end
  184. -- Resume starter mob immunity
  185. if player:get_attribute("lott:immunity") ~= nil then
  186. if not tonumber(player:get_attribute("lott:immunity")) then
  187. player:set_attribute("lott:immunity", nil)
  188. return
  189. end
  190. if tonumber(player:get_attribute("lott:immunity")) >= immune_amt then
  191. return
  192. end
  193. minetest.chat_send_player(name, minetest.colorize("green", "Your starter mob immunity has resumed!"))
  194. minetest.chat_send_player(name, minetest.colorize("green", "You still have "..tonumber(player:get_attribute("lott:immunity")) / 60 .." minutes left!"))
  195. for i = 1, tonumber(player:get_attribute("lott:immunity")) do
  196. if not tonumber(player:get_attribute("lott:immunity")) then
  197. player:set_attribute("lott:immunity", nil)
  198. return
  199. end
  200. minetest.after(i, function()
  201. if player == nil then return end
  202. if not player:get_attribute("lott:immunity") then return end
  203. player:set_attribute("lott:immunity", tonumber(player:get_attribute("lott:immunity")) - 1)
  204. end)
  205. end
  206. minetest.after(player:get_attribute("lott:immunity")+1, function()
  207. if player == nil then return end
  208. player:set_attribute("lott:immunity", nil)
  209. armor:set_player_armor(player)
  210. minetest.chat_send_player(name, minetest.colorize("orange", "Your starter mob immunity has expired!"))
  211. end)
  212. end
  213. end)
  214. local function player_race_stuff(race, text, mf, func, name, privs, player)
  215. minetest.chat_send_player(name, "You are now a member of the race of " .. text ..", go forth into the world.")
  216. privs["GAME" .. race] = true
  217. privs["GAME" .. mf] = true
  218. minetest.set_player_privs(name, privs)
  219. if minetest.settings:get_bool("lott_give_initial_stuff", true) == true then
  220. func(player)
  221. end
  222. if mf == "male" or race == "orc" or race == "wizard" then
  223. default.player_set_textures(player, {race .. "_skin.png", "lottarmor_trans.png", "lottarmor_trans.png", "lottarmor_trans.png"})
  224. multiskin[name].skin = race .. "_skin.png"
  225. elseif mf == "female" then
  226. default.player_set_textures(player, {race .. "_skinf.png", "lottarmor_trans.png", "lottarmor_trans.png", "lottarmor_trans.png"})
  227. multiskin[name].skin = race .. "_skinf.png"
  228. end
  229. minetest.log("action", name.. " chose to be a " .. race)
  230. end
  231. minetest.register_on_player_receive_fields(function(player, formname, fields)
  232. if formname ~= "race_selector" then return end
  233. local name = player:get_player_name()
  234. local privs = minetest.get_player_privs(name)
  235. if fields.gender == "Male" then
  236. if fields.dwarf then
  237. player_race_stuff("dwarf", "dwarves", "male", give_stuff_dwarf, name, privs, player)
  238. elseif fields.elf then
  239. player_race_stuff("elf", "elves", "male", give_stuff_elf, name, privs, player)
  240. elseif fields.man then
  241. player_race_stuff("man", "men", "male", give_stuff_man, name, privs, player)
  242. elseif fields.orc then
  243. player_race_stuff("orc", "orcs", "male", give_stuff_orc, name, privs, player)
  244. elseif fields.hobbit then
  245. player_race_stuff("hobbit", "hobbits", "male", give_stuff_hobbit, name, privs, player)
  246. end
  247. elseif fields.gender == "Female" then
  248. if fields.dwarf then
  249. player_race_stuff("dwarf", "dwarves", "female", give_stuff_dwarf, name, privs, player)
  250. elseif fields.elf then
  251. player_race_stuff("elf", "elves", "female", give_stuff_elf, name, privs, player)
  252. elseif fields.man then
  253. player_race_stuff("man", "men", "female", give_stuff_man, name, privs, player)
  254. elseif fields.orc then
  255. player_race_stuff("orc", "orcs", "female", give_stuff_orc, name, privs, player)
  256. elseif fields.hobbit then
  257. player_race_stuff("hobbit", "hobbits", "female", give_stuff_hobbit, name, privs, player)
  258. end
  259. end
  260. if fields.fast then
  261. privs.fast = true
  262. minetest.set_player_privs(name, privs)
  263. return
  264. elseif fields.fly then
  265. privs.fly = true
  266. minetest.set_player_privs(name, privs)
  267. return
  268. elseif fields.noclip then
  269. privs.noclip = true
  270. minetest.set_player_privs(name, privs)
  271. return
  272. elseif fields.fast_fly_noclip then
  273. privs.fly, privs.fast, privs.noclip = true, true, true
  274. minetest.set_player_privs(name, privs)
  275. return
  276. end
  277. end)
  278. minetest.register_chatcommand("race", {
  279. params = "<name>",
  280. description = "print out privileges of player",
  281. func = function(name, param)
  282. param = (param ~= "" and param or name)
  283. if minetest.check_player_privs(param, {GAMEwizard = true}) then
  284. return true, "Race of " .. param .. ": Wizard"
  285. elseif minetest.check_player_privs(param, {GAMEdwarf = true}) then
  286. return true, "Race of " .. param .. ": Dwarf"
  287. elseif minetest.check_player_privs(param, {GAMEelf = true}) then
  288. return true, "Race of " .. param .. ": Elf"
  289. elseif minetest.check_player_privs(param, {GAMEman = true}) then
  290. return true, "Race of " .. param .. ": Man"
  291. elseif minetest.check_player_privs(param, {GAMEorc = true}) then
  292. return true, "Race of " .. param .. ": Orc"
  293. elseif minetest.check_player_privs(param, {GAMEhobbit = true}) then
  294. return true, "Race of " .. param .. ": Hobbit"
  295. elseif minetest.check_player_privs(param, {shout = true}) ~= nil then
  296. if param == name then
  297. if minetest.is_singleplayer() then
  298. minetest.show_formspec(name, "race_selector", race_chooser .. fly_stuff)
  299. else
  300. minetest.show_formspec(name, "race_selector", race_chooser)
  301. end
  302. else
  303. return true, param .. " has not chosen a race!"
  304. end
  305. else
  306. return true, param .. " does not exist!"
  307. end
  308. end,
  309. })