stujones11 / minetest-3d_armor

Visible player armor & wielded items for minetest
Other
55 stars 97 forks source link

Global physics for other mods in armor.lua #10

Closed tenplus1 closed 10 years ago

tenplus1 commented 10 years ago

a few other mods tinker with player physics but not all work together it seems, so would it be possible to add global values to the armor.lua so that other mods KNOW it's current settings and can change accordingly so they all work hand in hand (change lines 126-128) to:

                            if o_value then
                                physics_o[vv] = physics_o[vv] + o_value
                                if vv == "speed" then
                                    armor.speed = physics_o[vv]
                                elseif vv == "jump" then
                                    armor.jump = physics_o[vv]
                                elseif vv == "gravity" then
                                    armor.gravity = physics_o[vv]
                                end
                            end

also adding the following just after line 101:

    armor.speed = 1
    armor.jump = 1
    armor.gravity = 1
stujones11 commented 10 years ago

The physics overrides can differ from one player to another so I don't think the code you posted will be of much use here. It is probably best added to armor.def which is global player-name keyed table, originally added by BlockMen to display armor stats in his hud mod. For example, somewhere after line 167 add: self.def[name].physics = physics_o and you can then read it from anywhere via gravity = armor.def[name].phyisics.gravity etc. You would prabably also want to initialize armor.def with some default values to avoid nil index errors. I will test this as soon as I get the chance.

Edit: It would be kinda helpful if the api provided a method to read player physics/armor levels, the latter being documented (but not supported) since MT 0.4.4. You should maybe file an issue there too.

tenplus1 commented 10 years ago

doh! how did I not realise global value = all players... my bad... thx for the alternative though, I added these lines where you said:

self.def[name].jump = physics_o.jump
self.def[name].speed = physics_o.speed
self.def[name].gravity = physics_o.gravity

and used this in my playerplus mod:

if minetest.get_modpath("3d_armor") then
    def = armor.def[player:get_player_name()] or nil
    if def then
        pp.speed = def.speed or 1
        pp.jump = def.jump or 1
        pp.gravity = def.gravity or 1
    end
end
stujones11 commented 10 years ago

Yeah, that looks better than what I wrote, I'll get this added asap, thanks.

OT: or nil ???

tenplus1 commented 10 years ago

I put a lot of redundancies in mods incase of weird errors, which reminds me, I was getting a weird crash on occasion with a nil error for player_inv in your armor.set_player_armor function and added this line which seems to have fixed it:

if not player_inv then print ("NO INVENTORY FOUND") return end
stujones11 commented 10 years ago

I have exposed the physics overrides and added a check for nil inventories. Can you test this and confirm that is works ok with your mod, thanks.