Disclaimer. This is made by the help of AI. I dont have the necessary tokens to continue today but I would share this since its basically work. The problem is
1. There is no character animation at the moment. As soon as the target within the search, it automatically attack the target.
2. Still buggy if you change the search range after the autobattle is on. So, please set it up before activating it.
3. No buff auto skill. only damage skill.
The system allows your character to automatically:
The system excludes:
The following files are modified:
Follow the original GameServer installation instructions for the exact code blocks and insertion locations.
cpp
Add the Auto Battle function declarations inside the CCharacter class:
cpp
Add the Auto Battle state variables inside CCharacter:
cpp
Do not replace the existing declarations or variables.
cpp
Insert:
cpp
Inside
cpp
Inside
cpp
Insert the command handler after the existing
cpp
This allows the server to recognise Auto Battle commands sent through chat.
cpp
Check the timing array capacity in your source before adding another timing entry.
The implementation contains:
The Client must be modified because the
Without this modification, typing:
text
may be interpreted as a party chat message instead of being sent to the GameServer as an Auto Battle command.
We will modify the chat sending function so that only valid Auto Battle commands are intercepted.
Other messages beginning with
Navigate to:
text
Open
text
Search for:
cpp
You should find the function responsible for processing and sending messages typed into the chat input box.
Do not modify another chat function.
cpp
This is the insertion point for the Client modification.
Important: Insert the new code immediately BEFORE this line.
Do not delete the existing
Your code should be structured like this:
cpp
The exact surrounding code may differ depending on your source version.
cpp
cpp
Do not place the Auto Battle block:
The new code checks whether the message begins with the exact
Examples:
The code also restores the previously selected chat channel after sending an Auto Battle command.
For example, if the player was using party chat, the chat input should return to party mode after sending
The shortcut index starts at zero:
This means Auto Battle stops after 30 seconds of unresolved SP exhaustion.
Target priority:
It skips empty slots, inactive skills, passive skills, helpful skills, skills on cooldown and invalid skill records.
After submitting a skill, it advances to the next shortcut slot.
This prevents overlapping skill submissions.
If SP remains exhausted and the consumable cannot resolve the issue for 30 seconds, Auto Battle stops automatically.
The code is based on a particular source structure. Other source versions may require adjustments to function names, member declarations or chat handling.
The implementation should be tested on a development server before being deployed to a live server.
Always back up your original files before modifying them.
Credits: Auto Battle system implementation and source integration.
Hope this helps other developers who want to add an Auto Battle feature to their own server projects!
1. There is no character animation at the moment. As soon as the target within the search, it automatically attack the target.
2. Still buggy if you change the search range after the autobattle is on. So, please set it up before activating it.
3. No buff auto skill. only damage skill.
[Guide] Auto Battle System – Complete Installation & Configuration Guide
1. Introduction
This guide explains how to implement an Auto Battle system into your game source code.The system allows your character to automatically:
- Search for nearby land monsters.
- Prioritise monsters already within skill range.
- Move towards monsters outside skill range before attacking.
- Automatically use offensive skills assigned to the shortcut bar.
- Rotate through available offensive skills.
- Use an SP consumable from a designated shortcut slot.
- Stop Auto Battle if SP remains exhausted for the configured duration.
Supported targets
Only ordinary land monsters are supported.The system excludes:
- Sea monsters and boat monsters.
- NPCs and event NPCs.
- Player pets.
- Trees and mines.
- Fish and other non-standard monster types.
2. Requirements
Before starting, prepare:- GameServer source code.
- Client source code.
- Visual Studio or the appropriate compiler.
- A backup of your original source files.
3. GameServer modifications
The Auto Battle functionality is primarily handled by the GameServer.The following files are modified:
| File | Purpose |
|---|---|
| Character.h | Auto Battle definitions, declarations and variables |
| Character.cpp | Initialization, reset and death handling |
| CharacterPrl.cpp | Receives Auto Battle chat commands |
| CharacterRun.cpp | Runs the Auto Battle update timer |
| CharacterCmd.cpp | Targeting, skill rotation, item usage and Auto Battle logic |
Step 1 – Character.h
Add the configuration definitions:cpp
Code:
#define defAUTOBATTLE_TICK 250
#define defAUTOBATTLE_DEFAULT_RANGE 800
#define defAUTOBATTLE_MIN_RANGE 100
#define defAUTOBATTLE_MAX_RANGE 3000
#define defAUTOBATTLE_SP_SLOT 1
#define defAUTOBATTLE_SP_TIMEOUT (30 * 1000)
#define defAUTOBATTLE_CAST_TIMEOUT 10000
#define defAUTOBATTLE_POTION_INTERVAL 1000
cpp
Code:
bool HandleAutoBattleCommand(dbc::cChar *pszCmd, dbc::uLong ulLen);
void SetAutoBattle(bool bEnable, dbc::uLong ulRange = 0);
bool IsAutoBattle(void) const;
void OnAutoBattle(DWORD dwCurTime);
void AutoBattleReset(void);
void AutoBattleStop(const char *szReason);
bool AutoBattleFindTarget(CSkillRecord *pSkill, CCharacter **ppTar);
bool AutoBattleTryCast(bool &bSpBlocked);
bool AutoBattleTryUseSpItem(void);
void AutoBattleGetTargetName(char *szBuf, int nLen);
cpp
Code:
bool m_bAutoBattle;
bool m_bAutoBattleCastPending;
DWORD m_dwAutoBattleRange;
CTimer m_timerAutoBattle;
int m_nAutoBattleNextSlot;
DWORD m_dwAutoBattleShortcutHash;
dbc::uLong m_ulAutoBattleTarID;
dbc::Long m_lAutoBattleTarHandle;
DWORD m_dwAutoBattleCastTick;
DWORD m_dwAutoBattleSpLowTick;
DWORD m_dwAutoBattlePotionTick;
Step 2 – Character.cpp
Initialize the Auto Battle variables after:cpp
Code:
m_timerScripts.Begin(defCHA_SCRIPT_TIMER);
cpp
Code:
m_bAutoBattle = false;
m_bAutoBattleCastPending = false;
m_dwAutoBattleRange = defAUTOBATTLE_DEFAULT_RANGE;
m_nAutoBattleNextSlot = 0;
m_dwAutoBattleShortcutHash = 0;
m_ulAutoBattleTarID = 0;
m_lAutoBattleTarHandle = 0;
m_dwAutoBattleCastTick = 0;
m_dwAutoBattleSpLowTick = 0;
m_dwAutoBattlePotionTick = 0;
m_timerAutoBattle.Begin(defAUTOBATTLE_TICK);
Finally(), add:cpp
Code:
AutoBattleReset();
Die(), immediately after BreakAction(), add:cpp
Code:
if (m_bAutoBattle)
AutoBattleStop("character died");
Step 3 – CharacterPrl.cpp
Add the Auto Battle command interception inside the existing chat-processing section.Insert the command handler after the existing
$$ branch:cpp
Code:
else if (*l_content == '!' &&
HandleAutoBattleCommand(l_content + 1, l_retlen - 1))
{
break;
}
Step 4 – CharacterRun.cpp
Add the Auto Battle update timer inside the character update routine, after the existing OnFight timing block:cpp
Code:
t.Begin();
if (bIsLiveing && m_bAutoBattle)
{
if (m_timerAutoBattle.IsOK(dwCurTime))
OnAutoBattle(dwCurTime);
}
m_dwCellRunTime[chCount++] = t.End();
Step 5 – CharacterCmd.cpp
Append the complete Auto Battle implementation after the final existing function definition.The implementation contains:
- HandleAutoBattleCommand()
- SetAutoBattle()
- AutoBattleReset()
- AutoBattleStop()
- AutoBattleFindTarget()
- AutoBattleTryUseSpItem()
- AutoBattleTryCast()
- OnAutoBattle()
- AutoBattleGetTargetName()
4. Client modifications – Detailed instructions
This section is particularly important.The Client must be modified because the
! character is already used by the original client to select party chat.Without this modification, typing:
text
Code:
!autobattle on
We will modify the chat sending function so that only valid Auto Battle commands are intercepted.
Other messages beginning with
! will continue to use the original party chat behaviour.Step 1 – Locate the client source file
Open your Client source folder.Navigate to:
text
Code:
sources\Client\src\UICozeForm.cpp
UICozeForm.cpp in Visual Studio.Step 2 – Find the SendMsg() function
Press:text
Code:
Ctrl + F
cpp
Code:
void CCozeForm::SendMsg()
Do not modify another chat function.
Step 3 – Locate the insertion point
InsideCCozeForm::SendMsg(), find this existing line:cpp
Code:
string strCurCmd="";
Important: Insert the new code immediately BEFORE this line.
Do not delete the existing
string strCurCmd="" line.Your code should be structured like this:
cpp
Code:
void CCozeForm::SendMsg()
{
// Existing code above remains unchanged.
// INSERT AUTO BATTLE CLIENT CODE HERE
string strCurCmd="";
// Existing code below remains unchanged.
}
Step 4 – Insert the Auto Battle Client code
Copy the entire block below and paste it immediately beforestring strCurCmd="";.cpp
Code:
// ============================================================
// Auto Battle Client Command Interception
// ============================================================
// Only intercept the exact !autobattle command.
// Other ! messages will continue through normal party chat.
static const char szAutoBattleCmd[] = "!autobattle";
bool bAutoBattleHead = (strMsg.length() >= 11);
for (int i = 0; bAutoBattleHead && i < 11; ++i)
{
char c = strMsg[i];
if (c >= 'A' && c <= 'Z')
c = char(c - 'A' + 'a');
if (c != szAutoBattleCmd[i])
bAutoBattleHead = false;
}
if (bAutoBattleHead &&
(strMsg.length() == 11 || strMsg[11] == ' '))
{
string strArg = (strMsg.length() > 11)
? strMsg.substr(12)
: "";
// Remove leading spaces.
while (!strArg.empty() && strArg[0] == ' ')
strArg.erase(0, 1);
// Remove trailing spaces.
while (!strArg.empty() &&
strArg[strArg.size() - 1] == ' ')
{
strArg.erase(strArg.size() - 1);
}
// Convert arguments to lowercase.
for (size_t i = 0; i < strArg.size(); ++i)
{
if (strArg[i] >= 'A' && strArg[i] <= 'Z')
strArg[i] = char(strArg[i] - 'A' + 'a');
}
// Check valid Auto Battle arguments.
bool bValidArg =
strArg.empty() ||
strArg == "on" ||
strArg == "off" ||
strArg == "status" ||
strArg == "target" ||
strArg == "help" ||
strArg == "range";
// Allow range followed by a numeric value.
if (!bValidArg && strArg.compare(0, 6, "range ") == 0)
{
const char *pNum = strArg.c_str() + 6;
while (*pNum == ' ')
++pNum;
bValidArg = (*pNum >= '0' && *pNum <= '9');
}
if (bValidArg)
{
// Add command to the local chat history.
m_cSendMsgCard.AddCard(strMsg);
// Send as normal server chat instead of party chat.
m_bSendMsgCardSwitch = false;
CS_Say(strMsg.c_str());
// Restore the previously selected chat channel.
m_edtMsg->SetCaption(
CCharMsg::GetChannelCommand(
CCharMsg::GetChannelIndex(m_eCurSelChannel)).c_str());
return;
}
}
// ============================================================
// End Auto Battle Client Command Interception
// ============================================================
Step 5 – Verify the code placement
After inserting the block, your function should look structurally similar to this:cpp
Code:
void CCozeForm::SendMsg()
{
// Original source code.
// Auto Battle interception code.
// The complete block from Step 4 goes here.
// Original source code continues.
string strCurCmd="";
// Remaining original SendMsg() implementation.
}
- Outside
SendMsg(). - Inside another function.
- After the function's closing brace.
- In the GameServer source folder.
CCozeForm::SendMsg() and before string strCurCmd="";.Step 6 – Why this modification is necessary
The original Client uses! as a party chat prefix.The new code checks whether the message begins with the exact
!autobattle command token.Examples:
| Message | Client behaviour |
|---|---|
!autobattle on | Sent as Auto Battle command |
!autobattle off | Sent as Auto Battle command |
!autobattle status | Sent as Auto Battle command |
!autobattle range 1500 | Sent as Auto Battle command |
!hello | Normal party chat |
!autobattlefoo | Normal party chat |
!autobattle is fun | Normal party chat |
!autobattle range abc | Normal party chat |
For example, if the player was using party chat, the chat input should return to party mode after sending
!autobattle on.Step 7 – Compile the Client
After inserting the code:- Save
UICozeForm.cpp. - Open your Client project in Visual Studio.
- Build the Client project.
- Check for compiler errors.
- If successful, update your test Client executable using your normal deployment process.
5. Auto Battle configuration
The main settings are located inCharacter.h.| Setting | Default | Description |
|---|---|---|
| Update interval | 250 ms | Auto Battle checking interval |
| Default search range | 800 | Initial monster search range |
| Minimum range | 100 | Minimum configurable range |
| Maximum range | 3000 | Maximum configurable range |
| SP consumable slot | 2 | Second shortcut slot |
| SP exhaustion timeout | 30 seconds | Stops Auto Battle after prolonged SP exhaustion |
| Skill queue timeout | 10 seconds | Safety timeout |
| Potion interval | 1 second | Minimum interval between potion attempts |
SP consumable slot
cpp
Code:
#define defAUTOBATTLE_SP_SLOT 1
- Index 0 = Slot 1
- Index 1 = Slot 2
- Index 2 = Slot 3
SP exhaustion timeout
cpp
Code:
#define defAUTOBATTLE_SP_TIMEOUT (30 * 1000)
6. In-game commands
Once both projects have been compiled and deployed, use the following commands:| Command | Description |
|---|---|
!autobattle on | Enable Auto Battle |
!autobattle off | Disable Auto Battle |
!autobattle status | Display Auto Battle status |
!autobattle target | Display current target |
!autobattle help | Display available commands |
!autobattle range 800 | Set search range to 800 |
Example: Increase search range
text
Code:
!autobattle range 1500
Example: Start Auto Battle
text
Code:
!autobattle on
Example: Stop Auto Battle
text
Code:
!autobattle off
7. How the Auto Battle system works
Monster targeting
The system searches for eligible monsters within the configured search range.Target priority:
- Nearest monster already within the selected skill's range.
- If no suitable monster is in skill range, nearest eligible monster within search range.
Skill rotation
The system checks offensive skills assigned to the shortcut bar.It skips empty slots, inactive skills, passive skills, helpful skills, skills on cooldown and invalid skill records.
After submitting a skill, it advances to the next shortcut slot.
Action queue protection
The system waits for the previous MOVE + SKILL action to finish before submitting another skill.This prevents overlapping skill submissions.
SP consumable
When SP is insufficient, the system attempts to use the consumable in shortcut slot 2.If SP remains exhausted and the consumable cannot resolve the issue for 30 seconds, Auto Battle stops automatically.
8. Testing checklist
GameServer
- GameServer compiles successfully.
!autobattle helpworks.!autobattle onenables Auto Battle.!autobattle offdisables Auto Battle.- Search range can be changed.
- Only ordinary land monsters are targeted.
- Character moves into skill range before attacking.
- Skill rotation works.
- Action queue protection works.
- SP consumable works from shortcut slot 2.
- Auto Battle stops after 30 seconds of unresolved SP exhaustion.
Client
- Client compiles successfully.
!autobattle onreaches the GameServer.!autobattle offreaches the GameServer.!autobattle statusworks.!autobattle range 1500works.!hellostill works in party chat.!autobattlefoostill works as normal party chat.- Chat channel returns to its previous selection after a command.
- No chat input or channel switching issues occur.
9. Important notes
This is a source-code modification, not a standalone plugin.The code is based on a particular source structure. Other source versions may require adjustments to function names, member declarations or chat handling.
The implementation should be tested on a development server before being deployed to a live server.
Always back up your original files before modifying them.
Credits: Auto Battle system implementation and source integration.
Hope this helps other developers who want to add an Auto Battle feature to their own server projects!