1 -- See README.txt for licensing and other information.
3 -- Player animation blending
4 -- Note: This is currently broken due to a bug in Irrlicht, leave at 0
5 local animation_blend
= 0
9 hades_player
.registered_player_models
= { }
12 local models
= hades_player
.registered_player_models
14 function hades_player
.player_register_model(name
, def
)
18 -- Default player appearance
19 hades_player
.player_register_model("character.b3d", {
21 textures
= {"character.png", },
23 -- Standard animations.
24 stand
= { x
= 0, y
= 79, },
25 lay
= { x
=162, y
=166, },
26 walk
= { x
=168, y
=187, },
27 mine
= { x
=189, y
=198, },
28 walk_mine
= { x
=200, y
=219, },
29 -- Extra animations (not currently used by the game).
30 sit
= { x
= 81, y
=160, },
34 -- Player stats and animations
35 local player_model
= {}
36 local player_textures
= {}
37 local player_anim
= {}
38 local player_sneak
= {}
39 hades_player
.player_attached
= {}
41 function hades_player
.player_get_animation(player
)
42 local name
= player
:get_player_name()
44 model
= player_model
[name
],
45 textures
= player_textures
[name
],
46 animation
= player_anim
[name
],
50 -- Called when a player's appearance needs to be updated
51 function hades_player
.player_set_model(player
, model_name
)
52 local name
= player
:get_player_name()
53 local model
= models
[model_name
]
55 if player_model
[name
] == model_name
then
58 player
:set_properties({
60 textures
= player_textures
[name
] or model
.textures
,
62 visual_size
= model
.visual_size
or {x
=1, y
=1},
64 hades_player
.player_set_animation(player
, "stand")
66 player
:set_properties({
67 textures
= { "player.png", "player_back.png", },
68 visual
= "upright_sprite",
71 player_model
[name
] = model_name
74 function hades_player
.player_set_textures(player
, textures
)
75 local name
= player
:get_player_name()
76 player_textures
[name
] = textures
77 player
:set_properties({textures
= textures
,})
80 function hades_player
.player_set_animation(player
, anim_name
, speed
)
81 local name
= player
:get_player_name()
82 if player_anim
[name
] == anim_name
then
85 local model
= player_model
[name
] and models
[player_model
[name]]
86 if not (model
and model
.animations
[anim_name
]) then
89 local anim
= model
.animations
[anim_name
]
90 player_anim
[name
] = anim_name
91 player
:set_animation(anim
, speed
or model
.animation_speed
, animation_blend
)
94 -- Update appearance when the player joins
95 minetest
.register_on_joinplayer(function(player
)
96 hades_player
.player_attached
[player
:get_player_name()] = false
97 hades_player
.player_set_model(player
, "character.b3d")
98 player
:set_local_animation({x
=0, y
=79}, {x
=168, y
=187}, {x
=189, y
=198}, {x
=200, y
=219}, 30)
101 if not minetest
.is_creative_enabled(player
:get_player_name()) then
102 player
:set_inventory_formspec(hades_gui
.gui_survival_form
)
104 player
:hud_set_hotbar_itemcount(10)
105 player
:hud_set_hotbar_image("hades_gui_hotbar.png")
106 player
:hud_set_hotbar_selected_image("hades_gui_hotbar_selected.png")
107 player
:set_formspec_prepend("listcolors[#000000;#C68D3C;#ffffff;#C68D3C;#000000]")
110 minetest
.register_on_leaveplayer(function(player
)
111 local name
= player
:get_player_name()
112 player_model
[name
] = nil
113 player_anim
[name
] = nil
114 player_textures
[name
] = nil
117 -- Localize for better performance.
118 local player_set_animation
= hades_player
.player_set_animation
119 local player_attached
= hades_player
.player_attached
121 -- Check each player and apply animations
122 minetest
.register_globalstep(function(dtime
)
123 for _
, player
in pairs(minetest
.get_connected_players()) do
124 local name
= player
:get_player_name()
125 local model_name
= player_model
[name
]
126 local model
= model_name
and models
[model_name
]
128 if model
and not player_attached
[name
] then
129 local controls
= player
:get_player_control()
130 local walking
= false
131 local animation_speed_mod
= model
.animation_speed
or 30
133 -- Determine if the player is walking
134 if controls
.up
or controls
.down
or controls
.left
or controls
.right
then
138 -- Determine if the player is sneaking, and reduce animation speed if so
139 if controls
.sneak
then
140 animation_speed_mod
= animation_speed_mod
/ 2
143 -- Apply animations based on what the player is doing
144 if player
:get_hp() == 0 then
145 player_set_animation(player
, "lay")
147 if player_sneak
[name
] ~= controls
.sneak
then
148 player_anim
[name
] = nil
149 player_sneak
[name
] = controls
.sneak
152 player_set_animation(player
, "walk_mine", animation_speed_mod
)
154 player_set_animation(player
, "walk", animation_speed_mod
)
156 elseif controls
.LMB
then
157 player_set_animation(player
, "mine")
159 player_set_animation(player
, "stand", animation_speed_mod
)
165 minetest
.register_on_dieplayer(function(player
)
166 local name
= player
:get_player_name()
167 minetest
.sound_play({name
="hades_player_death"}, {to_player
=name
}, true)
170 minetest
.register_on_respawnplayer(function(player
)
171 local name
= player
:get_player_name()
172 minetest
.sound_play({name
="hades_player_respawn"}, {to_player
=name
}, true)