• 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 TFS 1.0 onChangeHealth(cid, attacker, damage)

eduardbean

Member
Joined
Nov 26, 2010
Messages
129
Solutions
2
Reaction score
16
Code:
function onChangeHealth(cid, attacker, damage)
    Creature(cid):addHealth(-damage)
    if ( Creature(cid):getMaster() ) then
        local sid = Player(Creature(cid):getMaster())
        sid.sendExtendedOpcode(sid, 26, Creature(cid):getHealth() )
    end

end

I make this for send health of summon to otclient, but now when i healh my summon, they lose health, how i can use this funcition with this "bug" ?
 
this is how onChangeHealth has to be used.
Code:
onChangeHealth(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

havn't tested it:
Code:
function onChangeHealth(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
  if creature:getMaster() then
     if Player(creature:getMaster()) then
       local sid = Player(creature:getMaster())
       sid.sendExtendedOpcode(sid, 26, (creature:getHealth() + primaryDamage))
     end
   end
   return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
Thats work, but in the client dont return the true creature health. Its have a "delay".

Im try to make it

print("\nCreature: ", creature, "\n", "Attacker: ", attacker, "\n", "Primaray Damage: ", primaryDamage, "\n", "Primary Type: ", primaryType, "\n", "Secondary Damage: ", secondaryDamage, "\n", "Secondary Type: ", secondaryType, "\n", "Origin: ", origin)

but it returns a random numbers, where i can translate this numbers ?
 
Last edited by a moderator:
Code:
function onChangeHealth(cid, attacker, damage)
    Creature(cid):addHealth(-damage)
    if ( Creature(cid):getMaster() ) then
        local sid = Player(Creature(cid):getMaster())
        sid.sendExtendedOpcode(sid, 26, Creature(cid):getHealth() )
    end

end

I make this for send health of summon to otclient, but now when i healh my summon, they lose health, how i can use this funcition with this "bug" ?

You using latest 1.0?
https://github.com/otland/forgottenserver/commit/4343f34041ad735e799dafe13bf231d27f9ff62b
 
I made this change but nothing has changed besides the name, I need to know how to identify when my summon being attacked or healed
 
onHealthChange/Mana is called before damage or heal change. If you call this and send health points to client, then it will be changed after returning the function.
You can do that: (Creature(cid):getHealth() + damage)
 
Back
Top