• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua [TFS 1.x]Monster scale on player entry amount

Lopaskurwa

Well-Known Member
Joined
Oct 6, 2017
Messages
936
Solutions
2
Reaction score
57
Anyone know or got a script that basically would spawn monster that has scalable health and damage or at least one of it, could be action script or movementscript if there is X players on screen or lets say it checks if players stand in square of x,y,z [could be zone check if players are in zone X] it gets all of the players and spawns a stronger monster according to the amount of participants?
 
Solution
Talked with @Lopaskurwa in private
End product:


LUA:
local config = {
    bossName = "Demon",
    bossPosition = Position(1079, 1001, 7),
    bossLoot = {
        {9020, 1, 3, 1000}, -- ItemId, ItemAmount Min, ItemAmount Max , Chance
    },
    topLeft = Position(1072, 994, 7), -- TOP Left Area Position
    bottomRight = Position(1085, 1006, 7), -- BOTTOM Right Area Position
    storage = 50000, -- For Exhaust.
    actionId = 4723, -- The action id of the lever.
    expReward = 5000000, -- Experience reward for players that did at least 2% damage to the boss
    minHealthDamagePercent = 0.02, -- Minimum damage percent to be eligible for experience reward
    time = 30, -- seconds
}...
When it comes to a some sort of a system that spawns monster usually i use
doSummonCreature or Game.createMonster

If you like system skulls check this proposition
How many "phases" do you think there will be in total for a given monster?

If you have events/creature.lua, you can do this easily
First, check the player count using Game.getSpectators() and local table #players - (you should definitely have a boss arena script you can use to get this)

Then create a fixed scenario like:

LUA:
local mob = Game.createMonster("Rat", Position(123, 123, 7), false, false)

if #players >= 2 then
mob:setSkull(2)
end
if #players >= 3 then
mob:setSkull(3)
end
if #players >= 4 then
mob:setSkull(4)
end
if #players >= 5 then
mob:setSkull(5)
end

And then in events/creature.lua or creaturescripts

LUA:
if attacker:isMonster() then -- for attack
if attacker:getSkull() == 2 then
primaryDamage = primaryDamage * 2
end

if attacker:getSkull() == 3 then
primaryDamage = primaryDamage * 3
end

if attacker:getSkull() == 4 then
primaryDamage = primaryDamage * 4
end

if attacker:getSkull() == 5 then
primaryDamage = primaryDamage * 5
end
end

--else if for damage from players (defence monster)
 
Last edited:
If you like system skulls check this proposition
How many "phases" do you think there will be in total for a given monster?

If you have events/creature.lua, you can do this easily
First, check the player count using Game.getSpectators() and local table #players - (you should definitely have a boss arena script you can use to get this)

Then create a fixed scenario like:

LUA:
local mob = Game.createMonster("Rat", Position(123, 123, 7), false, false)

if #players >= 2 then
mob:setSkull(2)
end
if #players >= 3 then
mob:setSkull(3)
end
if #players >= 4 then
mob:setSkull(4)
end
if #players >= 5 then
mob:setSkull(5)
end

And then in events/creature.lua or creaturescripts

LUA:
if attacker:isMonster() then -- for attack
if attacker:getSkull() == 2 then
primaryDamage = primaryDamage * 2
end

if attacker:getSkull() == 3 then
primaryDamage = primaryDamage * 3
end

if attacker:getSkull() == 4 then
primaryDamage = primaryDamage * 4
end

if attacker:getSkull() == 5 then
primaryDamage = primaryDamage * 5
end
end

--else if for damage from players (defence monster)

This is the lazy solution
There are way better solutions
 
Probably. If you have it for free, share it. But I don't know why you add a banner to your post every time. It won't bring in more players

I don't know why you still don't know that the banner is added in the signature (member since 2019 btw)
You made yourself ridiculous with that answer, gg!
Using ChatGpt doesn't make you smarter ;D

When it comes to a some sort of a system that spawns monster usually i use
doSummonCreature or Game.createMonster

Send me all information via DM how the script should exactly work and I will help you with that
 
Last edited:
I don't know why you still don't know that the banner is added in the signature (member since 2019 btw)
You made yourself ridiculous with that answer, gg!
Using ChatGpt doesn't make you smarter ;D



Send me all information via DM how the script should exactly work and I will help you with that


It's always nice to cheer someone up. He definitely needs advice, not opinions. Thanks for your focus
But Chatgpt?
Some things are written on a phone. So who is lazy?

The skull solution was created a long time ago and helps visually distinguish monster levels. We don't know if the user has monster:getLevel() functions, etc., but it's pretty universal and should work on any server (generated without gpt)
 
It's always nice to cheer someone up. He definitely needs advice, not opinions. Thanks for your focus
But Chatgpt?
Some things are written on a phone. So who is lazy?

Can you please speak like a human so I could atleast understand what u saying :D

The skull solution was created a long time ago and helps visually distinguish monster levels. We don't know if the user has monster:getLevel() functions, etc., but it's pretty universal and should work on any server (generated without gpt)

It may work but based on your answer
5 players -> setSkull 5
What u do if there are 10 players as example
 
Talked with @Lopaskurwa in private
End product:


LUA:
local config = {
    bossName = "Demon",
    bossPosition = Position(1079, 1001, 7),
    bossLoot = {
        {9020, 1, 3, 1000}, -- ItemId, ItemAmount Min, ItemAmount Max , Chance
    },
    topLeft = Position(1072, 994, 7), -- TOP Left Area Position
    bottomRight = Position(1085, 1006, 7), -- BOTTOM Right Area Position
    storage = 50000, -- For Exhaust.
    actionId = 4723, -- The action id of the lever.
    expReward = 5000000, -- Experience reward for players that did at least 2% damage to the boss
    minHealthDamagePercent = 0.02, -- Minimum damage percent to be eligible for experience reward
    time = 30, -- seconds
}
----------------------------------------------------
-- local playersInArea = getPlayersInArea(topLeft, bottomRight)
local function getPlayersInArea(topLeft, bottomRight)
    local count = 0

    for _, player in ipairs(Game.getPlayers()) do
        local pos = player:getPosition()

        if pos.z == topLeft.z
        and pos.x >= topLeft.x and pos.x <= bottomRight.x
        and pos.y >= topLeft.y and pos.y <= bottomRight.y then
            count = count + 1
        end
    end

    return count
end
----------------------------------------------------
local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if not item:getActionId() == config.actionId then
        return true
    end
    if Game.getStorageValue(config.storage) == 1 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'The boss is already spawned.')
        return true
    end
    if Game.getStorageValue(config.storage) > os.time() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Boss can be spawned again in ' ..Game.getStorageValue(config.storage) - os.time()..' seconds.')
        return true
    end
    local playersInArea = getPlayersInArea(config.topLeft, config.bottomRight)
    local monster = Game.createMonster(config.bossName, config.bossPosition, nil, true)
    if monster then
        monster:setMaxHealth(monster:getMaxHealth() * playersInArea) -- If you got 4 players in the area the boss will have 4x health.
        monster:addHealth(monster:getMaxHealth()) -- Heal the monster to full health after changing max health.
        monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        monster:registerEvent("bossGuildDeath") -- Death Event Register
    end
    Game.setStorageValue(config.storage, 1) -- This will avoid spawning multipe bosses.
    return true
end

action:aid(config.actionId)
action:register()
----------------------------------------------------
-- Boss death event (LOOT HANDLER)
local creatureEvent = CreatureEvent("bossGuildDeath")

function creatureEvent.onDeath(creature, corpse, lastHitKiller, mostDamageKiller)
    if creature:isPlayer() or creature:getMaster() then
        return true
    end

    if not corpse or not corpse:isContainer() then
        return true
    end

    local playersInArea = getPlayersInArea(config.topLeft, config.bottomRight)
    for _, loot in ipairs(config.bossLoot) do
        if math.random(1000) <= loot[4] then
            local amount = math.random(loot[2] * playersInArea, loot[3] * playersInArea)
            corpse:addItem(loot[1], amount)
        end
    end
  
    for pid, info in pairs(creature:getDamageMap()) do
        local percent = creature:getMaxHealth() * config.minHealthDamagePercent
        local player = Player(pid)
        if player and info.total >= percent then
            player:addExperience(config.expReward, true)
        end
    end
    Game.setStorageValue(config.storage, 0) -- Keep this to check if the boss is spawned or not.
    Game.setStorageValue(config.storage, os.time() + config.time)
    return true
end

creatureEvent:register()
 
Last edited:
Solution
Back
Top