-
Notifications
You must be signed in to change notification settings - Fork 3
/
wood.lua
145 lines (138 loc) · 4.75 KB
/
wood.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
minetest.register_tool("chakram:chakram_wood", {
description = "Wooden Chakram",
range = 1,
inventory_image = "chakram_chakram_w.png",
on_use=function(itemstack, user, pointed_thing)
if chakram_max()==false or type(user)=="table" then
minetest.chat_send_player(user:get_player_name(), "Too many chakrams: (max " .. chakram_max_number .. ")")
return itemstack
end
local pos=user:get_pos()
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 5)) do
if ob:get_luaentity() and ob:get_luaentity().name=="chakram:chakramr_w" then
return itemstack
end
end
chakramshot_user=user
chakramshot_user_name=user:get_player_name()
local dir = user:get_look_dir()
local veloc=15
pos.y=pos.y+1.5
local m=minetest.add_entity(pos, "chakram:chakr_w")
chakram_max(m)
m:set_velocity({x=dir.x*veloc, y=dir.y*veloc, z=dir.z*veloc})
m:set_yaw(user:get_look_horizontal()+math.pi)
itemstack:take_item()
minetest.sound_play("chakram_throw", {pos=pos, gain = 1.0, max_hear_distance = 5,})
return itemstack
end,
})
minetest.register_entity("chakram:chakr_w",{
hp_max = 999,
physical = false,
weight = 0,
visual="cube",
visual_size = {x=1, y=0.04},
textures = {"chakram_chakram_w.png","chakram_chakram_w.png","chakram_light.png","chakram_light.png","chakram_light.png","chakram_light.png"},
colors = {},
spritediv = {x=1, y=1},
initial_sprite_basepos = {x=1, y=1},
is_visible = true,
makes_footstep_sound = false,
automatic_rotate = math.pi * 4,
timer = 0,
timer2 = 0,
timer3 = 0,
stuck = 0,
user={},
user_name="",
opos={x=0,z=0,y=0},
chakram_w=1,
on_punch=function(self, puncher, time_from_last_punch, tool_capabilities, dir)
if puncher:get_luaentity() or (puncher:get_player_name()~=self.user_name) then
minetest.add_item(self.object:get_pos(), "chakram:chakram_wood")
self.object:remove()
end
end,
on_activate=function(self, staticdata)
if chakramshot_user_name=="" then
minetest.add_item(self.object:get_pos(), "chakram:chakram_wood")
self.object:remove()
return false
end
self.user=chakramshot_user
self.user_name=chakramshot_user_name
chakramshot_user_name=""
chakramshot_user=""
end,
on_step = function(self, dtime)
self.timer=self.timer+dtime
if self.timer<0.05 then return self end
self.timer3=self.timer3+self.timer
if self.user==nil then
self.timer3=10
self.stuck=1
end
if self.timer3>=2 then
if self.stuck==1 then
minetest.add_item(self.object:get_pos(), "chakram:chakram_wood")
self.object:remove()
return
else
self.timer3=-2
self.stuck=1
end
end
self.timer=0
self.timer2=self.timer2+dtime
self.object:set_hp(999)
local pos=self.object:get_pos()
local name=minetest.get_node(pos).name
if name~="air" and (minetest.get_item_group(name, "snappy")>0 or minetest.get_item_group(name, "dig_immediate")>0) and minetest.is_protected(pos,self.user:get_player_name())==false then
local meta=minetest.get_meta(pos)
if meta and meta:get_string("infotext")~="" then return self end
minetest.add_item(pos, chakram_drops(name))
minetest.set_node(pos, {name="air"})
elseif chakram_def(pos,"walkable") then
minetest.add_item(self.opos, "chakram:chakram_wood")
self.object:remove()
return false
end
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 2)) do
if (not ob:get_attach()) and (ob:get_luaentity() and (not ob:get_luaentity().chakram_w) and (not ob:get_luaentity().itemstring)) or ((not ob:get_luaentity()) and ob:get_player_name()~=self.user_name and pvp) then
ob:punch(self.user,2,{full_punch_interval=1,damage_groups={fleshy=4}})
minetest.sound_play("chakram_hard_punch", {pos=ob:get_pos(), gain = 1.0, max_hear_distance = 5,})
end
end
if self.stuck==0 then
else
if self.user==nil or self.user:get_pos()==nil then
self.timer3=10
self.stuck=1
return
end
local ta=self.user:get_pos()
ta.y=ta.y+1
local vec = {x = pos.x - ta.x, y = pos.y - ta.y, z = pos.z - ta.z}
local amount = (vec.x ^ 2 + vec.y ^ 2 + vec.z ^ 2) ^ 0.5
local v = -15
vec.x = vec.x * v / amount
vec.y = vec.y * v / amount
vec.z = vec.z * v / amount
self.object:set_velocity(vec)
for i, ob in pairs(minetest.get_objects_inside_radius(pos, 2)) do
if (not ob:get_luaentity()) and ob:get_player_name()==self.user_name then
if self.object==nil or self.user==nil or self.user:get_pos()==nil then
self.timer3=10
self.stuck=1
return
end
if self.object:get_attach() then self.object:set_detach() return false end
self.user:get_inventory():add_item("main", ItemStack("chakram:chakram_wood"))
self.object:remove()
end
end
end
self.opos=pos
end,
})