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

Lua Creature script: Monster only lives 20 seconds

Fermantor

Active Member
Joined
Dec 16, 2009
Messages
209
Solutions
4
Reaction score
33
Location
Germany
So in warzone 3 at vesperoth there are spawning lava golems (Minion of Vesperoth) that live for about 20 seconds.
I guess you can add a script in the monster xml and make an onThink function, that counts to 20 and the removes the creature. But I am not really sure how this type of script works. I usualy use this event function only for killing the creature.
Can you please give me an example of how this could work, doesn't need to be a working script, just basic idea.
 
So in warzone 3 at vesperoth there are spawning lava golems (Minion of Vesperoth) that live for about 20 seconds.
I guess you can add a script in the monster xml and make an onThink function, that counts to 20 and the removes the creature. But I am not really sure how this type of script works. I usualy use this event function only for killing the creature.
Can you please give me an example of how this could work, doesn't need to be a working script, just basic idea.
Do you want the monster to live only 20 seconds regardless there is a player nearby or not, or do you want it to live 20 seconds only when there is a player nearby to witness it?
 
Do you want the monster to live only 20 seconds regardless there is a player nearby or not, or do you want it to live 20 seconds only when there is a player nearby to witness it?
20 seconds regardless if there are any players around. So you get sure, monster will dissapear if players die or leave the area
 
ok... can u provide me with the monster xml file?

edit: i forgot to ask which TFS version do you use?
 
Last edited:
Can you explain this a little more in detail? :)
Code:
local spectators = Game.getSpectators(Position(x, y, z), false, false, 10, 10, 10, 10) -- Game.getSpectators(position[, multifloor = false[, onlyPlayer = false[, minRangeX = 0[, maxRangeX = 0[, minRangeY = 0[, maxRangeY = 0]]]]]])
if spectators ~= nil then
    for i = 1, #spectators do
        local spectator = spectators[i]
        if spectator and spectator:isMonster() then
            if spectator:getName():lower() == "monster name" then
                spectator:remove()
            end
        end
    end
end
 
XML:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="Minion of Vesperoth" nameDescription="minion of vesperoth" race="blood" experience="2900" speed="670" manacost="0">
  <health now="3800" max="3800"/>
  <look type="491" corpse="0"/>
  <targetchange interval="5000" chance="8"/>
  <strategy attack="90" defense="10"/>
  <flags>
    <flag summonable="0"/>
    <flag attackable="1"/>
    <flag hostile="1"/>
    <flag illusionable="0"/>
    <flag convinceable="0"/>
    <flag pushable="0"/>
    <flag canpushitems="1"/>
    <flag canpushcreatures="1"/>
    <flag targetdistance="1"/>
    <flag staticattack="90"/>
    <flag runonhealth="0"/>
  </flags>
  <script>
        <event name="MinionOfVesperoth"/>
  </script>
  <attacks>
    <attack name="melee" interval="2000" skill="90" attack="90"/>
        <attack name="manadrain" interval="2800" chance="100" range="7" min="-340" max="-540">
        </attack>   
  </attacks>
  <defenses armor="55" defense="55">    
  </defenses>
    <elements>       
        <element energyPercent="-10"/>       
        <element icePercent="-10"/>       
        <element firePercent="+30"/>
    </elements>
  <immunities>
    <immunity earth="100"/>
    <immunity lifedrain="0"/>
    <immunity paralyze="100"/>
    <immunity invisible="100"/>
  </immunities>  
    <voices interval="2500" chance="10">
        <voice sentence="Creak!"/>
        <voice sentence="Crunch!"/>
    </voices>
  <loot>  
</loot>
</monster>
 
xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<monster script="20seconds.lua" name="Minion of Vesperoth" nameDescription="minion of vesperoth" race="blood" experience="2900" speed="670" manacost="0">
  <health now="3800" max="3800"/>
  <look type="491" corpse="0"/>
  <targetchange interval="5000" chance="8"/>
  <strategy attack="90" defense="10"/>
  <flags>
    <flag summonable="0"/>
    <flag attackable="1"/>
    <flag hostile="1"/>
    <flag illusionable="0"/>
    <flag convinceable="0"/>
    <flag pushable="0"/>
    <flag canpushitems="1"/>
    <flag canpushcreatures="1"/>
    <flag targetdistance="1"/>
    <flag staticattack="90"/>
    <flag runonhealth="0"/>
  </flags>
  <attacks>
    <attack name="melee" interval="2000" skill="90" attack="90"/>
        <attack name="manadrain" interval="2800" chance="100" range="7" min="-340" max="-540">
        </attack> 
  </attacks>
  <defenses armor="55" defense="55">   
  </defenses>
    <elements>     
        <element energyPercent="-10"/>     
        <element icePercent="-10"/>     
        <element firePercent="+30"/>
    </elements>
  <immunities>
    <immunity earth="100"/>
    <immunity lifedrain="0"/>
    <immunity paralyze="100"/>
    <immunity invisible="100"/>
  </immunities> 
    <voices interval="2500" chance="10">
        <voice sentence="Creak!"/>
        <voice sentence="Crunch!"/>
    </voices>
  <loot> 
</loot>
</monster>

monsters/scripts/20seconds.lua
Lua:
local monsterTime = {}
local config = {deathTime = 20, corpse = true} -- here u can set how many seconds they live and if they die normally to leave a corpse or just dissappear

function onCreatureAppear(cid)
local think = createConditionObject(CONDITION_ATTRIBUTES) -- conditions are the only way to force a monster to "think", even if there are no players nearby
setConditionParam(think, CONDITION_PARAM_TICKS, -1) -- set condition to be indefinite in duration
cid:addCondition(think) -- give condition to monster
monsterTime[cid:getId()] = monsterTime[cid:getId()] and monsterTime[cid:getId()] or 0 -- set monster timer to 0 or leave it alone if it already has a value
end
function onCreatureDisappear(cid)                    end
function onCreatureSay(cid, type, msg)                end
function onThink(cid)
    monsterTime[cid:getId()] = monsterTime[cid:getId()] + 1 -- onThink triggers once a second, so every time onThink triggers, it adds 1 second to the monster timer
    if monsterTime[cid:getId()] == config.deathTime then -- if the amount of seconds = deathtime in config
        if config.corpse then  -- if corpse is set to "true"
            cid:addHealth(-cid:getHealth() - 1) -- drains it's health to die normally and leave a corpse
        else -- if corpse is not set to "true"
            cid:remove() -- removes itself from the server without leaving a corpse
        end
    end
end

tested and works fine so far. let me know if u run into problems.
 
When a creature first sees a person, their spell timers start.

So if you have a creature with a spell, that has a 20 second interval, it will run that spell after 20 seconds.
This means you could literally make a "Remove Creature" spell, and add it to any creature. Then just set the interval to the time-limit of the creature.
 
When a creature first sees a person, their spell timers start.

So if you have a creature with a spell, that has a 20 second interval, it will run that spell after 20 seconds.
This means you could literally make a "Remove Creature" spell, and add it to any creature. Then just set the interval to the time-limit of the creature.
Is that for all iterations of tfs?
The creature spell timer start, part.
 
I believe yes.

But, even if you find out that it runs the spell timer when the creature first becomes active. Then you'd just set it to require the spell to cast twice before it removes the creature.
 
When a creature first sees a person, their spell timers start.

So if you have a creature with a spell, that has a 20 second interval, it will run that spell after 20 seconds.
This means you could literally make a "Remove Creature" spell, and add it to any creature. Then just set the interval to the time-limit of the creature.

Thats a really good idea
 
Back
Top