• 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 onEquip Create (summon) / get bonus

alejandro762

Well-Known Member
Joined
Sep 6, 2021
Messages
224
Reaction score
62
Hello everyone,

Im testing on TFS 1.3 to create onEquip and deEquip an item, getting for example 2% chance to create a summon who helps the player for 20 seconds, but also giving a bonus stat for 20 seconds.

I start the script like this:

Lua:
local summonTest = MoveEvent()

local config = {
    chance = 2,
    summon = 'rat',
    bonus = 'SKILL_CRITICAL_HIT_CHANCE',
    bonus.percent = 2,
    duration = 20
}

function summonTest.onEquip(player, item, slot, isCheck, fromPosition)
if isCheck then
        return true
    end
    local pos = player:getPosition()
    local chance = math.random(100)
    pos:sendMagicEffect(CONST_ME_TELEPORT)
    if chance then
    game.createmonster(config.summon, pos? player:getposition() ?) -- There im not sure
    -- player:addSkill(config.bonus, bonus.percent) or
    -- addEvent(config.bonus, bonus.percent, config.duration)
    end
end

summonTest:type("equip")
summonTest:id(10300)
summonTest:register()


function summonTest.onDeEquip(player, item, slot, spectators)
    local pos = player:getPosition()
    pos:sendMagicEffect(CONST_ME_POFF)
    stopEvent(config.bonus)
    -- there dit we need to use getSpectators() if spectator:isPlayer() or isMonster () then spectator:remove() ?
-- for i = 1, #spectators do
    -- if spectator:isMonster()  then -- how register a duration here ?
    -- spectator:remove()
-- end

summonTest:type("deequip")
summonTest:id(10300)
summonTest:register()

Thanks in advance if anyone could explain me,

Regards
 
Solution
I'm not good at explaining, but I can show you an example of course.
Example with your script:
yourscript.lua
Lua:
local config = {
    chance = 2,
    summon = 'rat',
    bonus = CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE,
    bonusPercent = 2,
    duration = 20
}

local summons = {}

local summonTest = MoveEvent()

function summonTest.onEquip(player, item, slot, isCheck)
    if isCheck then
        return true
    end

    if math.random(100) <= config.chance then
        local monster = Game.createMonster(config.summon, player:getPosition())
        if monster then
            monster:setMaster(player)
            monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            summons[player:getId()] = monster:getId()...
I'm not good at explaining, but I can show you an example of course.
Example with your script:
yourscript.lua
Lua:
local config = {
    chance = 2,
    summon = 'rat',
    bonus = CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE,
    bonusPercent = 2,
    duration = 20
}

local summons = {}

local summonTest = MoveEvent()

function summonTest.onEquip(player, item, slot, isCheck)
    if isCheck then
        return true
    end

    if math.random(100) <= config.chance then
        local monster = Game.createMonster(config.summon, player:getPosition())
        if monster then
            monster:setMaster(player)
            monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            summons[player:getId()] = monster:getId()
            local bonus = Condition(CONDITION_ATTRIBUTES)
            bonus:setParameter(CONDITION_PARAM_TICKS, config.duration * 1000)
            bonus:setParameter(config.bonus, config.bonusPercent)
            player:addCondition(bonus)
            return true
        end
    end

    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return true
end

summonTest:id(10300)
summonTest:register()

local summonTest = MoveEvent()

function summonTest.onDeEquip(player, item, slot)
    local playerId = player:getId()
    if summons[playerId] then
        local monster = Monster(summons[playerId])
        if monster then
            monster:remove()
            summons[playerId] = nil
        end
    end
    return true
end

summonTest:id(10300)
summonTest:register()
I haven't tested the script, but it should work fine.
 
Solution
I'm not good at explaining, but I can show you an example of course.
Example with your script:
yourscript.lua
Lua:
local config = {
    chance = 2,
    summon = 'rat',
    bonus = CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE,
    bonusPercent = 2,
    duration = 20
}

local summons = {}

local summonTest = MoveEvent()

function summonTest.onEquip(player, item, slot, isCheck)
    if isCheck then
        return true
    end

    if math.random(100) <= config.chance then
        local monster = Game.createMonster(config.summon, player:getPosition())
        if monster then
            monster:setMaster(player)
            monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            summons[player:getId()] = monster:getId()
            local bonus = Condition(CONDITION_ATTRIBUTES)
            bonus:setParameter(CONDITION_PARAM_TICKS, config.duration * 1000)
            bonus:setParameter(config.bonus, config.bonusPercent)
            player:addCondition(bonus)
            return true
        end
    end

    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return true
end

summonTest:id(10300)
summonTest:register()

local summonTest = MoveEvent()

function summonTest.onDeEquip(player, item, slot)
    local playerId = player:getId()
    if summons[playerId] then
        local monster = Monster(summons[playerId])
        if monster then
            monster:remove()
            summons[playerId] = nil
        end
    end
    return true
end

summonTest:id(10300)
summonTest:register()
I haven't tested the script, but it should work fine.
works perfect in TFS 1.4, is it possible to make the creature immune to the attacks of the player who summons it with the item?
 
I'm not good at explaining, but I can show you an example of course.
Example with your script:
yourscript.lua
Lua:
local config = {
    chance = 2,
    summon = 'rat',
    bonus = CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE,
    bonusPercent = 2,
    duration = 20
}

local summons = {}

local summonTest = MoveEvent()

function summonTest.onEquip(player, item, slot, isCheck)
    if isCheck then
        return true
    end

    if math.random(100) <= config.chance then
        local monster = Game.createMonster(config.summon, player:getPosition())
        if monster then
            monster:setMaster(player)
            monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            summons[player:getId()] = monster:getId()
            local bonus = Condition(CONDITION_ATTRIBUTES)
            bonus:setParameter(CONDITION_PARAM_TICKS, config.duration * 1000)
            bonus:setParameter(config.bonus, config.bonusPercent)
            player:addCondition(bonus)
            return true
        end
    end

    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return true
end

summonTest:id(10300)
summonTest:register()

local summonTest = MoveEvent()

function summonTest.onDeEquip(player, item, slot)
    local playerId = player:getId()
    if summons[playerId] then
        local monster = Monster(summons[playerId])
        if monster then
            monster:remove()
            summons[playerId] = nil
        end
    end
    return true
end

summonTest:id(10300)
summonTest:register()
I haven't tested the script, but it should work fine.

Yes i forget, i am looking about "onPlayerAttack" to give this chance/bonus , each time a player attack has 2% chance to summon a rat and give a bonus of 2% skill crit, or maybe more easy onKill/onUseWeapon ? but i think i need to script the item on movements in this case.
I can't find on visual an example of player attacking to try it

Anyway thanks is working perfectly
 
Last edited:

Similar threads

Back
Top