Purpose

An NPC gives gifts based on the total amount topped up. Each time the player talks to it, if the account has topped up enough, the player receives the next gift tier; the items are sent to the Gremory Case (K key). For example: tier 1 requires 20000, tier 2 requires 500000, tier 3 requires 1000000... After the tiers in the list, the required amount doubles at each tier up to MaxLevel (and the items of the last tier in the list are received).

The total top-up and the most recently claimed tier are read from your top-up table (by default acc_recharge with the columns AccountId, TotalAmount, ClaimedLevel, ClaimedDate).

How to enable

  1. Make sure the top-up table exists (acc_recharge is in the standard game DB) or edit the table / column names in Database of Config.lua.
  2. Remove the -- in front of LoadModule("RechargeGift\\RechargeGift") in Main.lua.
  3. Check the NPC position and the DB columns in Includes\RechargeGift\Config.lua.
  4. Click Reload LuaAPI.

The module attaches OnReadScript (creates the NPC), OnNpcTalk, OnSQLAsyncResult. The NPC is created only if its map runs on this GameServer; the NPC is removed when LuaAPI is reloaded and created again (no duplicates). This module was previously named NpcAddOption.

Configuration (Config.lua, RechargeGiftConfig table)

KeyMeaning
EnableTurns the module on / off.
NpcNPC created by the module: Class (Data\Monster\MonsterList.xml), Map, X, Y, Dir.
DatabaseTable and column names: Table, Account (account ID column, numeric), Total (total topped up), Claimed (most recently claimed gift tier), ClaimedTime (column recording the claim time, "" = not used).
LevelsThe gift tiers in order: Name, Money (required total top-up), Items (each entry: Item = { group, index }, Level, Count, Duration in seconds, 0 = 7 days).
MaxLevelThe last gift tier.
StorageGremory Case: 1 = the character's, 2 = the account's.
TextThe notice messages.
Talking to the NPC several times in a row sends only one DB query (protection against repeated clicking). The gift tier is written to the DB before the items are granted; if the Gremory Case is full, nothing is written and nothing is granted.
Levels = {
	{ Name = "First Recharge Gift", Money = 20000,
	  Items = { { Item = { 12, 15 }, Count = 1, Duration = 604800 } } },
},
MaxLevel = 22,
Storage = 1,