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

C++ [TFS1.3] doSetHealthBackgroundOutfit

srunobantana

Member
Joined
Oct 24, 2021
Messages
42
Reaction score
19
I have the doSetHealthBackgroundOutfit function in TFS 0.4

File: luascript.cpp


In TFS 0.4, the doSetHealthBackgroundOutfit function is registered as follows:

luascript.CPP
C++:
// Register the function in Lua
lua_register(m_luaState, "doSetHealthBackgroundOutfit", LuaInterface::luaDoSetHealthBackgroundOutfit);

int32_t LuaInterface::luaDoSetHealthBackgroundOutfit(lua_State* L)
{
    // Arguments: doSetHealthBackgroundOutfit(cid, healthBackground)
    ScriptEnviroment* env = getEnv();
    uint16_t healthBg = popNumber(L);  // Get the healthBackground value
    const Creature* creature = env->getCreatureByUID(popNumber(L));  // Retrieve the creature by UID
    
    if (!creature) {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));  // If the creature is not found
        lua_pushboolean(L, false);  // Return "false" in case of error
        return 1;
    }

    Outfit_t outfit = creature->getCurrentOutfit();  // Get the current outfit of the creature
    outfit.healthBackground = healthBg;  // Set the healthBackground in the outfit
    g_game.internalCreatureChangeOutfit(const_cast<Creature*>(creature), outfit, true);  // Apply the outfit change
    lua_pushboolean(L, true);  // Return "true" indicating success
    return 1;
}

luascript.H
C++:
// Function declaration for Lua
static int32_t luaDoSetHealthBackgroundOutfit(lua_State* L);

Now I need the same function for TFS 1.3. Can anyone help?
I tried adapting the code for TFS 1.3, but I couldn't get it to work since the code structure is quite different. The interaction with Lua and the outfit-changing functions have undergone significant changes in version 1.3.
Post automatically merged:

For this reason, I'm adding custom health bars that I used in TFS 0.4.


3.webp2.webp25.webp
 
So you are writing client based code, into the server...?

Anything that is being done on the client side like that, should be handled on the client side (at least in terms of hardcoding source code), not on the server side... and in fact, writing all this code on the server side would do absolutely nothing for you if you don't have code written on the client side to handle this stuff... and since you still have to write the client side code, I'm super confused as to what you need the server side code for?
 
O que é exatamente um "histórico de saúde"?

doSetHealthBackgroundOutfit It’s not available in TFS 1.3; it was implemented in TFS 0.4. I need to fix it in TFS 1.3 to make it work again.

LUA:
barras locais = {
    ["1"] = {
        id = 1,
        storage = 23144531,
    },
    ["2"] = {
        id = 2,
        storage = 23144532,
    },
    ["3"] = {
        id = 3,
        storage = 23144533,
    },


}

local storageRunning = 712813

function onSay(cid, words, param)

    local bar = bars[param]

    if param == "" then
        onSendMessage(cid, "white", "Por favor, informe qual barra de vida você deseja usar.")
        return true
    end

    if not bar then
        onSendMessage(cid, "white", "A health bar que você está tentando usar não existe.")
        return true
    end

    local hasBar = getPlayerStorageValue(cid, bar.storage)
    
    if hasBar >= 1 then
        doSetHealthBackgroundOutfit(cid, bar.id)
        -- doSendMagicEffect(getCreaturePosition(cid), 1489)
        setPlayerStorageValue(cid, HASLASTHEALTHBAR, bar.id)
        setPlayerStorageValue(cid, storageRunning, bar.id)
    else
        onSendMessage(cid, "white", "Infelizmente, você não possui essa health bar.")
    end

    return true
end
Post automatically merged:

Então você está escrevendo código baseado no cliente, no servidor...?

Qualquer coisa que esteja sendo feita no lado do cliente dessa forma, deve ser tratada no lado do cliente (pelo menos em termos de codificação do código-fonte), não no lado do servidor... e, de fato, escrever todo esse código no lado do servidor não faria absolutamente nada por você se você não tivesse código escrito no lado do cliente para lidar com essas coisas... e como você ainda tem que escrever o código do lado do cliente, estou super confuso sobre para que você precisa do código do lado do servidor?

I already have the OTC module ready to receive this code, and everything is configured. The only thing left is to implement the doSetHealthBackgroundOutfit, which was implemented in TFS 0.4, but now I need to adapt it to work in TFS 1.3.

1738114035468.webp
 
you function literally only changes a "variable" of the "outfit" and its a number... to make the code compatible will require you to change "outfit" in possibly many places in the source code... it would likely be much easier to just send an extended opcode to handle this for you.
 
you function literally only changes a "variable" of the "outfit" and its a number... to make the code compatible will require you to change "outfit" in possibly many places in the source code... it would likely be much easier to just send an extended opcode to handle this for you.

Sorry for sending everything at once. I'm Brazilian, and it's a bit difficult to translate and understand the translation. This is my code, and I need the doSetHealthBackgroundOutfit mentioned in the post to work again.


talkactions


LUA:
 <talkaction words="/checkbar"  script="checkbar.lua"/>
    <talkaction words="/bar" separator=" " script="bars.lua"/>

checkbar.lua
LUA:
local storagesbar = {
    [231531] = {name = "1"},
    [231532] = {name = "2"},
    [231533] = {name = "3"},
}

local opcode = 20
local opcodedestroy = 21

function onSay(cid, words, param)
    local player = Player(cid)
    player:sendExtendedOpcode(opcodedestroy, "destroy@")

    local hasStorage = false -- Variável para controlar se o jogador tem algum armazenamento

    for indice, storage in pairs(storagesbar) do
        if player:getStorageValue(indice) > 0 then
            if storage.name and storage.name ~= "" then
                player:sendExtendedOpcode(opcode, storage.name.."@".."unlock".."@")
                hasStorage = true -- O jogador possui pelo menos um armazenamento
            end
        end
    end

    if not hasStorage then
        player:sendExtendedOpcode(opcode, json.encode({action = "msg", data = {type = "error", msg = "Você não possui nenhuma health bar disponível."}}))
    end

    return true
end

bars.lua

LUA:
local bars = {
    ["1"] = {
        id = 1,
        storage = 23144531,
    },
    ["2"] = {
        id = 2,
        storage = 23144532,
    },
    ["3"] = {
        id = 3,
        storage = 23144533,
    },


}

local storageRunning = 712813

function onSay(cid, words, param)

    local bar = bars[param]

    if param == "" then
        onSendMessage(cid, "white", "Por favor, informe qual barra de vida você deseja usar.")
        return true
    end

    if not bar then
        onSendMessage(cid, "white", "A health bar que você está tentando usar não existe.")
        return true
    end

    local hasBar = getPlayerStorageValue(cid, bar.storage)
  
    if hasBar >= 1 then
        doSetHealthBackgroundOutfit(cid, bar.id)
        -- doSendMagicEffect(getCreaturePosition(cid), 1489)
        setPlayerStorageValue(cid, HASLASTHEALTHBAR, bar.id)
        setPlayerStorageValue(cid, storageRunning, bar.id)
    else
        onSendMessage(cid, "white", "Infelizmente, você não possui essa health bar.")
    end

    return true
end

OTCV8 Module:
 
Last edited:
Bro, its not a translation problem. You are trying to just send code and hope someone converts it for you...

I'm trying to tell you its not as simple as just converting the code. The "outfit" struct/class does not contain the field member "healthBackground" in TFS 1.0+, which means you need to alter the data structure, which potentially means making changes in many places its used...

It would likely be much easier to just use the extended op codes.
 
Bro, its not a translation problem. You are trying to just send code and hope someone converts it for you...

I'm trying to tell you its not as simple as just converting the code. The "outfit" struct/class does not contain the field member "healthBackground" in TFS 1.0+, which means you need to alter the data structure, which potentially means making changes in many places its used...

It would likely be much easier to just use the extended op codes.
Thank you very much for your response! I will be waiting for further guidance and I really appreciate your help. Your assistance has been very valuable to me. Thank you again!
 
Thank you very much for your response! I will be waiting for further guidance and I really appreciate your help. Your assistance has been very valuable to me. Thank you again!

Start here

Ensure to add it to the SendOutfit for the protocol things

And receive it in the same place on the client
 
Back
Top