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

TFS 1.X+ [TFS 1.3] How to Do Players No Hit Monsters Melee and Range Damage?

Yan18

Member
Joined
Jun 14, 2014
Messages
104
Solutions
3
Reaction score
17
Hello folks!

I would like to know how to do players no hit damage monsters melee and range, however, the player can target monsters. In other words, I want players can target and focus monsters, but the monsters don't receive damage from players (0 damage when targeting). Although, the monster can hit damage players normally .
 
Solution
E
don't forget to register the onhealthchange event to monsters (using onspawn event)

I'd do something like this:
Lua:
local test = CreatureEvent("test")

function test.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker == nil then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if creature:isMonster() and attacker:isPlayer() then
        return 0, 0, 0, 0
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

test:register()

and MESSAGE_BLUE doesn't exist
you can use onHealthChange event and return zero if target is monster and attacker is player
I tried do this by RevScripts, but didn't work:

Lua:
local creatureevent = CreatureEvent("player_no_hit")

function creatureevent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature:isMonster() and attacker:isPlayer() then
        primaryDamage = 0
        secondaryDamage = 0

        attacker:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You cannot attack.")
       
        return primaryDamage, secondaryDamage
    end
end

creatureevent:register()

And I tried this too:
Lua:
local creatureevent = CreatureEvent("player_no_hit")

function creatureevent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature:isMonster() and attacker:isPlayer() then
        primaryDamage = 0
        secondaryDamage = 0

        attacker:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You cannot attack.")
       
        return false
    end
end

creatureevent:register()

I registered the event above on Login.lua RevScript.

I tried put 0 in vocations.xml:
XML:
<vocation id="0" clientid="0" name="None" description="" gaincap="10" gainhp="5" gainmana="5" gainhpticks="6" gainhpamount="1" gainmanaticks="6" gainmanaamount="1" manamultiplier="4.0" attackspeed="0" basespeed="220" soulmax="100" gainsoulticks="120" fromvoc="0">
        <formula meleeDamage="0" distDamage="0" defense="0" armor="10" />
        <skill id="0" multiplier="0" />
        <skill id="1" multiplier="0" />
        <skill id="2" multiplier="0" />
        <skill id="3" multiplier="0" />
        <skill id="4" multiplier="0" />
        <skill id="5" multiplier="0" />
        <skill id="6" multiplier="1.1" />
</vocation>

But it didn't work too.
 
don't forget to register the onhealthchange event to monsters (using onspawn event)

I'd do something like this:
Lua:
local test = CreatureEvent("test")

function test.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker == nil then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if creature:isMonster() and attacker:isPlayer() then
        return 0, 0, 0, 0
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

test:register()

and MESSAGE_BLUE doesn't exist
 
Solution
don't forget to register the onhealthchange event to monsters (using onspawn event)

I'd do something like this:
Lua:
local test = CreatureEvent("test")

function test.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker == nil then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if creature:isMonster() and attacker:isPlayer() then
        return 0, 0, 0, 0
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

test:register()

and MESSAGE_BLUE doesn't exist
Thanks! It works! I didn't register event to monster event, only for players in login.lua. Only missed to add the event in monster.lua on onSpawn().

About the MESSAGE_BLUE, this is a shortcut that I did to facilitate the writing, but I had edit and put the MESSAGE_STATUS_CONSOLE_BLUE to don't mistake anyone.
 
Last edited:
Back
Top