Skip to content

fix(config): let rateLoot accept decimal values - #877

Open
msholl wants to merge 1 commit into
zimbadev:mainfrom
msholl:fix-rateloot-decimals
Open

fix(config): let rateLoot accept decimal values#877
msholl wants to merge 1 commit into
zimbadev:mainfrom
msholl:fix-rateloot-decimals

Conversation

@msholl

@msholl msholl commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

rateLoot is loaded with loadIntConfig, which does static_cast<int32_t> and silently drops the fractional part — rateLoot = 2.5 becomes 2, with no warning and nothing in config.lua suggesting the field is integer-only.

Switching it to loadFloatConfig forces every reader to be updated, because getNumber() on a value stored as a float takes the wrong type branch: it returns 0 and logs a warning (configmanager.cpp:529-533). The readers are:

file why it matters
src/creatures/monsters/monster.cpp the > 0 gate that decides whether loot is generated at all
src/server/network/protocol/protocolstatus.cpp easy to miss — the server kept announcing loot="0" while looting itself worked fine
data/libs/functions/functions.lua getLootRandom(), the actual multiplier
data/libs/functions/monster.lua, monstertype.lua the same <= 0 gate on the Lua side
data/scripts/talkactions/player/server_info.lua what !serverinfo shows the player

protocolstatus.cpp uses fmt::format("{:g}", ...) so the value comes out as 2.5 rather than 2.500000.

Testing

Running on a live server (Crystal 15.25). With rateLoot = 2.5 the status protocol reports loot="2.5" and fractional rates apply to drops; with rateLoot = 3 behaviour is unchanged from before. The warning in the log was what exposed the missed protocolstatus.cpp reader in the first place.

Note for LuaJIT (5.1 semantics, as used here): a non-integer float passed where an integer is expected truncates. On Lua 5.3+ lua_tointeger would return 0 instead — another reason the readers must match the stored type.

rateLoot was loaded with loadIntConfig, which static_casts to int32_t and
silently drops the fractional part: "rateLoot = 2.5" became 2, with nothing in
config.lua suggesting the field is integer-only.

Switching to loadFloatConfig requires fixing every reader, because getNumber()
on a value stored as float takes the wrong type branch, returns 0 and logs a
warning (configmanager.cpp). Besides the single C++ use in monster.cpp, those
are the four Lua readers and protocolstatus.cpp -- the last one is easy to miss
and made the status protocol announce loot="0" while looting itself worked.

Verified in a live server: loot="2.5" is now reported correctly by the status
protocol and fractional rates apply to drops.
@jprzimba

jprzimba commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Please remove the unnecessary comment in configmanager.cpp, and thank you for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants