Code tweak and tidy

This commit is contained in:
TenPlus1 2016-02-01 13:59:00 +00:00
parent 060a8278dc
commit 09db61b997

31
api.lua
View File

@ -1,4 +1,4 @@
-- Mobs Api (29th January 2016)
-- Mobs Api (1st February 2016)
mobs = {}
mobs.mod = "redo"
@ -38,13 +38,13 @@ set_velocity = function(self, v)
local x = 0
local z = 0
if v and v ~= 0 then
-- if v and v ~= 0 then
local yaw = (self.object:getyaw() + self.rotate) or 0
x = math.sin(yaw) * -v
z = math.cos(yaw) * v
end
-- end
self.object:setvelocity({
x = x,
@ -1053,7 +1053,7 @@ minetest.register_entity(name, {
}
if vec.x ~= 0
or vec.z ~= 0 then
and vec.z ~= 0 then
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
@ -1122,7 +1122,7 @@ minetest.register_entity(name, {
}
if vec.x ~= 0
or vec.z ~= 0 then
and vec.z ~= 0 then
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
@ -1131,7 +1131,7 @@ minetest.register_entity(name, {
end
end
else
yaw = self.object:getyaw() + ((math.random(0, 360) - 180) / 180 * pi)
yaw = (math.random(0, 360) - 180) / 180 * pi
end
self.object:setyaw(yaw)
@ -1185,7 +1185,7 @@ minetest.register_entity(name, {
}
if vec.x ~= 0
or vec.z ~= 0 then
and vec.z ~= 0 then
yaw = math.atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
@ -1199,7 +1199,7 @@ minetest.register_entity(name, {
-- otherwise randomly turn
elseif math.random(1, 100) <= 30 then
yaw = self.object:getyaw() + ((math.random(0, 360) - 180) / 180 * pi)
yaw = (math.random(0, 360) - 180) / 180 * pi
self.object:setyaw(yaw)
end
@ -1287,7 +1287,7 @@ minetest.register_entity(name, {
}
if vec.x ~= 0
or vec.z ~= 0 then
and vec.z ~= 0 then
yaw = math.atan(vec.z / vec.x) + pi / 2 - self.rotate
@ -1436,7 +1436,7 @@ minetest.register_entity(name, {
}
if vec.x ~= 0
or vec.z ~= 0 then
and vec.z ~= 0 then
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
@ -1518,7 +1518,7 @@ minetest.register_entity(name, {
}
if vec.x ~= 0
or vec.z ~= 0 then
and vec.z ~= 0 then
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
@ -1553,8 +1553,7 @@ minetest.register_entity(name, {
local obj = minetest.add_entity(p, self.arrow)
local ent = obj:get_luaentity()
local amount = (vec.x ^ 2 + vec.y ^ 2 + vec.z ^ 2) ^ 0.5
local amount = (vec.x * vec.x + vec.y * vec.y + vec.z * vec.z) ^ 0.5
local v = ent.velocity
ent.switch = 1
@ -1649,7 +1648,7 @@ minetest.register_entity(name, {
}
if vec.x ~= 0
or vec.z ~= 0 then
and vec.z ~= 0 then
local yaw = math.atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
@ -1770,8 +1769,8 @@ minetest.register_entity(name, {
self.object:set_hp(self.health)
self.object:set_armor_groups({fleshy = self.armor})
self.old_y = self.object:getpos().y
self.object:setyaw(math.random(1, 360) / 180 * pi)
self.sounds.distance = (self.sounds.distance or 10)
self.object:setyaw((math.random(0, 360) - 180) / 180 * pi)
self.sounds.distance = self.sounds.distance or 10
self.textures = textures
self.mesh = mesh
self.collisionbox = colbox