Fix crashes on PUC Lua 5.1

This commit is contained in:
Lars Mueller 2023-08-18 22:30:10 +02:00
parent 8954aa3493
commit c5ce85e802
2 changed files with 12 additions and 8 deletions

View File

@ -527,9 +527,9 @@ function animalia.action_wander_walk(self, timer, pos2, speed, anim)
local check_timer = 0.25
timer = timer or 2
pos2 = pos2 or {
x = pos.x + random(width, -width),
x = pos.x + random(-width, width),
y = pos.y,
z = pos.z + random(width, -width)
z = pos.z + random(-width, width)
}
local function func(_self)
pos = _self.object:get_pos()
@ -573,9 +573,9 @@ function animalia.action_wander_fly(self, timer, pos2)
local check_timer = 0.25
timer = timer or 2
pos2 = pos2 or {
x = pos.x + random(width, -width),
y = pos.y + random(width, -width),
z = pos.z + random(width, -width)
x = pos.x + random(-width, width),
y = pos.y + random(-width, width),
z = pos.z + random(-width, width)
}
local function func(_self)
pos = _self.object:get_pos()

View File

@ -3,6 +3,10 @@
-----------
local random = math.random
-- Like `random`, but swaps `from` and `to` if needed.
local function randint(from, to)
return random(math.min(from, to), math.max(from, to))
end
local follows = {}
@ -266,9 +270,9 @@ creatura.register_mob("animalia:horse", {
tex_no = mate_ent.texture_no
end
ent:memorize("texture_no", tex_no)
ent:memorize("speed", random(mate_ent.speed, self.speed))
ent:memorize("jump_power", random(mate_ent.jump_power, self.jump_power))
ent:memorize("max_health", random(mate_ent.max_health, self.max_health))
ent:memorize("speed", randint(mate_ent.speed, self.speed))
ent:memorize("jump_power", randint(mate_ent.jump_power, self.jump_power))
ent:memorize("max_health", randint(mate_ent.max_health, self.max_health))
ent.speed = ent:recall("speed")
ent.jump_power = ent:recall("jump_power")
ent.max_health = ent:recall("max_health")