Skip to content

Commit 8d0fb34

Browse files
authoredSep 9, 2020
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'.
1 parent 268f869 commit 8d0fb34

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed
 

‎game_api.txt

+27-25
Original file line numberDiff line numberDiff line change
@@ -426,63 +426,65 @@ Give Initial Stuff API
426426
^ Adds items to the list of items to be given
427427

428428

429-
Players API
430-
-----------
429+
Player API
430+
----------
431431

432432
The player API can register player models and update the player's appearance.
433433

434434
* `player_api.register_model(name, def)`
435435
* Register a new model to be used by players
436-
* name: model filename such as "character.x", "foo.b3d", etc.
437-
* def: See [#Model definition]
438-
* saved to player_api.registered_models
436+
* `name`: model filename such as "character.x", "foo.b3d", etc.
437+
* `def`: see [#Model definition]
438+
* Saved to player_api.registered_models
439439

440-
* `player_api.registered_player_models[name]`
441-
* Get a model's definition
442-
* see [#Model definition]
440+
* `player_api.registered_models[name]`
441+
* Get a model's definition
442+
* `name`: model filename
443+
* See [#Model definition]
443444

444445
* `player_api.set_model(player, model_name)`
445446
* Change a player's model
446447
* `player`: PlayerRef
447448
* `model_name`: model registered with player_api.register_model()
448449

449-
* `player_api.set_animation(player, anim_name [, speed])`
450+
* `player_api.set_animation(player, anim_name, speed)`
450451
* Applies an animation to a player
451-
* anim_name: name of the animation.
452-
* speed: frames per second. If nil, default from the model is used
452+
* `player`: PlayerRef
453+
* `anim_name`: name of the animation
454+
* `speed`: frames per second. If nil, the default from the model def is used
453455

454456
* `player_api.set_textures(player, textures)`
455457
* Sets player textures
456458
* `player`: PlayerRef
457-
* `textures`: array of textures, If `textures` is nil the default
458-
textures from the model def are used
459+
* `textures`: array of textures. If nil, the default from the model def is used
459460

460461
* `player_api.get_animation(player)`
461-
* Returns a table containing fields `model`, `textures` and `animation`.
462-
* Any of the fields of the returned table may be nil.
463-
* player: PlayerRef
462+
* Returns a table containing fields `model`, `textures` and `animation`
463+
* Any of the fields of the returned table may be nil
464+
* `player`: PlayerRef
464465

465466
* `player_api.player_attached`
466-
* A table that maps a player name to a boolean.
467-
* If the value for a given player is set to true, the default player
468-
animations (walking, digging, ...) will no longer be updated.
469-
Knockback from damage is also prevented for that player.
467+
* A table that maps a player name to a boolean
468+
* If the value for a given player is set to true, the default player animations
469+
(walking, digging, ...) will no longer be updated, and knockback from damage is
470+
prevented for that player
471+
* Example of usage: A mod sets a player's value to true when attached to a vehicle
470472

471473
### Model Definition
472474

473475
{
474-
animation_speed = 30, -- Default animation speed, in FPS.
475-
textures = {"character.png", }, -- Default array of textures.
476-
visual_size = {x = 1, y = 1}, -- Used to scale the model.
476+
animation_speed = 30, -- Default animation speed, in FPS
477+
textures = {"character.png", }, -- Default array of textures
478+
visual_size = {x = 1, y = 1}, -- Used to scale the model
477479
animations = {
478480
-- <anim_name> = {x = <start_frame>, y = <end_frame>},
479481
foo = {x = 0, y = 19},
480482
bar = {x = 20, y = 39},
481483
-- ...
482484
},
483485
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}, -- In nodes from feet position
484-
stepheight = 0.6, -- In nodes
485-
eye_height = 1.47, -- In nodes above feet position
486+
stepheight = 0.6, -- In nodes
487+
eye_height = 1.47, -- In nodes above feet position
486488
}
487489

488490

‎mods/player_api/api.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function player_api.set_textures(player, textures)
6868
local model = models[player_model[name]]
6969
local model_textures = model and model.textures or nil
7070
player_textures[name] = textures or model_textures
71-
player:set_properties({textures = textures or model_textures,})
71+
player:set_properties({textures = textures or model_textures})
7272
end
7373

7474
function player_api.set_animation(player, anim_name, speed)
@@ -90,6 +90,8 @@ minetest.register_on_leaveplayer(function(player)
9090
player_model[name] = nil
9191
player_anim[name] = nil
9292
player_textures[name] = nil
93+
player_sneak[name] = nil
94+
player_api.player_attached[name] = nil
9395
end)
9496

9597
-- Localize for better performance.

‎mods/player_api/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dofile(minetest.get_modpath("player_api") .. "/api.lua")
55
-- Default player appearance
66
player_api.register_model("character.b3d", {
77
animation_speed = 30,
8-
textures = {"character.png", },
8+
textures = {"character.png"},
99
animations = {
1010
-- Standard animations.
1111
stand = {x = 0, y = 79},

0 commit comments

Comments
 (0)
Please sign in to comment.