init.lua 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. survivalist = survivalist or {}
  2. survivalist.modpath = minetest.get_modpath("survivalist")
  3. survivalist.players = survivalist.players or {}
  4. survivalist.groups = survivalist.groups or {}
  5. -- XP requirements. Amounts are somewhat arbitrary.
  6. survivalist.xp_minimum = 700
  7. survivalist.xp_surface = 700
  8. survivalist.xp_cave = 1500
  9. survivalist.xp_nether = 2400
  10. -- XP completion requirements. Amounts are somewhat arbitrary.
  11. survivalist.completion_xp_surface = 1100
  12. survivalist.completion_xp_cave = 2700
  13. survivalist.completion_xp_nether = 4500
  14. function survivalist.have_xp(pname, ch)
  15. local amount = (survivalist["xp_" .. ch]) or 0
  16. return (xp.get_xp(pname, "digxp") >= amount)
  17. end
  18. -- Localize for performance.
  19. local vector_distance = vector.distance
  20. local vector_round = vector.round
  21. local math_floor = math.floor
  22. local math_random = math.random
  23. -- Positions of surface & nether cities.
  24. local surfacecitypos = {x=0, y=-8, z=0}
  25. local nethercitypos = {x=0, y=-30793, z=0}
  26. -- Valid gamemodes are 'surface', 'cave', & 'nether'.
  27. -- The game rules description. Shown in formspec.
  28. survivalist.gamerules =
  29. "===| Survival Challenge Description |===\n\n" ..
  30. "This page contains the rules for this mini-game, with options to begin a Challenge or claim victory on a Challenge currently in-progress.\n\n" ..
  31. "The Survival Challenge focuses on survival in the wild far from developed regions. You can play it solo or with other players.\n\n" ..
  32. "You will need to scroll this text in order to read all of it.\n\n" ..
  33. "When beginning a Challenge it is possible to end up in a starting situation where survival is impossible. You always have the option to cancel without affecting your score.\n\n" ..
  34. "On accepting a challenge you are transported into a small dungeon, which is at a distant location in the world very far from the Surface Colony and the Nether City. The minimum distance you’ll be teleported is 10,000 meters; the server will not choose a dungeon closer to either city than this. You’ll have the basic starting items that every player starts with when they first join the server, and the dungeon has a chest containing additional items to make getting a head-start a little easier, since otherwise some scenarios would be impossible to beat. The chest contents differ between challenge types and are somewhat random.\n\n" ..
  35. "Before you can begin a challenge all your inventories must be empty: your main inventory, your craft grid, the craft-preview and craft-output inventory slots (yes, those too, cheaters!), your Star-Fissure Box, your armor inventory, your bags, and the wielditem inventory (if you don’t know what this is, then don’t worry about it). Proof of Citizenship tokens are exempt.\n\n" ..
  36. "You can play this mini-game cooperatively. To do so one player should to start a Survival Challenge just as if they were going to play solo. Whenever a player starts a Challenge there is a 5 minute window in which other players can join the first player by being transported to the same dungeon. To join another player in their dungeon, you must stand within 5 meters of the place where they stood at the time they began their Challenge. You must also choose the same gamemode (Iceworld, Underearth, or Netherealm) as the first player. If you are too far away, or you choose a wrong gamemode, or the 5 minute window has passed, you won’t be transported to the same dungeon. If you are are unsuccessful and are not teleported to the same dungeon, you can simply cancel and try again if you wish. There is no limit on the number of players who may play cooperatively. Every player who joins extends the 5-minute window a bit. Do note that supplies are not increased with each player beyond the first, so you’ll need to share. Players win or lose the Challenge separately, so if one player has a fatal accident, the remaining players can keep playing.\n\n" ..
  37. "Finding a suitable location to build the starting dungeon can take the server some time, so you have a few seconds to interact with the world after accepting a challenge. Don’t rely on this, though.\n\n" ..
  38. "(Note to builders in distant lands: the server will not overwrite any of your builds when creating a player’s starting dungeon, as long as your builds are protected. Although the world is vast and the chance of randomly selecting a location inside someone else’s home is small, the server nonetheless performs checks to avoid accidents.)\n\n" ..
  39. "In order to win after starting a challenge, you must find your way back to the Surface Colony OR the Nether City and claim victory (press the ‘Claim Victory’ button below these rules) in the Central Square of either location. Finding civilization to claim victory is your goal; avoiding a fatal death during your travels in the wild is your challenge. Rules for death are below the Challenge descriptions.\n\n" ..
  40. "Note that you may to use your Proof of Citizenship to teleport you the rest of the way to the Surface Colony or Nether City once you are in range of the teleport beacons. Use of diamond teleporters is also allowed, as are flameportals which go to and from the Netherealm, or any other form of transportation. However, when starting a challenge your flameportal’s previous return position (if you had one set) is erased to prevent using a return portal as a ‘cheat’ to obtain an easy win. The same is true for beds.\n\n" ..
  41. "There are three challenge types: the Iceworld Challenge, the Underearth Challenge, and the Netherealm Challenge, with difficulty being in that order. Each challenge awards Skill Marks when victory is successfully claimed. The Skill Marks are Copper, Silver, and Gold. The amount of marks you’ll receive on successful completion of a challenge depends on the distance you travel to either the Surface Colony or the Nether City, starting from your initial dungeon. You receive 1 mark for every 1K meters of distance (rounded down), minus the first 10 kilometers. You always receive at least 1 Skill Mark.\n\n" ..
  42. "The following is a basic description of each challenge.\n\n" ..
  43. "In the Iceworld Challenge you start in an ice-and-brick dungeon at what is normally sea-level (if this server were to have a liquid sea). Chances are, you’ll be under a mountain or below a raised plain, so your first goal will be to dig up and find the surface. If you are very lucky you will be on an ice-lake instead. Avoid the icemen and don’t go out at night! This is the easiest challenge. The first time you complete it successfully, the skill learned causes your wield-hotbar (the 8 itemslots below your health and hunger stats) to expand to 16 slots for easier building. (Note: if you prefer the regular 8 slots anyway and don’t want the bigger version, you can let the server administrator know, to get it reset back to 8 slots!)\n\n" ..
  44. "In the Underearth Challenge you start in a cobble dungeon deep under the earth, between -24K and -3K. Since you are underground, your first priority is using the materials in the starting chest to build a small farm. Note that the server never locates a dungeon to be floating in the middle of a caverealm void, but it is remotely possible that you could have lava outside the dungeon walls. Once you have a food source, the main difficulty is digging your way to the surface or to the nether (if you choose to claim victory in the Nether City). Beware of mining instabilities! Note that this Challenge typically takes the longest to complete. Once you’ve established a base with a bed, consider using Obsidian Gateways to try and bring yourself closer to the surface. The first time you complete this Challenge, you unlock a hidden feature of the Key of Citizenship which allows you to jaunt (teleport) to other players who also possess a Key—provided their Key’s beacon signal can be successfully triangulated ….\n\n" ..
  45. "The Netherealm Challenge is similar to the Underearth Challenge, except that your starting dungeon is located in the second-worst place in the world, some 60 meters under the brimstone ocean. (The worst place in the world is the islands directly above all that lava.) Your starting dungeon is made of black rackstone, but don’t imagine you’ll be able to use it for anything except stone picks. You need to be very, very careful in this challenge, because lava is everywhere, and netherack is nasty to dig. There are very few usable resources in the nether, so finding the few resources you can is very important. The first thing you need to do is dig up to the islands without letting the brimstone ocean flow into your dungeon. Once there you can explore the brimstone cavern for a few meager resources. In this Challenge, you are recommended to claim victory in the Nether City rather than attempt to dig to the surface. However, those who dig to the surface will receive more reward. If you choose to dig up out of the nether into normal rock you’ll be able to find a few more resources, and the caverealms of the Underearth Challenge will seem like a garden. :-) The first time you beat this Challenge, you unlock a hidden feature of the Key of Citizenship which allows you to access its little-understood cloaking capabilities, which can render you invisible in all but a few circumstances ….\n\n" ..
  46. "After starting a Challenge you may cancel it without affecting your death/success score. This option is available as long as a Challenge is running. The conditions for canceling a challenge are the same as the conditions for starting one: all your inventories must be empty except for passport tokens. (You cannot bring anything with you when you cancel.) You may choose this option if, for instance, you do not like your starting situation. When you cancel a Challenge you are returned to the same spot you were when you began the Challenge.\n\n" ..
  47. "Rules for death: you lose the Challenge if you die and have not slept in a bed. Lacking a bed is your initial state whenever you begin a Challenge, and you avoid losing the Challenge by crafting a bed and sleeping in it. Afterwards if you die you will respawn in your bed and the Challenge will continue as before. Note that a bed is only good for a limited number of respawns, so you should remember to sleep often to refresh it.\n\n" ..
  48. "Warning: since your bed is lost if you are killed by another player (but not by a mob or the environment), the effect of being murdered is that you will fail the Challenge. Your murderer does not get any special benefits other than hearing your screams of fury.\n\n" ..
  49. "Each player’s total number of victories, fatal deaths, and victory streaks are recorded permanently, as well as the number of victories in the three individual challenges, and the total number of marks earned. This information is never reset.\n\n" ..
  50. "===| Challenge Description End |==="
  51. -- Add player to a list of players contained in the database.
  52. -- This is because we can't iterate over the database entries directly,
  53. -- so we need a way to find all players who have ranking entries.
  54. function survivalist.add_player_to_rankings(pname)
  55. -- Obtain the database in string form.
  56. local data = survivalist.modstorage:get_string(":ranked_players:")
  57. -- If the string is empty, create a dummy table for deserialization.
  58. if data == "" then
  59. data = "return {}"
  60. end
  61. -- Deserialize the rankings database into a table.
  62. local tb = minetest.deserialize(data)
  63. -- Add player to table.
  64. tb[pname] = true
  65. -- Reserialize the database table.
  66. local serialized = minetest.serialize(tb)
  67. -- Don't overwrite the old database unless the table serialized successfully.
  68. if type(serialized) == "string" then
  69. survivalist.modstorage:set_string(":ranked_players:", serialized)
  70. end
  71. end
  72. function survivalist.get_ranking_entries()
  73. -- Obtain the database in string form.
  74. local data = survivalist.modstorage:get_string(":ranked_players:")
  75. -- If the string is empty, create a dummy table for deserialization.
  76. if data == "" then
  77. data = "return {}"
  78. end
  79. -- Deserialize the rankings database into a table.
  80. local tb = minetest.deserialize(data)
  81. -- Return the table.
  82. return tb or {}
  83. end
  84. function survivalist.inventory_empty(inv, name)
  85. local count = 0
  86. for i = 1, inv:get_size(name) do
  87. local stack = inv:get_stack(name, i)
  88. if not passport.is_passport(stack:get_name()) then
  89. if stack:get_count() > 0 then
  90. count = count + stack:get_count()
  91. end
  92. end
  93. end
  94. return (count == 0)
  95. end
  96. function survivalist.check_inventories_empty(pname)
  97. local player = minetest.get_player_by_name(pname)
  98. if not player then
  99. return
  100. end
  101. local inv = player:get_inventory()
  102. if survivalist.inventory_empty(inv, "main") and
  103. survivalist.inventory_empty(inv, "craft") and
  104. survivalist.inventory_empty(inv, "armor") and
  105. survivalist.inventory_empty(inv, "voidchest:voidchest") and
  106. survivalist.inventory_empty(inv, "craftresult") and
  107. survivalist.inventory_empty(inv, "craftpreview") and
  108. survivalist.inventory_empty(inv, "bag1contents") and
  109. survivalist.inventory_empty(inv, "bag2contents") and
  110. survivalist.inventory_empty(inv, "bag3contents") and
  111. survivalist.inventory_empty(inv, "bag4contents") and
  112. survivalist.inventory_empty(inv, "xchest") and
  113. survivalist.inventory_empty(inv, "bag1") and
  114. survivalist.inventory_empty(inv, "bag2") and
  115. survivalist.inventory_empty(inv, "bag3") and
  116. survivalist.inventory_empty(inv, "bag4") then
  117. return true
  118. end
  119. end
  120. -- Loot parameters & stuff.
  121. dofile(survivalist.modpath .. "/loot.lua")
  122. -- Actually teleport the player to the start location and announce in chat.
  123. -- Also, record that the game has begun.
  124. function survivalist.teleport_and_announce(pname, pos, gamemode)
  125. local player = minetest.get_player_by_name(pname)
  126. if not player then
  127. return
  128. end
  129. -- Player's inventories must be empty.
  130. if not survivalist.check_inventories_empty(pname) then
  131. minetest.chat_send_player(pname, "# Server: All your inventories (including the Starfissure Box and armor) must be empty before you can begin a challenge (the Proof of Citizenship does not count). You will receive starting items when you begin.")
  132. easyvend.sound_error(pname)
  133. return
  134. end
  135. -- Abort if player is trying to cheat by sitting in a cart. >:)
  136. if default.player_attached[pname] then
  137. minetest.chat_send_player(pname, "# Server: Transport error. Player attached!")
  138. return
  139. end
  140. -- Record home position.
  141. local homepos = vector_round(player:get_pos())
  142. -- Teleport player.
  143. wield3d.on_teleport()
  144. player:set_pos(vector.add(pos, {x=math_random(-3, 3), y=0.5, z=math_random(-3, 3)}))
  145. -- Make sure player is healthy.
  146. heal.heal_health_and_hunger(pname)
  147. -- Remove posibility of cheating via netherportals.
  148. flameportal.clear_return_location(pname)
  149. -- Clear bed respawn position. Player must make new bed to survive.
  150. beds.clear_player_spawn(pname)
  151. -- Give the game name some interesting names.
  152. local gamestring = "Void"
  153. if gamemode == "surface" then
  154. gamestring = "Iceworld"
  155. elseif gamemode == "cave" then
  156. gamestring = "Underearth"
  157. elseif gamemode == "nether" then
  158. gamestring = "Netherealm"
  159. end
  160. -- Inform player the game has begun.
  161. if not gdac.player_is_admin(pname) then
  162. local dname = rename.gpn(pname)
  163. minetest.chat_send_all("# Server: Player <" .. dname .. "> has begun a test of skill in the " .. gamestring .. " at " .. rc.pos_to_namestr(vector_round(pos)) .. "!")
  164. else
  165. minetest.chat_send_player(pname, "# Server: You have begun a test of skill in the " .. gamestring .. " at " .. rc.pos_to_namestr(vector_round(pos)) .. "!")
  166. end
  167. survivalist.shout_player_stats(pname)
  168. minetest.chat_send_player(pname, "# Server: To win, you must find the city and claim victory in the Main Square. If you die without sleeping, you will fail the Challenge.")
  169. -- Give player the starting items.
  170. give_initial_stuff.give(player)
  171. -- Record the player's new gamemode.
  172. survivalist.modstorage:set_string(pname .. ":mode", gamemode)
  173. -- Record the player's starting position.
  174. survivalist.modstorage:set_string(pname .. ":pos", minetest.pos_to_string(vector_round(pos)))
  175. -- Record the player's home position. Used when canceling a Challenge.
  176. survivalist.modstorage:set_string(pname .. ":home", minetest.pos_to_string(homepos))
  177. -- Record the amount of XP player has at the start of the Challenge.
  178. survivalist.modstorage:set_string(pname .. ":xp", tostring(xp.get_xp(pname, "digxp")))
  179. -- Record that this player is accepting groups.
  180. survivalist.groups[pname] = survivalist.groups[pname] or {count=0}
  181. survivalist.groups[pname].count = survivalist.groups[pname].count + 1
  182. minetest.after(60*5, function()
  183. if survivalist.groups[pname] then
  184. survivalist.groups[pname].count = survivalist.groups[pname].count - 1
  185. if survivalist.groups[pname].count <= 0 then
  186. survivalist.groups[pname] = nil
  187. end
  188. end
  189. end)
  190. end
  191. -- This function must find a location for the player and teleport them there.
  192. -- Also create a starting dungeon (must not destroy protected stuff) and a chest with extra resources.
  193. function survivalist.prepare_dungeon(pname, pos, gamemode)
  194. -- Positions to load. Need a larger area in order to make sure any protections are discovered.
  195. local minp = vector.add(pos, vector.new(-64, -64, -64))
  196. local maxp = vector.add(pos, vector.new(64, 64, 64))
  197. -- Dungeon coordinates.
  198. local dminp = vector.add(pos, vector.new(-4, 0, -4))
  199. local dmaxp = vector.add(pos, vector.new(4, 4, 4))
  200. -- Copy the position table so it doesn't get modified.
  201. local pos2 = table.copy(pos)
  202. -- Build callback function. When the map is loaded, we need to check protections and create the dungeon.
  203. local tbparam = {}
  204. local cb = function(blockpos, action, calls_remaining, param)
  205. if action == core.EMERGE_CANCELLED or action == core.EMERGE_ERRORED then
  206. minetest.chat_send_player(pname, "# Server: Internal error, try again or report.")
  207. easyvend.sound_error(pname)
  208. return
  209. end
  210. -- We don't do anything until the last callback.
  211. if calls_remaining ~= 0 then
  212. return
  213. end
  214. -- Check for the presence of a city-block.
  215. if city_block:in_city_suburbs(pos2) then
  216. minetest.chat_send_player(pname, "# Server: Error: did not succeed in finding a suitable start location! If this happens, just try again.")
  217. easyvend.sound_error(pname)
  218. return
  219. end
  220. -- Check for protections, and if there are none, create a dungeon.
  221. for x = dminp.x, dmaxp.x, 1 do
  222. for y = dminp.y, dmaxp.y, 1 do
  223. for z = dminp.z, dmaxp.z, 1 do
  224. if minetest.test_protection({x=x, y=y, z=z}, "") then
  225. -- Return failure if target is protected. This shouldn't happen often.
  226. minetest.chat_send_player(pname, "# Server: Error: did not succeed in finding a suitable start location! If this happens, just try again.")
  227. easyvend.sound_error(pname)
  228. return
  229. end
  230. end
  231. end
  232. end
  233. -- Check if spawning in air (e.g., due to large cavern).
  234. if minetest.get_node(pos2).name == "air" then
  235. minetest.chat_send_player(pname, "# Server: Error: did not succeed in finding a suitable start location! If this happens, just try again.")
  236. easyvend.sound_error(pname)
  237. return
  238. end
  239. -- No protections? Create the dungeon.
  240. -- Generate dungeon for the player to spawn in.
  241. local path = survivalist.modpath .. "/schematics/survivalist_" .. gamemode .. "_dungeon.mts"
  242. minetest.place_schematic(vector.add(pos2, {x=-4, y=0, z=-4}), path, "random", nil, true)
  243. -- Choose a location for the chest.
  244. local chestpos = vector.add(pos2, vector.new(math_random(-3, 3), 1, math_random(-3, 3)))
  245. chestpos = vector_round(chestpos)
  246. -- Create chest with stuff.
  247. minetest.set_node(chestpos, {
  248. name = "morechests:goldchest_public_closed",
  249. param2 = math_random(0, 3),
  250. })
  251. local meta = minetest.get_meta(chestpos)
  252. local inv = meta:get_inventory()
  253. if inv then
  254. survivalist.fill_loot_chest(inv, gamemode)
  255. end
  256. -- Teleport player and announce.
  257. survivalist.teleport_and_announce(pname, pos2, gamemode)
  258. end
  259. -- Emerge the target area. Once emergence is complete the dungeon will spawn.
  260. minetest.chat_send_player(pname, "# Server: Checking reliability of target location ... please stand by, this can take several seconds.")
  261. minetest.emerge_area(minp, maxp, cb, tbparam)
  262. end
  263. function survivalist.shout_player_stats(pname)
  264. local ms = survivalist.modstorage
  265. local wins_total = pname .. ":wins_total"
  266. local wins_streak = pname .. ":wins_streak"
  267. local wins_surface = pname .. ":wins_surface"
  268. local wins_cave = pname .. ":wins_cave"
  269. local wins_nether = pname .. ":wins_nether"
  270. local wins_fail = pname .. ":wins_fail"
  271. local wins_bstreak = pname .. ":wins_bstreak"
  272. local wins_tokens = pname .. ":wins_tokens"
  273. if not gdac.player_is_admin(pname) then
  274. local dname = rename.gpn(pname)
  275. minetest.chat_send_all("# Server: Survivalist stats for <" ..
  276. dname .. ">: Victories: " .. ms:get_int(wins_total) ..
  277. ". Deaths: " .. ms:get_int(wins_fail) ..
  278. ". Iceworld: " .. ms:get_int(wins_surface) ..
  279. ". Underearth: " .. ms:get_int(wins_cave) ..
  280. ". Netherealm: " .. ms:get_int(wins_nether) ..
  281. ". C-Streak: " .. ms:get_int(wins_streak) ..
  282. ". B-Streak: " .. ms:get_int(wins_bstreak) ..
  283. ". Marks: " .. ms:get_int(wins_tokens) ..
  284. ".")
  285. end
  286. end
  287. function survivalist.game_in_progress(pname)
  288. local cg = survivalist.modstorage:get_string(pname .. ":mode")
  289. if cg == "surface" or cg == "cave" or cg == "nether" then
  290. return true
  291. end
  292. end
  293. -- This function is called when the player wants to begin the game.
  294. -- It must handle all game validation.
  295. function survivalist.start_game(pname, gamemode)
  296. -- Get player and make sure he exists.
  297. local player = minetest.get_player_by_name(pname)
  298. if not player then
  299. return
  300. end
  301. -- Is a game already running?
  302. local currentgame = survivalist.modstorage:get_string(pname .. ":mode")
  303. if currentgame == "surface" or currentgame == "cave" or currentgame == "nether" then
  304. minetest.chat_send_player(pname, "# Server: You are already engaged in a Survivalist Challenge, you cannot start a concurrent game.")
  305. easyvend.sound_error(pname)
  306. return
  307. end
  308. local pp = player:get_pos()
  309. if pp.y < -100 or pp.y > 1000 then
  310. minetest.chat_send_player(pname, "# Server: You need to be on the surface of the Overworld to start a challenge.")
  311. easyvend.sound_error(pname)
  312. return
  313. end
  314. -- Validate the gamemode.
  315. if type(gamemode) ~= "string" then
  316. minetest.chat_send_player(pname, "# Server: No starting option selected!")
  317. easyvend.sound_error(pname)
  318. return
  319. end
  320. if gamemode ~= "surface" and gamemode ~= "cave" and gamemode ~= "nether" then
  321. minetest.chat_send_player(pname, "# Server: You must choose a valid starting option!")
  322. easyvend.sound_error(pname)
  323. return
  324. end
  325. -- Player must have minimum XP for this kind of Challenge.
  326. if not survivalist.have_xp(pname, gamemode) then
  327. minetest.chat_send_player(pname, "# Server: Insufficient XP to start this Challenge.")
  328. easyvend.sound_error(pname)
  329. return
  330. end
  331. -- Player's inventories must be empty.
  332. if not survivalist.check_inventories_empty(pname) then
  333. minetest.chat_send_player(pname, "# Server: All your inventories (including the Starfissure Box and armor) must be empty before you can begin a challenge (the Proof of Citizenship does not count). You will receive starting items when you begin.")
  334. easyvend.sound_error(pname)
  335. return
  336. end
  337. local pos = {x=0, y=0, z=0}
  338. local group = false
  339. -- Group survival: check if the player should be grouped with someone else.
  340. local players = minetest.get_connected_players()
  341. for k, v in ipairs(players) do
  342. local oname = v:get_player_name()
  343. local omode = survivalist.modstorage:get_string(oname .. ":mode")
  344. -- Gamemodes must match.
  345. if omode == gamemode then
  346. local opos = minetest.string_to_pos(survivalist.modstorage:get_string(oname .. ":home"))
  347. -- Home position must have been recorded.
  348. if opos then
  349. -- We must be close enough to the other player's home pos, in order to be grouped with them.
  350. if vector_distance(opos, player:get_pos()) <= 5 then
  351. -- The other player must currently be accepting groups.
  352. -- Groups are not saved across restarts; this means that a player cannot
  353. -- team with another after the server restarts, even if less time than
  354. -- the time limit has gone by.
  355. if survivalist.groups[oname] then
  356. -- Get location of the other player's dungeon.
  357. local p2 = minetest.string_to_pos(survivalist.modstorage:get_string(oname .. ":pos"))
  358. if p2 then
  359. pos = p2
  360. group = true
  361. break
  362. end
  363. end
  364. end
  365. end
  366. end
  367. end
  368. if not group then
  369. -- Find a random position on the X,Z plane.
  370. while vector_distance(pos, surfacecitypos) < 10000 or vector_distance(pos, nethercitypos) < 10000 do
  371. for j, k in ipairs({"x", "z"}) do
  372. pos[k] = math_random(-30000, 30000)
  373. end
  374. -- Gamemode determines depth.
  375. if gamemode == "surface" then
  376. pos.y = -10
  377. elseif gamemode == "cave" then
  378. pos.y = math_random(-24000, -3000)
  379. elseif gamemode == "nether" then
  380. pos.y = math_random(-30860, -30810)
  381. end
  382. end
  383. end
  384. -- Prepare target location. The remaining logic is executed from a callback.
  385. if group then
  386. -- The dungeon has already been generated.
  387. survivalist.teleport_and_announce(pname, pos, gamemode)
  388. else
  389. -- Need to generate a dungeon, then teleport the player.
  390. survivalist.prepare_dungeon(pname, pos, gamemode)
  391. end
  392. end
  393. -- Checks if a player is in range to claim victory.
  394. -- Performs no other validation; this is a simple distance check.
  395. function survivalist.player_in_victory_range(pname)
  396. local player = minetest.get_player_by_name(pname)
  397. if not player then
  398. return
  399. end
  400. local pos = player:get_pos()
  401. if vector_distance(pos, surfacecitypos) <= 20 then
  402. return true
  403. elseif vector_distance(pos, nethercitypos) <= 20 then
  404. return true
  405. end
  406. end
  407. -- Called when the player wants to claim victory. Must validate.
  408. function survivalist.attempt_claim(pname)
  409. local player = minetest.get_player_by_name(pname)
  410. if not player then
  411. return
  412. end
  413. -- Make sure a game is actually running.
  414. local currentgame = survivalist.modstorage:get_string(pname .. ":mode")
  415. if currentgame ~= "surface" and currentgame ~= "cave" and currentgame ~= "nether" then
  416. minetest.chat_send_player(pname, "# Server: You are not currently engaged in a Survivalist Challenge.")
  417. easyvend.sound_error(pname)
  418. return
  419. end
  420. -- Check if player has earned the needed XP over the course of the Challenge.
  421. -- This ensures player does not complete the Challenge too fast, and needs to actually
  422. -- take some time, make a base/home, do some farming, etc!
  423. do
  424. local sxp = survivalist.modstorage:get_string(pname .. ":xp")
  425. local oxp = math.floor(tonumber(sxp) or 0)
  426. local cxp = math.floor(xp.get_xp(pname, "digxp"))
  427. local wxp = (survivalist["completion_xp_" .. currentgame]) or 0
  428. local dxp = (cxp - oxp)
  429. if dxp < wxp then
  430. local nxp = math.floor(oxp + wxp)
  431. minetest.chat_send_player(pname, "# Server: You need to obtain at least " .. wxp .. " XP over the course of the Challenge, first.")
  432. minetest.chat_send_player(pname, "# Server: You started with " .. oxp .. " XP. You must reach " .. nxp .. " XP!")
  433. easyvend.sound_error(pname)
  434. return
  435. end
  436. end
  437. -- Check if the player is in the city.
  438. local pos = player:get_pos()
  439. local cityname = ""
  440. -- The position and name of the city the player claims victory in.
  441. local finalcitypos
  442. if vector_distance(pos, surfacecitypos) <= 20 then
  443. finalcitypos = table.copy(surfacecitypos)
  444. cityname = "Surface Colony"
  445. elseif vector_distance(pos, nethercitypos) <= 20 then
  446. finalcitypos = table.copy(nethercitypos)
  447. cityname = "Nether City"
  448. end
  449. if not finalcitypos then
  450. minetest.chat_send_player(pname, "# Server: You must be within 20 meters of the main square of the Surface Colony or the Nether City in order to claim victory!")
  451. easyvend.sound_error(pname)
  452. return
  453. end
  454. -- What rank (copper, silver, gold) has the player earned?
  455. local ranks = {
  456. ["surface"] = {rank="copper", upper="Copper"},
  457. ["cave"] = {rank="silver", upper="Silver"},
  458. ["nether"] = {rank="gold", upper="Gold"},
  459. }
  460. local rank = ranks[currentgame].rank
  461. local upperank = ranks[currentgame].upper
  462. -- Reward the player.
  463. local tokencount = 1
  464. local startpos = minetest.string_to_pos(survivalist.modstorage:get_string(pname .. ":pos"))
  465. -- If the starting position couldn't be parsed we'll just give the player 1 token.
  466. if startpos then
  467. local dist = vector_distance(finalcitypos, startpos)
  468. -- Discount the minimum distance.
  469. dist = dist - 10000
  470. -- Get distance in kilometers.
  471. -- One skill mark per extra kilometer over 10k.
  472. dist = math_floor(dist / 1000)
  473. -- Clamp, just in case.
  474. if dist < 1 then
  475. dist = 1
  476. end
  477. tokencount = dist
  478. end
  479. local dname = rename.gpn(pname)
  480. if not gdac.player_is_admin(pname) then
  481. minetest.chat_send_all("# Server: Player <" .. dname .. "> has claimed victory in the " .. cityname .. "!")
  482. minetest.chat_send_all("# Server: Player <" .. dname .. ">'s skill has been tested in a Survival Challenge and proved worthy.")
  483. minetest.chat_send_all("# Server: Player <" .. dname .. "> has earned " .. tokencount .. " " .. upperank .. " Skill Mark(s).")
  484. else
  485. minetest.chat_send_player(pname, "# Server: You have won the Survival Challenge!")
  486. end
  487. local inv = player:get_inventory()
  488. local leftover = inv:add_item("main", ItemStack("survivalist:" .. rank .. "_skill_token " .. tokencount))
  489. -- No room in inventory? Drop 'em.
  490. if leftover:get_count() > 0 then
  491. minetest.item_drop(leftover, player, pos)
  492. if not gdac.player_is_admin(pname) then
  493. minetest.chat_send_all("# Server: Player <" .. dname .. ">'s Skill Mark was dropped on the ground!")
  494. end
  495. end
  496. minetest.chat_send_player(pname, "# Server: You should have received a skill mark in your inventory. If your inventory was full, check near your feet!")
  497. -- Record that the challenge is over.
  498. survivalist.modstorage:set_string(pname .. ":mode", nil)
  499. survivalist.modstorage:set_string(pname .. ":pos", nil)
  500. survivalist.modstorage:set_string(pname .. ":home", nil)
  501. survivalist.modstorage:set_string(pname .. ":xp", nil)
  502. survivalist.players[pname].choice = nil
  503. -- Record total wins, win streaks, and win types.
  504. local ms = survivalist.modstorage
  505. local wins_total = pname .. ":wins_total"
  506. local wins_streak = pname .. ":wins_streak"
  507. local wins_bstreak = pname .. ":wins_bstreak"
  508. local wins_type = pname .. ":wins_" .. currentgame
  509. local wins_tokens = pname .. ":wins_tokens"
  510. ms:set_int(wins_total, ms:get_int(wins_total) + 1)
  511. ms:set_int(wins_streak, ms:get_int(wins_streak) + 1)
  512. ms:set_int(wins_type, ms:get_int(wins_type) + 1)
  513. ms:set_int(wins_tokens, ms:get_int(wins_tokens) + tokencount)
  514. -- If current streak is better than best streak, update best streak.
  515. -- Best streak is never erased.
  516. if ms:get_int(wins_streak) > ms:get_int(wins_bstreak) then
  517. ms:set_int(wins_bstreak, ms:get_int(wins_streak))
  518. end
  519. -- Grant player the big_hotbar priv.
  520. -- Rewarded by the 'surface' gamemode only.
  521. if currentgame == "surface" then
  522. if not minetest.check_player_privs(player, {big_hotbar=true}) then
  523. local privs = minetest.get_player_privs(pname)
  524. privs.big_hotbar = true
  525. minetest.set_player_privs(pname, privs)
  526. minetest.notify_authentication_modified(pname)
  527. player:hud_set_hotbar_image("gui_hotbar2.png")
  528. player:hud_set_hotbar_itemcount(16)
  529. end
  530. end
  531. -- Let everyone know the player's win stats.
  532. survivalist.shout_player_stats(pname)
  533. -- Add player's name to the rankings.
  534. survivalist.add_player_to_rankings(pname)
  535. end
  536. function survivalist.player_beat_cave_challenge(pname)
  537. local ms = survivalist.modstorage
  538. local va = ms:get_int(pname .. ":wins_cave") or 0
  539. if va > 0 then
  540. return true
  541. end
  542. return false
  543. end
  544. function survivalist.player_beat_nether_challenge(pname)
  545. local ms = survivalist.modstorage
  546. local va = ms:get_int(pname .. ":wins_nether") or 0
  547. if va > 0 then
  548. return true
  549. end
  550. return false
  551. end
  552. -- If a player joins the server and a Survivalist Challenge is running, inform them.
  553. function survivalist.on_joinplayer(player)
  554. local pname = player:get_player_name()
  555. survivalist.players[pname] = {}
  556. minetest.after(0.5, function()
  557. local player = minetest.get_player_by_name(pname)
  558. if not player then
  559. return
  560. end
  561. local gamemode = survivalist.modstorage:get_string(pname .. ":mode")
  562. if gamemode == "surface" or gamemode == "cave" or gamemode == "nether" then
  563. local dname = rename.gpn(pname)
  564. if not gdac.player_is_admin(pname) then
  565. minetest.chat_send_all("# Server: Player <" .. dname .. "> is engaged in a Survival Challenge.")
  566. end
  567. minetest.chat_send_player(pname, "# Server: You are in a Survival Challenge. Avoid death by sleeping!")
  568. minetest.chat_send_player(pname, "# Server: Find the Surface Colony or the Nether City and claim victory in the Central Square to beat the Challenge.")
  569. end
  570. end)
  571. end
  572. -- Dying cancels the challenge.
  573. function survivalist.on_dieplayer(player)
  574. local pname = player:get_player_name()
  575. -- If player has a bed respawn set, then they don't fail the challenge.
  576. if beds.has_respawn_bed(pname) then
  577. if survivalist.game_in_progress(pname) then
  578. minetest.after(1, function()
  579. minetest.chat_send_player(pname, "# Server: You should respawn in your bed. Warning: if you die without a bed, you will fail the Challenge.")
  580. end)
  581. end
  582. return
  583. end
  584. local gamemode = survivalist.modstorage:get_string(pname .. ":mode")
  585. if gamemode == "surface" or gamemode == "cave" or gamemode == "nether" then
  586. -- Delay the chat messages slightly.
  587. minetest.after(1, function()
  588. if not gdac.player_is_admin(pname) then
  589. local dname = rename.gpn(pname)
  590. minetest.chat_send_all("# Server: Player <" .. dname .. ">'s survival skill was tested and found wanting!")
  591. end
  592. survivalist.shout_player_stats(pname)
  593. minetest.chat_send_player(pname, "# Server: You failed the Survivalist Challenge. No goodies for you!")
  594. end)
  595. -- No game in progress. Win streak is reset to 0.
  596. survivalist.modstorage:set_string(pname .. ":mode", nil)
  597. survivalist.modstorage:set_string(pname .. ":pos", nil)
  598. survivalist.modstorage:set_string(pname .. ":home", nil)
  599. survivalist.modstorage:set_string(pname .. ":xp", nil)
  600. survivalist.modstorage:set_int(pname .. ":wins_streak", 0)
  601. -- Count loss.
  602. local ms = survivalist.modstorage
  603. local ff = pname .. ":wins_fail"
  604. ms:set_int(ff, ms:get_int(ff) + 1)
  605. -- Add player's name to the rankings (deaths count too).
  606. survivalist.add_player_to_rankings(pname)
  607. end
  608. end
  609. -- Abort a running game without loss to player score.
  610. function survivalist.abort_game(pname)
  611. local gamemode = survivalist.modstorage:get_string(pname .. ":mode")
  612. if gamemode == "surface" or gamemode == "cave" or gamemode == "nether" then
  613. if not survivalist.check_inventories_empty(pname) then
  614. minetest.chat_send_player(pname, "# Server: All your inventories (including the Starfissure Box and armor) must be empty before you may cancel a challenge (the Proof of Citizenship does not count).")
  615. easyvend.sound_error(pname)
  616. return
  617. end
  618. minetest.chat_send_player(pname, "# Server: Challenge termination confirmed.")
  619. local target = rc.static_spawn("abyss")
  620. target = minetest.string_to_pos(survivalist.modstorage:get_string(pname .. ":home")) or target
  621. -- Pre-teleport callback function. We may need to abort to prevent cheating.
  622. local pcb = function()
  623. if not survivalist.check_inventories_empty(pname) then
  624. minetest.chat_send_player(pname, "# Server: All your inventories (including the Starfissure Box and armor) must be empty before you may cancel a challenge (the Proof of Citizenship does not count).")
  625. easyvend.sound_error(pname)
  626. -- Returning success means to abort the teleport.
  627. -- Only applicable to pre-teleport callbacks.
  628. return true
  629. end
  630. -- Abort if player is trying to cheat by sitting in a cart. >:)
  631. if default.player_attached[pname] then
  632. minetest.chat_send_player(pname, "# Server: Transport error. Player attached!")
  633. return true
  634. end
  635. end
  636. -- Don't clear the challenge gamestate unless teleport successful.
  637. local bcb = function()
  638. -- No game in progress.
  639. -- Do not touch scores.
  640. survivalist.modstorage:set_string(pname .. ":mode", nil)
  641. survivalist.modstorage:set_string(pname .. ":pos", nil)
  642. survivalist.modstorage:set_string(pname .. ":home", nil)
  643. survivalist.modstorage:set_string(pname .. ":xp", nil)
  644. flameportal.clear_return_location(pname)
  645. beds.clear_player_spawn(pname)
  646. if not gdac.player_is_admin(pname) then
  647. local dname = rename.gpn(pname)
  648. minetest.chat_send_all("# Server: Player <" .. dname .. "> canceled a Survival Challenge and went home.")
  649. else
  650. minetest.chat_send_player(pname, "# Server: You canceled a Survival Challenge and went home.")
  651. end
  652. end
  653. -- Teleport is forced.
  654. preload_tp.execute({
  655. player_name = pname,
  656. target_position = target,
  657. emerge_radius = 32,
  658. pre_teleport_callback = pcb,
  659. post_teleport_callback = bcb,
  660. force_teleport = true,
  661. send_blocks = true,
  662. particle_effects = true,
  663. })
  664. else
  665. minetest.chat_send_player(pname, "# Server: You are not in a Survival Challenge; cannot abort.")
  666. easyvend.sound_error(pname)
  667. end
  668. end
  669. -- Compost the GUI formspec.
  670. function survivalist.compose_formspec(pname)
  671. local modestring = ""
  672. local inchallenge = false
  673. local gamemode = survivalist.modstorage:get_string(pname .. ":mode")
  674. if gamemode == "surface" then
  675. modestring = " (You are currently in an Iceworld Challenge)"
  676. inchallenge = true
  677. elseif gamemode == "cave" then
  678. modestring = " (You are currently in an Underearth Challenge)"
  679. inchallenge = true
  680. elseif gamemode == "nether" then
  681. modestring = " (You are currently in a Netherealm Challenge)"
  682. inchallenge = true
  683. end
  684. local type_surface = "false"
  685. local type_cave = "false"
  686. local type_nether = "false"
  687. -- Choose which checkbox will be shown as selected.
  688. if survivalist.players[pname] and survivalist.players[pname].choice then
  689. local choice = survivalist.players[pname].choice
  690. if choice == "surface" then
  691. type_surface = "true"
  692. elseif choice == "cave" then
  693. type_cave = "true"
  694. elseif choice == "nether" then
  695. type_nether = "true"
  696. end
  697. end
  698. local formspec = ""
  699. formspec = formspec .. "size[8,7]" ..
  700. default.gui_bg ..
  701. default.gui_bg_img ..
  702. default.gui_slots ..
  703. "label[0,0;Survivalist Challenge" .. modestring .. "]" ..
  704. "textarea[0.3,0.5;8,4;rules;;" .. minetest.formspec_escape(survivalist.gamerules) .. "]"
  705. -- Show challenge choices only if no challenge is in progress.
  706. if not inchallenge and survivalist.have_xp(pname, "minimum") then
  707. formspec = formspec .. "label[0,4;Choose Your Challenge!]"
  708. if survivalist.have_xp(pname, "surface") then
  709. formspec = formspec .. "checkbox[0,4.3;type_surface;Surface Survival (Copper Mark);" .. type_surface .. "]"
  710. end
  711. if survivalist.have_xp(pname, "cave") then
  712. formspec = formspec .. "checkbox[0,4.8;type_cave;Cave Survival (Silver Mark);" .. type_cave .. "]"
  713. end
  714. if survivalist.have_xp(pname, "nether") then
  715. formspec = formspec .. "checkbox[0,5.3;type_nether;Nether Survival (Gold Mark);" .. type_nether .. "]"
  716. end
  717. end
  718. -- Choose between start/abort buttons.
  719. if inchallenge then
  720. formspec = formspec .. "button[0,6.2;2,1;abort;Go Home]"
  721. else
  722. if survivalist.have_xp(pname, "minimum") then
  723. formspec = formspec .. "button[0,6.2;3,1;start;Begin Challenge]"
  724. end
  725. end
  726. -- Show `Claim Victory` only if a challenge is in progress.
  727. if inchallenge then
  728. formspec = formspec .. "button[2,6.2;2,1;victory;Claim Victory]"
  729. end
  730. formspec = formspec .. "button[4,6.2;2,1;show_rankings;Rankings]" ..
  731. "button[6,6.2;2,1;close;Close]"
  732. return formspec
  733. end
  734. function survivalist.compose_rankings_formspec(pname)
  735. local players = survivalist.get_ranking_entries()
  736. local data = {}
  737. local ms = survivalist.modstorage
  738. for k, v in pairs(players) do
  739. data[#data+1] = {
  740. name = k,
  741. wins = ms:get_int(k .. ":wins_total"),
  742. deaths = ms:get_int(k .. ":wins_fail"),
  743. streak = ms:get_int(k .. ":wins_streak"),
  744. bstreak = ms:get_int(k .. ":wins_bstreak"),
  745. surface = ms:get_int(k .. ":wins_surface"),
  746. cave = ms:get_int(k .. ":wins_cave"),
  747. nether = ms:get_int(k .. ":wins_nether"),
  748. tokens = ms:get_int(k .. ":wins_tokens"),
  749. }
  750. end
  751. local form = ""
  752. form = form .. "size[13,7]" ..
  753. default.gui_bg ..
  754. default.gui_bg_img ..
  755. default.gui_slots ..
  756. "label[0,0;Survival Challenge Rankings]" ..
  757. "button[11,6.2;2,1;close_rankings;Close]"
  758. form = form .. "tablecolumns[color;text;text;text;text;text;text;text;text;text;text;text;text;text;text;text;text;text]"
  759. form = form .. "table[0,0.5;12.8,5;rankings_table;"
  760. form = form .. "#00ffff,Username,|,Victories,|,Deaths,|,C-Streak,|,B-Streak,|,Iceworld,|,Underearth,|,Netherealm,|,Marks,"
  761. for k, v in ipairs(data) do
  762. form = form .. ",<" .. rename.gpn(v.name) .. ">,|," .. v.wins .. ",|," .. v.deaths .. ",|," ..
  763. v.streak .. ",|," .. v.bstreak .. ",|," .. v.surface .. ",|," .. v.cave ..
  764. ",|," .. v.nether .. ",|," .. v.tokens .. ","
  765. end
  766. form = string.gsub(form, ",$", "")
  767. form = form .. ";1]"
  768. return form
  769. end
  770. function survivalist.show_rankings_formspec(pname)
  771. local formspec = survivalist.compose_rankings_formspec(pname)
  772. minetest.show_formspec(pname, "survivalist:rankings", formspec)
  773. end
  774. -- API function (called from passport mod, for instance).
  775. function survivalist.show_formspec(pname)
  776. local formspec = survivalist.compose_formspec(pname)
  777. minetest.show_formspec(pname, "survivalist:survivalist", formspec)
  778. end
  779. -- GUI form input handler.
  780. function survivalist.on_receive_fields(player, formname, fields)
  781. local pname = player:get_player_name()
  782. if formname ~= "survivalist:survivalist" and formname ~= "survivalist:rankings" then
  783. return
  784. end
  785. if fields.quit then
  786. return true
  787. end
  788. if fields.show_rankings then
  789. survivalist.show_rankings_formspec(pname)
  790. return true
  791. end
  792. if fields.rankings_table then
  793. survivalist.show_rankings_formspec(pname)
  794. return true
  795. end
  796. if fields.close_rankings or formname == "survivalist:rankings" then
  797. survivalist.show_formspec(pname)
  798. return true
  799. end
  800. -- Start game.
  801. if fields.start and survivalist.have_xp(pname, "minimum") then
  802. minetest.close_formspec(pname, "survivalist:survivalist")
  803. survivalist.start_game(pname, survivalist.players[pname].choice)
  804. return true
  805. end
  806. -- Claim victory.
  807. if fields.victory then
  808. minetest.close_formspec(pname, "survivalist:survivalist")
  809. survivalist.attempt_claim(pname)
  810. return true
  811. end
  812. -- Abort challenge.
  813. if fields.abort then
  814. minetest.close_formspec(pname, "survivalist:survivalist")
  815. survivalist.abort_game(pname)
  816. return true
  817. end
  818. -- Handle gamemode checkboxes.
  819. for j, k in ipairs({"surface", "cave", "nether"}) do
  820. if fields["type_" .. k] then
  821. if fields["type_" .. k] == "true" then
  822. survivalist.players[pname].choice = k
  823. else
  824. survivalist.players[pname].choice = nil
  825. end
  826. survivalist.show_formspec(pname)
  827. return true
  828. end
  829. end
  830. if fields.close then
  831. --minetest.close_formspec(pname, "survivalist:survivalist")
  832. passport.show_formspec(pname)
  833. return true
  834. end
  835. survivalist.show_formspec(pname)
  836. return true
  837. end
  838. -- Here belongs code which must run only once.
  839. if not survivalist.run_once then
  840. -- Obtain modstorage.
  841. survivalist.modstorage = minetest.get_mod_storage()
  842. minetest.register_privilege("big_hotbar", {
  843. description = "Player has double-wide hotbar for item wielding.",
  844. give_to_singleplayer = false,
  845. })
  846. -- Define the victory tokens.
  847. local nodebox = {
  848. type = "fixed",
  849. fixed = {
  850. {-0.5, -0.5, -0.5, 0.5, -15/32, 0.5},
  851. },
  852. }
  853. for j, k in ipairs({
  854. {name="copper", upper="Copper"},
  855. {name="silver", upper="Silver"},
  856. {name="gold", upper="Gold"},
  857. }) do
  858. minetest.register_node("survivalist:" .. k.name .. "_skill_token", {
  859. description = k.upper .. " Skill Mark",
  860. tiles = {"survivalist_" .. k.name .. "_token.png"},
  861. inventory_image = "survivalist_" .. k.name .. "_token.png",
  862. wield_image = "survivalist_" .. k.name .. "_token.png",
  863. -- If stack_max is clamped, then players can lose marks they win due to
  864. -- stack clamping, when marks are placed in inventory or dropped on the ground.
  865. --stack_max = 1,
  866. paramtype = "light",
  867. paramtype2 = "facedir",
  868. sunlight_propagates = true,
  869. walkable = false,
  870. groups = utility.dig_groups("item"),
  871. sounds = default.node_sound_metal_defaults(),
  872. drawtype = "nodebox",
  873. node_box = nodebox,
  874. selection_box = nodebox,
  875. on_place = minetest.rotate_node,
  876. })
  877. end
  878. -- Compatibility alias.
  879. minetest.register_alias("survivalist:skill_token", "survivalist:silver_skill_token")
  880. -- GUI input handler.
  881. minetest.register_on_player_receive_fields(function(...)
  882. return survivalist.on_receive_fields(...)
  883. end)
  884. -- Update state for players that join.
  885. minetest.register_on_joinplayer(function(...)
  886. return survivalist.on_joinplayer(...)
  887. end)
  888. -- Dead players can't win anything.
  889. minetest.register_on_dieplayer(function(...)
  890. return survivalist.on_dieplayer(...)
  891. end)
  892. -- File is reloadable.
  893. local c = "survivalist:core"
  894. local f = survivalist.modpath .. "/init.lua"
  895. reload.register_file(c, f, false)
  896. -- Done.
  897. survivalist.run_once = true
  898. end