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

How fix the this Key number TFS 1.2

gubbo123

New Member
Joined
Aug 15, 2017
Messages
151
Solutions
1
Reaction score
3
Hello, i have a problem with key number look msg, I have this script here, to respawn a key on map...
Lua:
function onStartup()
local chance = math.random(1, 100)
if chance <= 50 then
Game.createItem(2969, 0021, Position(2832, 12384, 10))
    end
end

the problem is the number of key... the correct is 0021, but now appear only 21.
1.png

is there any way to tidy up? insert the 00 before. :/
 
item.cpp
Replace:
C++:
            if (it.isKey()) {
                s << " (Key:" << (item ? item->getActionId() : 0) << ')';
With:
C++:
            if (it.isKey()) {
                std::string aid = std::to_string(item ? item->getActionId() : 0);
                if (aid.size() < 4) {
                    aid.insert(0, 4 - aid.size(), '0');
                }
                s << " (Key:" << aid << ')';
 
Last edited:
item.cpp
Replace:
C++:
            if (it.isKey()) {
                s << " (Key:" << (item ? item->getActionId() : 0) << ')';
With:
C++:
            if (it.isKey()) {
                std::string aid = std::to_string(item ? item->getActionId() : 0);
                if (aid.size() < 4) {
                    aid.insert(0, 4 - aid.size(), '0');
                }
                s << " (Key:" << aid << ')';
You don't need that much code simply changing:
C++:
s << " (Key:" << (item ? item->getActionId() : 0) << ')';
to:
C++:
s << " (Key:" << std::setfill('0') << std::setw(4) << (item ? item->getActionId() : 0) << ')';
is enough.
 
Back
Top