]> git.lizzy.rs Git - Crafter.git/blob - mods/player/init.lua
Fix run sneaking, add sapling
[Crafter.git] / mods / player / init.lua
1 --[[
2 --map
3 running - set fov set_fov(fov, is_multiplier) set_breath(value)
4 sneaking --set eye offset
5
6 ]]--
7 minetest.register_on_joinplayer(function(player)
8       --add in info
9       player:hud_set_flags({minimap=true})
10       player:hud_add({
11             hud_elem_type = "text",
12             position = {x=0,y=0},
13             text = "Crafter Alpha 0.1",
14             number = 000000,
15             alignment = {x=1,y=1},
16             offset = {x=2, y=2},
17       })
18       player:hud_add({
19             hud_elem_type = "text",
20             position = {x=0,y=0},
21             text = "Crafter Alpha 0.1",
22             number = 0xffffff,
23             alignment = {x=1,y=1},
24             offset = {x=0, y=0},
25       })
26 end)
27
28 --hurt sound
29 minetest.register_on_player_hpchange(function(player, hp_change, reason)
30       if hp_change < 0 then
31             minetest.sound_play("hurt", {object=player, gain = 1.0, max_hear_distance = 60,pitch = math.random(80,100)/100})
32       end
33 end)
34
35 --throw all items on death
36 minetest.register_on_dieplayer(function(player, reason)
37       local pos = player:getpos()
38       print(reason)
39       local inv = player:get_inventory()
40       
41       for i = 1,inv:get_size("main") do
42             local stack = inv:get_stack("main", i)
43             local name = stack:get_name()
44             local count = stack:get_count()
45             print(name)
46             if name ~= "" then
47                   local obj = minetest.add_item(pos, name.." "..count)
48                   obj:setvelocity(vector.new(math.random(-3,3),math.random(4,8),math.random(-3,3)))
49                   inv:set_stack("main", i, ItemStack(""))
50             end
51       end
52       for i = 1,inv:get_size("craft") do
53       
54       end 
55       
56
57 end)
58
59 minetest.register_globalstep(function(dtime)
60       --collection
61       for _,player in ipairs(minetest.get_connected_players()) do
62             local run = player:get_player_control().aux1
63             local walk = player:get_player_control().up
64             local sneak = player:get_player_control().sneak
65             
66             if run and walk and not sneak then
67                   --[[ I'll impliment this in later
68                   local meta = player:get_meta()
69                   
70                   local run_time = meta:get_float("running_timer")
71                   
72                   if not run_time then
73                         run_time = 0
74                   end
75                   
76                   if run_time >= 0.1 then
77                         --take breath away
78                         local breath = player:get_breath()
79                         breath = breath - 1
80                         player:set_breath(breath)
81                         run_time = 0
82                         print(breath)
83                   end
84                   
85                   meta:set_float("running_timer", run_time + dtime)
86                   
87                   ]]--
88                   
89                   local fov = player:get_fov()
90                   if fov == 0 then
91                         fov = 1
92                   end
93                   
94                   if fov < 1.2 then
95                         player:set_fov(fov + 0.05, true)
96                   end
97                   
98                   player:set_physics_override({speed=1.5})
99             else
100                   local meta = player:get_meta()
101                   local fov = player:get_fov()
102                   if fov > 1 then
103                         player:set_fov(fov - 0.05, true)
104                   end
105                   
106                   player:set_physics_override({speed=1})
107                   --meta:set_float("running_timer", 0)
108             end
109             
110             if sneak then
111                   player:set_eye_offset({x=0,y=-1,z=0},{x=0,y=-1,z=0})
112             else
113                   player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
114             end
115       end
116 end)
117
118 minetest.register_globalstep(function(dtime)
119       --collection
120       for _,player in ipairs(minetest.get_connected_players()) do
121             if player:get_player_control().RMB then
122                   local health = player:get_wielded_item():get_definition().health
123                   if health then
124                         local meta = player:get_meta()
125                         local eating = meta:get_float("eating")
126                         
127                         if meta:get_int("eating_ps") == 0 then
128                               local ps = minetest.add_particlespawner({
129                                     amount = 100,
130                                     time = 0,
131                                     minpos = {x=0, y=-1.5, z=0.5},
132                                     maxpos = {x=0, y=1.7, z=0.5},
133                                     minvel = vector.new(-0.5,0,-0.5),
134                                     maxvel = vector.new(0.5,0,0.5),
135                                     minacc = {x=0, y=-9.81, z=1},
136                                     maxacc = {x=0, y=-9.81, z=1},
137                                     minexptime = 0.5,
138                                     maxexptime = 1.5,
139                                     minsize = 1,
140                                     maxsize = 2,
141                                     attached = player,
142                                     collisiondetection = true,
143                                     vertical = false,
144                                     texture = "treecapitator.png"
145                               })
146                               meta:set_int("eating_ps", ps)
147                         end
148                               
149                         if eating + dtime >= 2 then
150                               local stack = player:get_wielded_item()
151                               stack:take_item(1)
152                               player:set_wielded_item(stack)
153                               player:set_hp(player:get_hp() + health)
154                               eating = 0
155                               minetest.sound_play("eat", {
156                                     object = player,
157                                     gain = 1.0,  -- default
158                                     max_hear_distance = 32,  -- default, uses an euclidean metric
159                                     pitch = math.random(70,100)/100,
160                               })
161                         end
162                         meta:set_float("eating", eating + dtime)
163                   else
164                         local meta = player:get_meta()
165                         meta:set_float("eating", 0)
166                         minetest.delete_particlespawner(meta:get_int("eating_ps"))
167                         meta:set_int("eating_ps", 0)
168                         
169                   end
170             else
171                   local meta = player:get_meta()
172                   meta:set_float("eating", 0)
173                   minetest.delete_particlespawner(meta:get_int("eating_ps"))
174                   meta:set_int("eating_ps", 0)
175             end
176             
177       end
178 end)
179