• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Ugly monster

onewave1

Member
Joined
May 26, 2021
Messages
90
Reaction score
15
I need a gaffir when he has 50% of his life he creates an "ugly monster"
Lua:
local uglyspawn = CreatureEvent("uglyspawn")
local count = true
local chance = math.random(0, 100)
function uglyspawn.onThink(creature)
    local hp = (creature:getHealth()/creature:getMaxHealth())*100
    print(count)
    print(chance)
    if chance < 33 then
        if (hp < 50 and count) then
            Game.createMonster("Ugly Monster", creature:getPosition())
            count = false
        end
    end
end
uglyspawn:register()
I have something like this but it work only with first monster
the point is that it does not draw again and count = false
TFS 1.3
 
Solution
works almost perfect but "chance" roll all the time, not once and "ugly monster" spawns always
Right.
Lua:
local uglyspawn = CreatureEvent("uglyspawn")
local spawned = {}
local chance = {}

function uglyspawn.onThink(creature)
    local cid = creature:getId()
    if spawned[cid] then
        return
    end
    if not chance[cid] then
        chance[cid] = math.random(100)
    end
    local hp = (creature:getHealth()/creature:getMaxHealth())*100
 
    if hp < 50 then
        if chance[cid] < 33 then
            Game.createMonster("Ugly Monster", creature:getPosition())
            spawned[cid] = true
        end
    end
end
uglyspawn:register()
Lua:
local uglyspawn = CreatureEvent("uglyspawn")
local spawned = {}

function uglyspawn.onThink(creature)
    local cid = creature:getId()
    if spawned[cid] then
        return
    end
    local hp = (creature:getHealth()/creature:getMaxHealth())*100
 
    if hp < 50 then
        local chance = math.random(100)
        if chance < 33 then
            Game.createMonster("Ugly Monster", creature:getPosition())
            spawned[cid] = true
        end
    end
end
uglyspawn:register()
 
Lua:
local uglyspawn = CreatureEvent("uglyspawn")
local spawned = {}

function uglyspawn.onThink(creature)
    local cid = creature:getId()
    if spawned[cid] then
        return
    end
    local hp = (creature:getHealth()/creature:getMaxHealth())*100
 
    if hp < 50 then
        local chance = math.random(100)
        if chance < 33 then
            Game.createMonster("Ugly Monster", creature:getPosition())
            spawned[cid] = true
        end
    end
end
uglyspawn:register()
works almost perfect but "chance" roll all the time, not once and "ugly monster" spawns always
 
works almost perfect but "chance" roll all the time, not once and "ugly monster" spawns always
Right.
Lua:
local uglyspawn = CreatureEvent("uglyspawn")
local spawned = {}
local chance = {}

function uglyspawn.onThink(creature)
    local cid = creature:getId()
    if spawned[cid] then
        return
    end
    if not chance[cid] then
        chance[cid] = math.random(100)
    end
    local hp = (creature:getHealth()/creature:getMaxHealth())*100
 
    if hp < 50 then
        if chance[cid] < 33 then
            Game.createMonster("Ugly Monster", creature:getPosition())
            spawned[cid] = true
        end
    end
end
uglyspawn:register()
 
Solution
Back
Top