• 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 prevent summon attacks

Fortera Global

Intermediate OT User
Joined
Nov 20, 2015
Messages
1,180
Solutions
2
Reaction score
117
What I'm trying to do: prevent spells from my summon from affecting a player I did not attack or affect (take pk) if I'm not on secureMode.
I mean, if player are with secureMode/have a summon/his summon attack one monster, the spell will shoot the target:isPlayer() but like non-pvp (no damage)

tfs 1.3
current script:

Lua:
    local Master = self:getMaster()
    if Master then
        if Master:isPlayer() then
            if (self:getName():lower() == 'monk vip') then
                if target and target:isPlayer() then
                    -- no works here cuz my target is monster
                    if self:getMaster():hasSecureMode() then
                        return RETURNVALUE_TURNSECUREMODETOATTACKUNMARKEDPLAYERS
                    end
                end
            end
        end
    end

cksX5BN.png
 
Last edited by a moderator:
Solution
remember to check in your "luascript.cpp" if you have this function Player.hasSecureMode()
Code:
local master = self:getMaster()
    if master and master:isPlayer() and target and target:isPlayer() and master:hasSecureMode() then
        return RETURNVALUE_NOTPOSSIBLE
    end
me like please :eek:
Edit for ( and target )
same, but u solved with this?
Add in creaturescripts.xml
Lua:
    <event type="HealthChange" name="summonsHealDmg" script="summon_dmg.lua"/>
    <event type="ManaChange" name="summonsManaDmg" script="summon_dmg.lua"/>

Create new file with name summon_dmg.lua in creaturescripts/scripts/ and add:
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    local summons = creature:getSummons()
    if summons and #summons > 0 and table.contains(summons, attacker) then
        return 0, primaryType, 0, secondaryType
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

function onManaChange(creature, attacker, manaChange, origin)
    local summons = creature:getSummons()
    if summons and #summons > 0 and table.contains(summons, attacker) then
        return 0
    end
    return manaChange
end

Add in creaturescripts/scripts/login.lua
Lua:
player:registerEvent("summonsHealDmg")
player:registerEvent("summonsManaDmg")

That will work. But if you have more than 1 summon, it attacks each other. If you know how to solve this problem I would also appreciate, please!
 
Back
Top