Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- global
- pova = {}
- -- set player table and defaults on join
- minetest.register_on_joinplayer(function(player)
- pova[ player:get_player_name() ] = {
- default = {speed = 1, jump = 1, gravity = 1}}
- end)
- -- reset player table and defaults on respawn
- minetest.register_on_respawnplayer(function(player)
- pova[ player:get_player_name() ] = {
- default = {speed = 1, jump = 1, gravity = 1}}
- end)
- -- blank player table on leave
- minetest.register_on_leaveplayer(function(player)
- pova[ player:get_player_name() ] = nil
- end)
- -- main counter that runs every second and totals override list
- local timer = 0
- minetest.register_globalstep(function(dtime)
- timer = timer + dtime
- -- every 1 second
- if timer < 1 then
- return
- end
- -- reset time for next check
- timer = 0
- -- define locals outside loop
- local name
- local speed, jump, gravity
- -- loop through players
- for _,player in ipairs(minetest.get_connected_players()) do
- name = player:get_player_name()
- if pova[name] then
- -- check for new defaults
- speed = pova[name]["default"].speed or 1
- jump = pova[name]["default"].jump or 1
- gravity = pova[name]["default"].gravity or 1
- for id, var in pairs(pova[name]) do
- if var and id ~= "default" then
- -- add any additional changes
- speed = speed + (pova[name][id].speed or 0)
- jump = jump + (pova[name][id].jump or 0)
- gravity = gravity + (pova[name][id].gravity or 0)
- end
- end
- print ("speed: " .. speed .. " / jump: " .. jump .. " / gravity: " .. gravity)
- player:set_physics_override(speed, jump, gravity)
- end
- end
- end)
- -- axe tool that adds to override table on use
- minetest.register_craftitem("pova:axe", {
- description = "Test Axe (left to apply, right to remove effects)",
- inventory_image = "default_tool_steelaxe.png",
- liquids_pointable = true,
- on_use = function(itemstack, user, pointed_thing)
- local name = user:get_player_name()
- -- set new defaults
- pova[name]["default"].speed = 2
- pova[name]["default"].jump = 0.5
- pova[name]["default"].gravity = 1.0
- -- define and set changes to apply
- pova[name]["test"] = {}
- pova[name]["test"].speed = 1
- pova[name]["test"].jump = 2
- pova[name]["test"].gravity = 0.5
- end,
- on_place = function(itemstack, user, pointed_thing)
- local name = user:get_player_name()
- -- reset defaults
- pova[name]["default"].speed = 1
- pova[name]["default"].jump = 1
- pova[name]["default"].gravity = 1
- -- remove changes
- pova[name]["test"] = nil
- end,
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement