Introduction to rAthena Scripting
Ever wondered how those custom NPCs, quests, and unique events come to life in rAthena? Well, it all boils down to the powerful rAthena scripting language! Think of it as your comprehensive toolkit, packed with commands and functions designed to bring your server ideas to reality. Now, this isn't your typical 'learn to code from scratch' tutorial. Instead, it's a detailed reference manual, perfect for anyone who already has a good grasp of programming basics and is eager to explore the specific tools rAthena offers. If you've got a vision for your server, this documentation is your go-to resource for understanding how to make it happen. Trust me, a solid foundation in general programming will make navigating this manual a breeze! ✨
What is RID and GID?
In rAthena scripting, RID and GID are important identifiers used to refer to game entities.
RID stands for Requesting ID which also refering to the player. It is the unique account identification number of a character that triggers a script's execution. When a script is invoked by a character (e.g., by clicking an NPC, walking into an OnTouch zone, or using an item), the RID of that character is automatically attached to the running script.
- Most scripting commands and functions that interact with a specific character (like storing variables, sending messages to the client, or modifying character data) require an RID.
- Scripts triggered without a specific character (e.g., floating scripts, timers, or clock-based activations) will not have an RID attached. In such cases, commands like attachrid can be used to explicitly associate a character with the script, or playerattached can be used to check if a player is currently linked.
GID stands for Game ID. This is a unique identifier for various game objects, including monsters, NPCs, or even a character's account ID. It's primarily used for mob control commands and newer skill implementations.
- For monsters, the GID is obtained when the monster is spawned (e.g., via mobspawn).
- For characters, the GID can also refer to their account ID.
- You can view the GID of a mob, NPC, or character by right-clicking them as a GM-sprited character.
- Commands like getpetinfo, getmercinfo, gethominfo, and geteleminfo can retrieve GIDs for specific entity types.
📚 Setting Up the Script to Run
To make the NPC work in your rAthena server permanently
, you need to save the script and configure the server to load it. Follow these steps:
-
Creating mytestnpc.txt Script:
Example Code:
// Simple mytestnpc NPC for rAthena prontera,150,150,4 script mytestnpc 99,{ mes "[mytestnpc]"; mes "Hello, adventurer! I hope you enjoy this game!"; close; }
-
Save the Script:
- Lets say you created a new text file named
mytestnpc.txt
. - Save the file in the
npc/custom/
folder of your rAthena Emulator directory (e.g.,npc/custom/mytestnpc.txt
). If thecustom
folder doesn’t exist, create it..
- Lets say you created a new text file named
-
Declare it in the Configuration File:
- Open the
npc/scripts_custom.conf
file in your rAthena emulator directory (located atnpc/scripts_custom.conf
). - After opening, add the following line to include your mytestnpc script:
- Upon including your mytestnpc script. Save the
scripts_custom.conf
file.
Example Code:// -------------------------------------------------------------- // - Custom Scripts - // -------------------------------------------------------------- // All the custom scripts, remove the '//' to enable... // Place your scripts here! //npc: npc/location/to/script.txt npc: npc/custom/mytestnpc.txt
- Open the
I wanted to test the script once only.
To test your created mytestnpc.txt
once, you need to use @loadnpc <pathfile_of_script>
and @reloadnpcfile <pathfile_of_script>
command via in-game. Follow these steps:
- Lets assume you are already in-game.
- To load the NPC without restarting the server, use
@loadnpc <pathfile_of_script>
in-game. Just make sure you are in GM Account - If you revise your
mytestnpc.txt
, you can use@reloadnpcfile <pathfile_of_script>
in-game to apply the changes in your script. - If you wanted to remove the loaded npc. use
@unloadnpcfile <pathfile_of_script>
to dynamically remove temporary event NPCs or scripts that are no longer needed to free up server resources. -
Key Difference Summary 🔑
@loadnpc <pathfile_of_script>
: For new script files or files that were explicitlyunloaded
.@reloadnpcfile <pathfile_of_script>
: For existing script files that have beenmodified
.@unloadnpcfile <pathfile_of_script>
: Remove temporary event NPCs or scripts that are no longer needed to free up server resources.