Skip to content

🐛 SQL Syntax Error, Data Synchronization, and Script Scoping in Chocobo Raising System #9239

@eyes-and-brain

Description

@eyes-and-brain

I affirm:

  • I understand that if I do not agree to the following points by completing the checkboxes my issue will be ignored.
  • I have read and understood the Contributing Guide and the Code of Conduct.
  • I have searched existing issues to see if the issue has already been opened, and I have checked the commit log to see if the issue has been resolved since my server was last updated.

OS / platform the server is running (if known)

Windows11

Branch affected by issue

base

I found several issues that prevent the !chocoboraising command and the egg trade event from functioning correctly. While I understand that the Chocobo Raising system is a work-in-progress, I am proposing these fixes to move the system closer to a stable state.

Changes and Diff Quotes:

  1. Core (C++): src/map/lua/lua_baseentity.cpp
    Removed LIMIT 1 from the REPLACE INTO statement. MariaDB does not support LIMIT in this context, which caused all saving attempts to fail.
// --- src/map/lua/lua_baseentity.cpp ---
// OLD:
"personality = ?, weather_preference = ?, hunger = ?, care_plan = ?, held_item = ? LIMIT 1",
// NEW:
"personality = ?, weather_preference = ?, hunger = ?, care_plan = ?, held_item = ?",
  1. Global Logic (Lua): scripts/globals/chocobo_raising.lua
    Added a fallback for chocobo creation and logic to immediately refresh the memory (chocoState) from the database after saving.
-- --- scripts/globals/chocobo_raising.lua ---
-- OLD:
local newChoco = xi.chocoboRaising.newChocobo(player, egg)
if player:setChocoboRaisingInfo(newChoco) then
    player:confirmTrade()
end

-- NEW:
local newChoco = xi.chocoboRaising.newChocobo(player, egg)
if not newChoco then
    newChoco = { first_name = "Chocobo", last_name = "Chocobo", created = os.time(), stage = 1 }
end
if player:setChocoboRaisingInfo(newChoco) then
    local charID = player:getID()
    xi.chocoboRaising.chocoState[charID] = player:getChocoboRaisingInfo()
    player:confirmTrade()
end
  1. Command (Lua): scripts/commands/chocoboraising.lua
    Corrected variable scoping (playerArg).
-- --- scripts/commands/chocoboraising.lua ---
-- OLD:
permission = 1,
-- ...
player:setChocoboRaisingInfo(newChoco)

-- NEW:
permission = 0,
-- ...
playerArg:setChocoboRaisingInfo(newChoco)

  1. Database (SQL): sql/char_chocobos.sql
    Standardized schema for MariaDB compatibility.
-- --- sql/char_chocobos.sql ---
-- OLD: `sex` boolean NOT NULL,
-- NEW: `sex` tinyint(1) NOT NULL,

Known Issue (Future Investigation):
I am aware of an issue where NPCs refuse to retire a chocobo, claiming it has "no name," even though the database has them registered as "Chocobo Chocobo". I plan to investigate this at a later time, but any support from the community is welcome.

Error Logs observed before fix:

[map][error] Query Failed: REPLACE INTO char_chocobos SET ... LIMIT 1
[map][error] (conn=81) You have an error in your SQL syntax; ... near 'LIMIT 1' at line 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions