• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua [onStatsChange] Monster Life Percent

subyth

New Member
Joined
May 1, 2009
Messages
56
Reaction score
4
I would like to know the correct way to check a monster's life.

The way I do, crash server.

LUA:
function onStatsChange(cid, attacker, type, combat, value)
    if not isPlayer(attacker) then
        return true
    end

    local pos_msg = getCreaturePosition(cid)

    if (getCreatureName(cid) == "Demon") then
        local lifePercent = 100 / (getCreatureMaxHealth(cid) / getCreatureHealth(cid))
        if getGlobalStorageValue(cid, 30074) == 6 then
            if (lifePercent <= 10) then
                setGlobalStorageValue(cid, 30074, 7)
                doCreatureSay(cid, "TEST!", TALKTYPE_ORANGE_1, false, 0, pos_msg)
                doCreateMonster("Demon", pos_msg, false, true);
            end
        end
    end
    return true
end
 
local lifePercent = math.floor( ( getCreatureHealth(cid) / getCreatureMaxHealth(cid) ) * 100)

I can't believe i actually have to do this for you?
 
Solution
Actually it shouldn't be the problem (I think)..

What version of TFS are you using?
I think there isn't a function called "getGlobalStorageValue" and "setGlobalStorageValue" that takes the creature (Cid) as parameter...
 
Actually it shouldn't be the problem (I think)..

What version of TFS are you using?
I think there isn't a function called "getGlobalStorageValue" and "setGlobalStorageValue" that takes the creature (Cid) as parameter...
In fact, GlobalStorageValue is a global storage. I used it so it would not run 2 IF's at once but it did not work.
 
In fact, GlobalStorageValue is a global storage. I used it so it would not run 2 IF's at once but it did not work.
Yes, global storage is like an identifier for the whole server, but it doesn't have "cid" as parameter, only storage number (and, on set function, the value) (I think)
 
Yes, global storage is like an identifier for the whole server, but it doesn't have "cid" as parameter, only storage number (and, on set function, the value) (I think)
I do not know lol
I've always done it that way and it works.

I tested the script using math.floor and it worked. However, I needed to create an addEvent function because it was crashing. With addEvent, it does not run as fast and it worked. I've tested it several times and I do not think I'm in danger of crashing.
 
I do not know lol
I've always done it that way and it works.

I tested the script using math.floor and it worked. However, I needed to create an addEvent function because it was crashing. With addEvent, it does not run as fast and it worked. I've tested it several times and I do not think I'm in danger of crashing.
onStatsChange only executes when the stats of the creature change. What is this need to have an addEvent?
 
Back
Top