• 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 Monster spawn item under yourself if target is player?

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,758
Solutions
127
Reaction score
2,277
Hello, like in topic is it possible? I want to make monster spawn item under yourself when he is targeting player. It should spawn randomly something like 1h cooldown between each spawn for each monster.
 
Hello, like in topic is it possible? I want to make monster spawn item under yourself when he is targeting player. It should spawn randomly something like 1h cooldown between each spawn for each monster.
This should be in requests, also tell them the tfs version
 
Open new file, call it 'itemspawn.lua', paste it to the '...data\spells\scripts\monster' folder:
Code:
local config = {
    item = 2160,                    -- item id here
    count = 1,                        -- count here
    cooldown = 60 * 60 * 1000,        -- 60 min cooldown
    effect = CONST_ME_MAGIC_BLUE    -- effect when creating item
}

local condition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
condition:setParameter(CONDITION_PARAM_SUBID, 88888)
condition:setParameter(CONDITION_PARAM_TICKS, config.cooldown)
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, 0.01)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, config.cooldown)

function onCastSpell(creature, var)
    local target = creature:getTarget()
    local pos = creature:getPosition()

    if not target then
        return
    end
    if target:isPlayer() and not creature:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT, 88888) then
        creature:addCondition(condition)
        Game.createItem(config.item, config.count, pos)
        pos:sendMagicEffect(config.effect)
        return true
    end
    return true
end
and this add to spells.xml at the end of the file:
Code:
<instant name="itemspawn" words="###itemspawn" aggressive="0" blockwalls="0" needtarget="1" needlearn="1" script="monster/itemspawn.lua"/>

#edit
I forgot about this:
Code:
<attack name="itemspawn" interval="1000" target="1" range="7" chance="100"/>
Add this to your monster attack spells.
 
Last edited:
Back
Top