• 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!

Solved Script question TFS 1.2

Aeronx

Intermediate OT User
Joined
Dec 17, 2015
Messages
738
Solutions
9
Reaction score
123
Hello ladies and gentlemen! I've got a little script that tp summons to master:

Code:
local distFromMaster = 6

function onThink(interval)
    for _, player in ipairs(Game.getPlayers()) do
        local playerPos = player:getPosition()
        if not Tile(playerPos):hasFlag(TILESTATE_PROTECTIONZONE) then
            local summons = player:getSummons()
            if #summons ~= 0 then
                for i = 1, #summons do
                    local summon = summons[i]
                    local summonPos = summon:getPosition()
                    if summonPos.z ~= playerPos.z or summonPos:getDistance(playerPos) > distFromMaster then
                        summon:teleportTo(playerPos)
                                            end
                end
            end
        end
    end
    return true
end

But now, i have a summon that i dont want to be teleported to master, how can i make "if summon == fire elemental" no telportTo..!

Thanks everybody!
 
Code:
if summonPos.z ~= playerPos.z or summonPos:getDistance(playerPos) > distFromMaster then
        if summon:getName():lower() ~= 'fire elemental' then
                summon:teleportTo(playerPos)
        end
end
 
Thanks! That worked perfectly! :)

I've got another issue tho:

Code:
function bye(creature)
    creature:remove()
end

function onThink(creature)
        if(not creature:isMonster()) then
            return true
        end
        local name = creature:getName() == "Fire Elemental"
        addEvent(bye, 10000, name)
        return true
    end

Why this doesnt work? It basically should do after 10 seconds in this case, remove the creature. Its a creaturescript.

Thanks for your help guys!
 
addEvent(bye, 10000, name)

creature:getId() instead of name
then in bye do Creature(creature):remove()
 
local name = creature:getName() == "Fire Elemental"
this a boolean. either true or false, not a creature userdata
 
Still not working :/

Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/creaturescripts/scripts/custom/fire totem.lua:2: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/custom/fire totem.lua:2: in function <data/creaturescripts/scripts/custom/fire totem.lua:1>

Code:
function bye(creature)
    Creature(creature):remove()
end

function onThink(creature)
        if(not creature:isMonster()) then
            return true
        end
        local name = creature:getId()
        addEvent(bye, 10000, name)
        return true
    end
 
Still nothing, argument unsafe#3 and same errors after that :/
Code:
function onThink(interval)
onThink only uses interval.
Changing "interval" to "creature" doesn't change the function parameters. -- afaik

So your very first line is currently asking if 'interval is not a monster, end function"

You can test this by adding
print(1)
-- check if monster
print(2)
 
I've simplified it like this looking at some other scripts i have. No errors, but instead of remove after 5 seconds, it gets removed instant after summoning it.

Code:
function onThink(creature)
    addEvent(function(cid)
    local creature = Creature(cid)

    return true
end, 5000, creature:remove())
end
 
I've simplified it like this looking at some other scripts i have. No errors, but instead of remove after 5 seconds, it gets removed instant after summoning it.

Code:
function onThink(creature)
    addEvent(function(cid)
    local creature = Creature(cid)

    return true
end, 5000, creature:remove())
end
Code:
function onThink(creature)
    addEvent(function(cid)
        local creature = Creature(cid)
        if creature then
            creature:remove()
        end
        return true
    end, 5000, creature:getId())
   
    return true
end
 
Its work perfect! thanks all!

Now im trying to add this. It works, but not as intended. Instead of doing the event once every time its called, it just spam area damage.
I guess it because everytime that "think" it executes that event from second 1. How do i solve that? thanks

Code:
local hitArea = createCombatArea(AREA_CIRCLE2X2)
function onThink(creature)
    addEvent(function(cid)
        local creature = Creature(cid)
        if creature then
            creature:remove()
        end
        return true
    end, 10000, creature:getId())
    addEvent(function(cid)
    local creature = Creature(cid)
    if creature then
   doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -100, -200, CONST_ME_FIREAREA)
   end
   end, 1000, creature:getId())
 
       addEvent(function(cid)
    local creature = Creature(cid)
    if creature then
   doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -100, -200, CONST_ME_FIREAREA)
   end
   end, 3000, creature:getId())
 
       addEvent(function(cid)
    local creature = Creature(cid)
    if creature then
   doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -100, -200, CONST_ME_FIREAREA)
   end
   end, 5000, creature:getId())
 
       addEvent(function(cid)
    local creature = Creature(cid)
    if creature then
   doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -100, -200, CONST_ME_FIREAREA)
   end
   end, 7000, creature:getId())
 
       addEvent(function(cid)
    local creature = Creature(cid)
    if creature then
   doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -200, -300, CONST_ME_FIREAREA)
   end
   end, 9500, creature:getId())
    return true
end
 
Its work perfect! thanks all!

Now im trying to add this. It works, but not as intended. Instead of doing the event once every time its called, it just spam area damage.
I guess it because everytime that "think" it executes that event from second 1. How do i solve that? thanks

Code:
local hitArea = createCombatArea(AREA_CIRCLE2X2)
function onThink(creature)
    addEvent(function(cid)
        local creature = Creature(cid)
        if creature then
            creature:remove()
        end
        return true
    end, 10000, creature:getId())
    addEvent(function(cid)
    local creature = Creature(cid)
    if creature then
   doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -100, -200, CONST_ME_FIREAREA)
   end
   end, 1000, creature:getId())

       addEvent(function(cid)
    local creature = Creature(cid)
    if creature then
   doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -100, -200, CONST_ME_FIREAREA)
   end
   end, 3000, creature:getId())

       addEvent(function(cid)
    local creature = Creature(cid)
    if creature then
   doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -100, -200, CONST_ME_FIREAREA)
   end
   end, 5000, creature:getId())

       addEvent(function(cid)
    local creature = Creature(cid)
    if creature then
   doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -100, -200, CONST_ME_FIREAREA)
   end
   end, 7000, creature:getId())

       addEvent(function(cid)
    local creature = Creature(cid)
    if creature then
   doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -200, -300, CONST_ME_FIREAREA)
   end
   end, 9500, creature:getId())
    return true
end
Use proper indentation please...
Code:
local hitArea = createCombatArea(AREA_CIRCLE2X2)
local eventsFired = {}
function onThink(creature)
    if not eventsFired[creature:getId()] then
        addEvent(function(cid)
            local creature = Creature(cid)
            if creature then
                creature:remove()
            end
        end, 10000, creature:getId())
       
        addEvent(function(cid)
            local creature = Creature(cid)
            if creature then
                doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -100, -200, CONST_ME_FIREAREA)
            end
        end, 1000, creature:getId())

        addEvent(function(cid)
            local creature = Creature(cid)
            if creature then
                doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -100, -200, CONST_ME_FIREAREA)
            end
        end, 3000, creature:getId())

        addEvent(function(cid)
            local creature = Creature(cid)
            if creature then
                doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -100, -200, CONST_ME_FIREAREA)
            end
        end, 5000, creature:getId())

        addEvent(function(cid)
            local creature = Creature(cid)
            if creature then
                doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -100, -200, CONST_ME_FIREAREA)
            end
        end, 7000, creature:getId())

        addEvent(function(cid)
        local creature = Creature(cid)
            if creature then
                doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -200, -300, CONST_ME_FIREAREA)
            end
        end, 9500, creature:getId())
       
        eventsFired[creature:getId()] = true
    end
    return true
end
 
As always @MatheusMkalo learning tons from you!

I wanted to go further, but im failing to get master:getMagicLevel()

Code:
       addEvent(function(cid)
            local creature = Creature(cid)
            if creature then
                local master = creature:getMaster()
                if master ~= nil and master:isPlayer() then
                local min = master():getMagicLevel()
                doAreaCombatHealth(creature, COMBAT_FIREDAMAGE, creature:getPosition(), hitArea, -min, -200, CONST_ME_FIREAREA)
            end
            end
        end, 1000, creature:getId())
 
Also, im trying to do it the healing way. But this heals monsters instead of players. A little explanation on how to make only heal master and party members (if there are party members). Thanks!!

Code:
        addEvent(function(cid)
            local creature = Creature(cid)
            if creature then
                doAreaCombatHealth(creature, COMBAT_HEALING, creature:getPosition(), hitArea, 100, 200, CONST_ME_MAGIC_BLUE)
            end
            end
        end, 1000, creature:getId())
 
Also, im trying to do it the healing way. But this heals monsters instead of players. A little explanation on how to make only heal master and party members (if there are party members). Thanks!!
Creature is a super or parent metatable to a npc, player or monster.
 
Back
Top