• 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++ SetCapacity directly in source tfs 1.3

Engradiel

Member
Joined
May 3, 2009
Messages
120
Reaction score
7
Location
Brazil
This a code to do a item that set cap of player.
but I don't know How to use the function to set player capacity...
Someone can help me?


C++:
int32_t storage;
            player->getStorageValue(71234, storage);
                       
            std::cout << "Storage: " << storage << "\n";
           
            if (equip && storage != 1) {
                    std::cout << "added storage";
                    player->addStorageValue(71234, 1);
            }
            else {
                if (storage == 1) {
                    std::cout << "removed storage";
                    player->addStorageValue(71234, -1);
                }
            }


in luascript.cpp has this:
C++:
int LuaScriptInterface::luaPlayerSetCapacity(lua_State* L)
{
    // player:setCapacity(capacity)
    Player* player = getUserdata<Player>(L, 1);
    if (player) {
        player->capacity = getNumber<uint32_t>(L, 2);
        player->sendStats();
        pushBoolean(L, true);
    } else {
        lua_pushnil(L);
    }
    return 1;
}
 
Solution
This a code to do a item that set cap of player.
but I don't know How to use the function to set player capacity...
Someone can help me?


C++:
int32_t storage;
            player->getStorageValue(71234, storage);
                  
            std::cout << "Storage: " << storage << "\n";
      
            if (equip && storage != 1) {
                    std::cout << "added storage";
                    player->addStorageValue(71234, 1);
            }
            else {
                if (storage == 1) {
                    std::cout << "removed storage";
                    player->addStorageValue(71234, -1);
                }
            }


in luascript.cpp has this:
C++:
int LuaScriptInterface::luaPlayerSetCapacity(lua_State*...
This a code to do a item that set cap of player.
but I don't know How to use the function to set player capacity...
Someone can help me?


C++:
int32_t storage;
            player->getStorageValue(71234, storage);
                  
            std::cout << "Storage: " << storage << "\n";
      
            if (equip && storage != 1) {
                    std::cout << "added storage";
                    player->addStorageValue(71234, 1);
            }
            else {
                if (storage == 1) {
                    std::cout << "removed storage";
                    player->addStorageValue(71234, -1);
                }
            }


in luascript.cpp has this:
C++:
int LuaScriptInterface::luaPlayerSetCapacity(lua_State* L)
{
    // player:setCapacity(capacity)
    Player* player = getUserdata<Player>(L, 1);
    if (player) {
        player->capacity = getNumber<uint32_t>(L, 2);
        player->sendStats();
        pushBoolean(L, true);
    } else {
        lua_pushnil(L);
    }
    return 1;
}
You would go with something like this
C++:
const int32_t additionalCapacity = 100; // Replace 100 with the value you want

int32_t storage;
player->getStorageValue(71234, storage);
std::cout << "Storage: " << storage << "\n";

if (equip && storage != 1) {
    std::cout << "added storage";
    player->addStorageValue(71234, 1);
    player->setCapacity(player->getCapacity() + additionalCapacity); // Increase capacity by 100
}
else if (storage == 1) {
    std::cout << "removed storage";
    player->addStorageValue(71234, -1);
    player->setCapacity(player->getCapacity() - additionalCapacity); // Decrease capacity by 100
}
If your sources lack the setCapacity method, you can add it directly in your Player class.
Define the function in your player.h:
C++:
void setCapacity(int32_t newCapacity);
And implement it in player.cpp:
C++:
void Player::setCapacity(int32_t newCapacity) {
    this->capacity = newCapacity;
}
 
Last edited:
Solution
Back
Top