Advertisement
Guest User

Untitled

a guest
Apr 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1.  
  2. -- global
  3. pova = {}
  4.  
  5.  
  6. -- set player table and defaults on join
  7. minetest.register_on_joinplayer(function(player)
  8. pova[ player:get_player_name() ] = {
  9. default = {speed = 1, jump = 1, gravity = 1}}
  10. end)
  11.  
  12. -- reset player table and defaults on respawn
  13. minetest.register_on_respawnplayer(function(player)
  14. pova[ player:get_player_name() ] = {
  15. default = {speed = 1, jump = 1, gravity = 1}}
  16. end)
  17.  
  18. -- blank player table on leave
  19. minetest.register_on_leaveplayer(function(player)
  20. pova[ player:get_player_name() ] = nil
  21. end)
  22.  
  23.  
  24. -- main counter that runs every second and totals override list
  25. local timer = 0
  26. minetest.register_globalstep(function(dtime)
  27.  
  28. timer = timer + dtime
  29.  
  30. -- every 1 second
  31. if timer < 1 then
  32. return
  33. end
  34.  
  35. -- reset time for next check
  36. timer = 0
  37.  
  38. -- define locals outside loop
  39. local name
  40. local speed, jump, gravity
  41.  
  42. -- loop through players
  43. for _,player in ipairs(minetest.get_connected_players()) do
  44.  
  45. name = player:get_player_name()
  46.  
  47. if pova[name] then
  48.  
  49. -- check for new defaults
  50. speed = pova[name]["default"].speed or 1
  51. jump = pova[name]["default"].jump or 1
  52. gravity = pova[name]["default"].gravity or 1
  53.  
  54. for id, var in pairs(pova[name]) do
  55.  
  56. if var and id ~= "default" then
  57.  
  58. -- add any additional changes
  59. speed = speed + (pova[name][id].speed or 0)
  60. jump = jump + (pova[name][id].jump or 0)
  61. gravity = gravity + (pova[name][id].gravity or 0)
  62. end
  63.  
  64. end
  65.  
  66. print ("speed: " .. speed .. " / jump: " .. jump .. " / gravity: " .. gravity)
  67.  
  68. player:set_physics_override(speed, jump, gravity)
  69.  
  70. end
  71.  
  72. end
  73.  
  74. end)
  75.  
  76.  
  77. -- axe tool that adds to override table on use
  78. minetest.register_craftitem("pova:axe", {
  79. description = "Test Axe (left to apply, right to remove effects)",
  80. inventory_image = "default_tool_steelaxe.png",
  81. liquids_pointable = true,
  82.  
  83. on_use = function(itemstack, user, pointed_thing)
  84.  
  85. local name = user:get_player_name()
  86.  
  87. -- set new defaults
  88. pova[name]["default"].speed = 2
  89. pova[name]["default"].jump = 0.5
  90. pova[name]["default"].gravity = 1.0
  91.  
  92. -- define and set changes to apply
  93. pova[name]["test"] = {}
  94. pova[name]["test"].speed = 1
  95. pova[name]["test"].jump = 2
  96. pova[name]["test"].gravity = 0.5
  97. end,
  98.  
  99. on_place = function(itemstack, user, pointed_thing)
  100.  
  101. local name = user:get_player_name()
  102.  
  103. -- reset defaults
  104. pova[name]["default"].speed = 1
  105. pova[name]["default"].jump = 1
  106. pova[name]["default"].gravity = 1
  107.  
  108. -- remove changes
  109. pova[name]["test"] = nil
  110. end,
  111. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement