• 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 Summon heals master - exhaustion problem

guiismiti

Well-Known Member
Joined
May 19, 2014
Messages
313
Solutions
3
Reaction score
67
Hi,

I'm trying to set an exhaustion for the summon to heal the master.
Here's my script, but it isn't working. I thought os.time() would return a value in seconds. When I set the exhaustion to 0 it has no exhaustion, so, no problem there. But when I set the exhaustion to 2, it just doesn't work.
Note: the storage value 35647 is set to zero every time the player logs in.

Code:
function onThink(cid)
    local master = getCreatureMaster(cid)

    local lastHeal = getPlayerStorageValue(master, 35647)
    local nextHeal = os.time()
    if((nextHeal - lastHeal) > 0) then
        setPlayerStorageValue(master, 35647, nextHeal)
        local maxhealth = getCreatureMaxHealth(master)
        local currenthealth = getCreatureHealth(master)
        local criticalhealth = 0.4 * maxhealth

        if not isInParty(master) then
            if currenthealth < criticalhealth then
                doCreatureAddHealth(master, math.random((maxhealth * 0.125), (maxhealth * 0.20)))
                local position = getThingPosition(master)
                doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
            end
        end
    end

    return true
end
 
Add the exhaustion time to os.time(), for example: nextHeal + 10 for 10 seconds.
You can check if the storagevalue is higher then os.time() to see if the player is exhausted, after 10 seconds, os.time() will be higher than the storagevalue, before that, the storagevalue will be higher.
 
Thank you @Limos , but I managed to make it work, I don't know how.

I changed this
Code:
if((nextHeal - lastHeal) > 2) then
to this
Code:
    local exhaustion = 2
    if((nextHeal - lastHeal) > exhaustion) then

I added the var exhaustion, but I don't know what it actually changed. I was simply using '2' in the place of exhaustion before, and it wasn't working.

Well, I'll now create one function for each vocation (it will heal % of life (if master is a paladin or a knight), and will attack with either thunderstorm or gfb (sorcerer), stoneshower or ava (druid).
Shouldn't have a problem there. If anyone wants the code when I'm done with it, send me a message.


Also, I think this image fits this case well:

Story-of-Every-Programmer.jpg
 
Still unsolved (I didn't want to open a new thread) - one thing left for the summons to be ready.

So, I want the player to loose the summons if it enters any kind of PVP combat. This means that I want the player to loose summons if anybody attacks him - it doesn't matter if he attacks back or not.
Code:
if (not isInParty(master)) and (not isPlayer(target)) and (not isPlayer(attacker)) and (skull == SKULL_NONE or skull == SKULL_GREEN) then
This will remove the summon:
- isInParty(master) > If the player is in a party;
- isPlayer(target) > If the player is targeting another player;
- isPlayer(attacker) > If the summon is being targeted by a player;
- If the player has any kind of skull except for green.

So, I don't care if the summon is being attacked by a player or not. What I want to know is if the master is being targeted, regardless if the master is fighting back or not.
I even tried changing attacker for master.attacker.
(I don't want people running away safely when they get attacked by PKs)
 
Last edited:
Do you still use TFS 0.3.6?
You can add a creaturescript with type combat or statschange, here you can check if the person with summons is attacked by a player.
 
I'm using that script as a 'think' script, since the summon will be monitoring master's life the entire time.

As for the version, I'm not even sure which one it is (it's the one from OTSL 8.60), but 'combat' works, cause I implemented no damage if player is in the same party.

Well, I don't see a way out of this, but it's not a big deal though.
Thanks again Limos
 
Back
Top