mirror of
https://github.com/minetest/minetest_game.git
synced 2024-11-08 08:43:51 +01:00
Player_api: Various maintenance (#2737)
Clear 'player_sneak' and 'player_api.player_attached' table values when player leaves. Remove unnecessary commas and whitespace. Fix table name in 'game_api.txt'. Clean up documentation in 'game_api.txt'.
This commit is contained in:
parent
268f869e67
commit
8d0fb34fb0
52
game_api.txt
52
game_api.txt
@ -426,54 +426,56 @@ Give Initial Stuff API
|
|||||||
^ Adds items to the list of items to be given
|
^ Adds items to the list of items to be given
|
||||||
|
|
||||||
|
|
||||||
Players API
|
Player API
|
||||||
-----------
|
----------
|
||||||
|
|
||||||
The player API can register player models and update the player's appearance.
|
The player API can register player models and update the player's appearance.
|
||||||
|
|
||||||
* `player_api.register_model(name, def)`
|
* `player_api.register_model(name, def)`
|
||||||
* Register a new model to be used by players
|
* Register a new model to be used by players
|
||||||
* name: model filename such as "character.x", "foo.b3d", etc.
|
* `name`: model filename such as "character.x", "foo.b3d", etc.
|
||||||
* def: See [#Model definition]
|
* `def`: see [#Model definition]
|
||||||
* saved to player_api.registered_models
|
* Saved to player_api.registered_models
|
||||||
|
|
||||||
* `player_api.registered_player_models[name]`
|
* `player_api.registered_models[name]`
|
||||||
* Get a model's definition
|
* Get a model's definition
|
||||||
* see [#Model definition]
|
* `name`: model filename
|
||||||
|
* See [#Model definition]
|
||||||
|
|
||||||
* `player_api.set_model(player, model_name)`
|
* `player_api.set_model(player, model_name)`
|
||||||
* Change a player's model
|
* Change a player's model
|
||||||
* `player`: PlayerRef
|
* `player`: PlayerRef
|
||||||
* `model_name`: model registered with player_api.register_model()
|
* `model_name`: model registered with player_api.register_model()
|
||||||
|
|
||||||
* `player_api.set_animation(player, anim_name [, speed])`
|
* `player_api.set_animation(player, anim_name, speed)`
|
||||||
* Applies an animation to a player
|
* Applies an animation to a player
|
||||||
* anim_name: name of the animation.
|
* `player`: PlayerRef
|
||||||
* speed: frames per second. If nil, default from the model is used
|
* `anim_name`: name of the animation
|
||||||
|
* `speed`: frames per second. If nil, the default from the model def is used
|
||||||
|
|
||||||
* `player_api.set_textures(player, textures)`
|
* `player_api.set_textures(player, textures)`
|
||||||
* Sets player textures
|
* Sets player textures
|
||||||
* `player`: PlayerRef
|
* `player`: PlayerRef
|
||||||
* `textures`: array of textures, If `textures` is nil the default
|
* `textures`: array of textures. If nil, the default from the model def is used
|
||||||
textures from the model def are used
|
|
||||||
|
|
||||||
* `player_api.get_animation(player)`
|
* `player_api.get_animation(player)`
|
||||||
* Returns a table containing fields `model`, `textures` and `animation`.
|
* Returns a table containing fields `model`, `textures` and `animation`
|
||||||
* Any of the fields of the returned table may be nil.
|
* Any of the fields of the returned table may be nil
|
||||||
* player: PlayerRef
|
* `player`: PlayerRef
|
||||||
|
|
||||||
* `player_api.player_attached`
|
* `player_api.player_attached`
|
||||||
* A table that maps a player name to a boolean.
|
* A table that maps a player name to a boolean
|
||||||
* If the value for a given player is set to true, the default player
|
* If the value for a given player is set to true, the default player animations
|
||||||
animations (walking, digging, ...) will no longer be updated.
|
(walking, digging, ...) will no longer be updated, and knockback from damage is
|
||||||
Knockback from damage is also prevented for that player.
|
prevented for that player
|
||||||
|
* Example of usage: A mod sets a player's value to true when attached to a vehicle
|
||||||
|
|
||||||
### Model Definition
|
### Model Definition
|
||||||
|
|
||||||
{
|
{
|
||||||
animation_speed = 30, -- Default animation speed, in FPS.
|
animation_speed = 30, -- Default animation speed, in FPS
|
||||||
textures = {"character.png", }, -- Default array of textures.
|
textures = {"character.png", }, -- Default array of textures
|
||||||
visual_size = {x = 1, y = 1}, -- Used to scale the model.
|
visual_size = {x = 1, y = 1}, -- Used to scale the model
|
||||||
animations = {
|
animations = {
|
||||||
-- <anim_name> = {x = <start_frame>, y = <end_frame>},
|
-- <anim_name> = {x = <start_frame>, y = <end_frame>},
|
||||||
foo = {x = 0, y = 19},
|
foo = {x = 0, y = 19},
|
||||||
@ -481,8 +483,8 @@ The player API can register player models and update the player's appearance.
|
|||||||
-- ...
|
-- ...
|
||||||
},
|
},
|
||||||
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}, -- In nodes from feet position
|
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}, -- In nodes from feet position
|
||||||
stepheight = 0.6, -- In nodes
|
stepheight = 0.6, -- In nodes
|
||||||
eye_height = 1.47, -- In nodes above feet position
|
eye_height = 1.47, -- In nodes above feet position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ function player_api.set_textures(player, textures)
|
|||||||
local model = models[player_model[name]]
|
local model = models[player_model[name]]
|
||||||
local model_textures = model and model.textures or nil
|
local model_textures = model and model.textures or nil
|
||||||
player_textures[name] = textures or model_textures
|
player_textures[name] = textures or model_textures
|
||||||
player:set_properties({textures = textures or model_textures,})
|
player:set_properties({textures = textures or model_textures})
|
||||||
end
|
end
|
||||||
|
|
||||||
function player_api.set_animation(player, anim_name, speed)
|
function player_api.set_animation(player, anim_name, speed)
|
||||||
@ -90,6 +90,8 @@ minetest.register_on_leaveplayer(function(player)
|
|||||||
player_model[name] = nil
|
player_model[name] = nil
|
||||||
player_anim[name] = nil
|
player_anim[name] = nil
|
||||||
player_textures[name] = nil
|
player_textures[name] = nil
|
||||||
|
player_sneak[name] = nil
|
||||||
|
player_api.player_attached[name] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Localize for better performance.
|
-- Localize for better performance.
|
||||||
|
@ -5,7 +5,7 @@ dofile(minetest.get_modpath("player_api") .. "/api.lua")
|
|||||||
-- Default player appearance
|
-- Default player appearance
|
||||||
player_api.register_model("character.b3d", {
|
player_api.register_model("character.b3d", {
|
||||||
animation_speed = 30,
|
animation_speed = 30,
|
||||||
textures = {"character.png", },
|
textures = {"character.png"},
|
||||||
animations = {
|
animations = {
|
||||||
-- Standard animations.
|
-- Standard animations.
|
||||||
stand = {x = 0, y = 79},
|
stand = {x = 0, y = 79},
|
||||||
|
Loading…
Reference in New Issue
Block a user