Player sit command

lkjoel
Member
 
Posts: 779
Joined: Wed Feb 29, 2012 19:27
Location: Gallifrey

Player sit command

by lkjoel » Thu Dec 06, 2012 23:15

When I saw the sitting animation, but no way to sit, I decided to sit down and hack the heck out of player.lua. To sit/unsit, simply type "/sit".

Notice that you can still move while sitting, so it looks kind of weird.

Here is the modified player.lua:
Code: Select all
-- Minetest 0.4 mod: player
-- See README.txt for licensing and other information.

--
-- Start of configuration area:
--

-- Player animation speed
animation_speed = 30

-- Player animation blending
-- Note: This is currently broken due to a bug in Irrlicht, leave at 0
animation_blend = 0

-- Default player appearance
default_model = "character.x"
default_textures = {"character.png", }

-- Frame ranges for each player model
function player_get_animations(model)
    if model == "character.x" then
        return {
        stand_START = 0,
        stand_END = 79,
        sit_START = 81,
        sit_END = 160,
        lay_START = 162,
        lay_END = 166,
        walk_START = 168,
        walk_END = 187,
        mine_START = 189,
        mine_END = 198,
        walk_mine_START = 200,
        walk_mine_END = 219
        }
    end
end

--
-- End of configuration area.
--

-- Player stats and animations
local player_model = {}
local player_anim = {}
local player_sneak = {}
local player_sit = {}
local ANIM_STAND = 1
local ANIM_SIT = 2
local ANIM_LAY = 3
local ANIM_WALK  = 4
local ANIM_WALK_MINE = 5
local ANIM_MINE = 6

-- Called when a player's appearance needs to be updated
function player_update_visuals(pl)
    local name = pl:get_player_name()

    player_model[name] = default_model
    player_anim[name] = 0 -- Animation will be set further below immediately
    player_sneak[name] = false
    player_sit[name] = false
    prop = {
        mesh = default_model,
        textures = default_textures,
        visual = "mesh",
        visual_size = {x=1, y=1},
    }
    pl:set_properties(prop)
end

-- Update appearance when the player joins
minetest.register_on_joinplayer(player_update_visuals)

-- Check each player and apply animations
function player_step(dtime)
    for _, pl in pairs(minetest.get_connected_players()) do
        local name = pl:get_player_name()
        local anim = player_get_animations(player_model[name])
        local controls = pl:get_player_control()
        local walking = false
        local animation_speed_mod = animation_speed

        -- Determine if the player is walking
        if controls.up or controls.down or controls.left or controls.right then
            walking = true
        end

        -- Determine if the player is sneaking, and reduce animation speed if so
        if controls.sneak and pl:get_hp() ~= 0 and (walking or controls.LMB) then
            animation_speed_mod = animation_speed_mod / 2
            -- Refresh player animation below if sneak state changed
            if not player_sneak[name] then
                player_anim[name] = 0
                player_sneak[name] = true
            end
        else
            -- Refresh player animation below if sneak state changed
            if player_sneak[name] then
                player_anim[name] = 0
                player_sneak[name] = false
            end
        end

        -- Apply animations based on what the player is doing
        if pl:get_hp() == 0 then
            if player_anim[name] ~= ANIM_LAY then
                pl:set_animation({x=anim.lay_START, y=anim.lay_END}, animation_speed_mod, animation_blend)
                player_anim[name] = ANIM_LAY
            end
        elseif player_sit[name] then
            if player_anim[name] ~= ANIM_SIT then
                pl:set_animation({x=anim.sit_START, y=anim.sit_END}, animation_speed_mod, animation_blend)
                player_anim[name] = ANIM_SIT
            end
        elseif walking and controls.LMB then
            if player_anim[name] ~= ANIM_WALK_MINE then
                pl:set_animation({x=anim.walk_mine_START, y=anim.walk_mine_END}, animation_speed_mod, animation_blend)
                player_anim[name] = ANIM_WALK_MINE
            end
        elseif walking then
            if player_anim[name] ~= ANIM_WALK then
                pl:set_animation({x=anim.walk_START, y=anim.walk_END}, animation_speed_mod, animation_blend)
                player_anim[name] = ANIM_WALK
            end
        elseif controls.LMB then
            if player_anim[name] ~= ANIM_MINE then
                pl:set_animation({x=anim.mine_START, y=anim.mine_END}, animation_speed_mod, animation_blend)
                player_anim[name] = ANIM_MINE
            end
        elseif player_anim[name] ~= ANIM_STAND then
            pl:set_animation({x=anim.stand_START, y=anim.stand_END}, animation_speed_mod, animation_blend)
            player_anim[name] = ANIM_STAND
        end
    end
end
minetest.register_globalstep(player_step)

minetest.register_chatcommand("sit", {
    params = "",
    description = "Sit",
    func = function(name, param)
        if player_sit[name] then
            player_sit[name] = false
            minetest.chat_send_player(name, "You are not sitting anymore")
        else
            player_sit[name] = true
            minetest.chat_send_player(name, "You are now sitting")
        end
    end,
})

-- END

Copy that to MINETEST_GAME_DIR/minetest_game/mods/default/player.lua.

Let me know what you think of it :D
Last edited by lkjoel on Thu Dec 06, 2012 23:40, edited 1 time in total.
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 

mikey2020
Member
 
Posts: 30
Joined: Sun Jul 15, 2012 03:39

by mikey2020 » Fri Dec 07, 2012 00:06

how do i install this?
 

lkjoel
Member
 
Posts: 779
Joined: Wed Feb 29, 2012 19:27
Location: Gallifrey

by lkjoel » Fri Dec 07, 2012 00:09

mikey2020 wrote:how do i install this?

Copy the player.lua code in the post and paste it to default/player.lua (the "default" directory is located in your minetest_game "mods" dir).
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Fri Dec 07, 2012 11:27

You could attach the player to an invisble entity while sitting so one cant move.
 

User avatar
jordan4ibanez
Member
 
Posts: 1895
Joined: Tue Sep 27, 2011 18:44
Location: Rhode Island, USA
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

by jordan4ibanez » Fri Dec 07, 2012 12:43

You should attach a player to a toilet from 3d forniture
I've been gone for a long time
 

User avatar
rubenwardy
Moderator
 
Posts: 5863
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

by rubenwardy » Fri Dec 07, 2012 13:18

Yeah, so if the player is near a chair or toilet, it moves to the correct position and attaches

If not, it should sit on the ground
 

lkjoel
Member
 
Posts: 779
Joined: Wed Feb 29, 2012 19:27
Location: Gallifrey

by lkjoel » Fri Dec 07, 2012 22:05

yeah, that was only a proof of concept... not sure if I actually want to work on it immensely, as it's a hack on player.lua (not it's own mod).
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 


Return to WIP Mods



Who is online

Users browsing this forum: MSN [Bot] and 12 guests