44b73c6793e0d58620203c5efada09efc272cdba
[oweals/minetest_game.git] / mods / default / player.lua
1 -- Minetest 0.4 mod: player
2 -- See README.txt for licensing and other information.
3
4 -- The API documentation in here was moved into doc/lua_api.txt
5
6 -- Set mesh for all players
7 function switch_player_visual()
8         prop = {
9                 mesh = "player.x",
10                 textures = {"player.png", },
11                 colors = {{255, 255, 255, 255}, },
12                 visual = "mesh",
13                 visual_size = {x=1, y=1},
14         }
15         
16         for _, obj in pairs(minetest.get_connected_players()) do
17                 obj:set_properties(prop)
18                 obj:set_animation({x=1, y=50}, 35, 0)
19                 --obj:set_bone_position("", {x=0,y=0,z=0}, {x=0,y=0,z=0})
20         end
21
22         minetest.after(1.0, switch_player_visual)
23 end
24 minetest.after(1.0, switch_player_visual)
25
26 -- Test case for attachments: An object is spawned and attached to the player with the specified name (use your own playername there) 10 seconds after the server starts
27 test2 = {
28   collisionbox = { 0, 0, 0, 0, 0, 0 },
29   visual = "cube"
30 }
31
32 minetest.register_entity("default:test2", test2)
33
34 function attachments()
35         prop = {
36                 mesh = "player.x",
37                 textures = {"player.png", },
38                 colors = {{255, 255, 255, 255}, },
39                 visual = "mesh",
40                 visual_size = {x=1, y=1},
41         }
42
43         local pos={x=0,y=0,z=0}
44         local newobject=minetest.env:add_entity(pos, "default:test2")
45         newobject:set_properties(prop)
46         newobject:set_animation({x=1, y=50}, 35, 0)
47         print ("Spawned test object")
48
49         for _, obj in pairs(minetest.get_connected_players()) do
50                 if(obj:get_player_name() == "some_nick") then
51                         newobject:set_attach(obj, "Bone.001", {x=0,y=3,z=0}, {x=0,y=45,z=0})
52                         print ("Attached test object to "..obj:get_player_name())
53                 end
54         end
55
56         minetest.after(5.0, function() detachments(newobject) end)
57 end
58
59 minetest.after(10.0, attachments)
60
61 -- Definitions made by this mod that other mods can use too
62 default = {}
63
64 -- Load other files
65 dofile(minetest.get_modpath("default").."/mapgen.lua")
66 dofile(minetest.get_modpath("default").."/leafdecay.lua")
67
68 -- END