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

onHealthChange CreatureScripts

mackerel

Well-Known Member
Joined
Apr 26, 2017
Messages
398
Solutions
18
Reaction score
72
From the name, I am guessing this function is being perfomed every time player hits an enemy (if it has been registered under player, not monster).

Here is my question, I want to know if you can register certain events only for specific vocation, let us say we have login.lua and inside that file, it will be something like;

Lua:
function onLogin(cid)
if Player(cid):getVocation() == 2 then
    Player(cid):registerEvent("XXX")
end
return true
end

I think I just answered my own question, okay so I have another one;

Is there any other way to link between creaturescripts folder and spells folder other than storage ID?

At the moment I have something like this:

[Spells] 1. Execute spell
[Spells] 2. Assign storage ID; 5000 = 1
[Creaturescripts] 3. If storage ID (5000 == 1) then do something

Once the spell is active the player gets unique storage ID and every time they hit, they will check for storage ID if its there they will perform various functions inside onHealthChange. So I was wondering if there is any other way than using storage ID

TFS 1.0

Thanks a lot!
 
Last edited:
Solution
From the name, I am guessing this function is being perfomed every time player hits an enemy (if it has been registered under player, not monster).
It's executed every time the health changes. You don't have to be hit by any creature at all.
If it has been registered under player, so it's player's health that matters not a monster.

Here is my question, I want to know if you can register certain events only for specific vocation, let us say we have login.lua and inside that file, it will be something like;
Yes, but i guess you can also just put vocation check directly in your "XXX" event.

Is there any other way to link between creaturescripts folder and spells folder other than storage ID?

At the moment I have something...
From the name, I am guessing this function is being perfomed every time player hits an enemy (if it has been registered under player, not monster).
It's executed every time the health changes. You don't have to be hit by any creature at all.
If it has been registered under player, so it's player's health that matters not a monster.

Here is my question, I want to know if you can register certain events only for specific vocation, let us say we have login.lua and inside that file, it will be something like;
Yes, but i guess you can also just put vocation check directly in your "XXX" event.

Is there any other way to link between creaturescripts folder and spells folder other than storage ID?

At the moment I have something like this:

[Spells] 1. Execute spell
[Spells] 2. Assign storage ID; 5000 = 1
[Creaturescripts] 3. If storage ID (5000 == 1) then do something
Conditions with set SUBIDs. But storage is good.
 
Solution
Yes, but i guess you can also just put vocation check directly in your "XXX" event.
That's what I thought but it's not efficient since registerEvent 'XXX' 'healthchange' will be allocated to every player, instead we can simply pass the function to specific vocations during login.

Also, I was trying to registerEvent 'logout' the same way I did the other one but it didn't work as it registered under every player so this is where I was forced to use the method you just mentioned. Not sure if there is any workaround to this one.

Conditions with set SUBIDs. But storage is good.
Hmm, if you say storage is good then I should probably continue using it. I've looked at SUBIDs and it looks like it's more C++ oriented, something like haste or strong haste spells. Correct me if I am wrong
 
Hmm, if you say storage is good then I should probably continue using it. I've looked at SUBIDs and it looks like it's more C++ oriented, something like haste or strong haste spells. Correct me if I am wrong
If you want to make some custom condition it's good to use both subid and storage value.
You can add condition with certain subid to a player that refers to your onHealthChange script and set storage value as some attribute.
So let's say you add attributes condition with subid 100 to a player and amount of bonus would depend on storage value he has got.
 
Back
Top