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

Request function TFS 1.2

darcioantonio

www.adventurerpg.com.br
Joined
Jul 30, 2013
Messages
165
Solutions
1
Reaction score
4
Location
Brasil
Twitch
darcio_
YouTube
UCEXCOEw_dYchojHNz
I would like to know which function is responsible for checking when the player receives damage from a creature, I will create some shields that when the player receives damage from the monster has 10% chance to activate and the player receives 10 to 20 mana!
 
creaturescript
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
end
 
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    --if creature that recived the damage is a PLAYER, reduce damage to 50%
    if creature:isPlayer() then
        primaryDamage = primaryDamage * 0.5
        secondaryDamage = secondaryDamage * 0.5
    end
    
    --if creature that recived the damage is a MONSTER, reduce damage to 75%
    if creature:isMonster() then
        primaryDamage = primaryDamage * 0.75
        secondaryDamage = secondaryDamage * 0.5
    end
    
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
if a monster attacks me it will have an effect on me!
I just need the function and a simple explanation of how to put the script into action +

Lua:
if monster_ataque_me_player then
sendefect(me_player)
end



I am creating a system of attributes on items such as shields, swords etc, as soon as the player takes damage from a monster there will be a% chance of raising the hp or mana slightly

@
zxmatzx
 
Last edited:
if a monster attacks me it will have an effect on me!
I just need the function and a simple explanation of how to put the script into action +

Lua:
if monster_ataque_me_player then
sendefect(me_player)
end



I am creating a system of attributes on items such as shields, swords etc, as soon as the player takes damage from a monster there will be a% chance of raising the hp or mana slightly

@
zxmatzx
data/events/events.xml:
Set enabled to 1
XML:
<event class="Creature" method="onTargetCombat" enabled="1" />

data/events/scripts/creature.lua:
Lua:
function Creature:onTargetCombat(target)
    if target:isPlayer() and self:isMonster() then
        target:getPosition():sendMagicEffect(6)--6 = number of effect
    end
    return true
end
 
I managed using it now

Lua:
-- Register in creaturescripts.xml
<event type="HealthChange" name="Teste" script="teste.lua" />

-- Register in Login.php
player:registerEvent("Teste")

-- Register in teste.lua
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)   
    if isCreature(attacker) then
        creature:say("TESTE!", TALKTYPE_MONSTER_SAY)
        creature:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
Post automatically merged:

@zxmatzx

your method is much better thank you!
 
Back
Top