diff options
-rw-r--r-- | db/pre-re/item_db.conf | 2 | ||||
-rw-r--r-- | npc/functions/clear_vars.txt | 17 | ||||
-rw-r--r-- | npc/functions/global_event_handler.txt | 1 | ||||
-rw-r--r-- | npc/functions/main.txt | 123 |
4 files changed, 142 insertions, 1 deletions
diff --git a/db/pre-re/item_db.conf b/db/pre-re/item_db.conf index ef1bfdfa..eeb7a57a 100644 --- a/db/pre-re/item_db.conf +++ b/db/pre-re/item_db.conf @@ -1457,7 +1457,7 @@ item_db: ( "> }, { - Id: 5270 + Id: 5272 AegisName: "ManaPearl" Name: "Mana Pearl" Type: "IT_ARMOR" diff --git a/npc/functions/clear_vars.txt b/npc/functions/clear_vars.txt index be895576..063feaec 100644 --- a/npc/functions/clear_vars.txt +++ b/npc/functions/clear_vars.txt @@ -142,3 +142,20 @@ function script ClearVariables { } +function script ServerUpdate { + if ($@STARTUP) { + debugmes "Cowardly refusing to update server outside startup"; + return; + } + + // Correct Mana Pearl ID + // qui jul 29 11:21:38 BRT 2021 + if ($VERSION < 1627568498) { + ReplaceItemFromEveryPlayer(5270, 5272); + $VERSION = 1627568498; + } + + $@STARTUP = true; + return; +} + diff --git a/npc/functions/global_event_handler.txt b/npc/functions/global_event_handler.txt index 8a9c4fd6..b63fb28f 100644 --- a/npc/functions/global_event_handler.txt +++ b/npc/functions/global_event_handler.txt @@ -45,6 +45,7 @@ OnClock1701: end; OnInit: + ServerUpdate(); // Update server if needed MOTD(); // set the MOTD array end; diff --git a/npc/functions/main.txt b/npc/functions/main.txt index abdaa5dd..6a19e3a7 100644 --- a/npc/functions/main.txt +++ b/npc/functions/main.txt @@ -790,3 +790,126 @@ function script spawndummy { return .@u; } +///////////////////////////////////////////////////////////////////////////////// +// Do not run this outside startup +// Delete item ID on inventories, storages, guild storages and carts. Also affects mails. +// WARNING, irreversible and dangerous! +// DelItemFromEveryPlayer( ID ) +function script DelItemFromEveryPlayer { + if (getarg(0, -1) < 0) + return; + + query_sql("DELETE FROM `inventory` WHERE `nameid`="+getarg(0)); + query_sql("DELETE FROM `cart_inventory` WHERE `nameid`="+getarg(0)); + query_sql("DELETE FROM `storage` WHERE `nameid`="+getarg(0)); + query_sql("DELETE FROM `guild_storage` WHERE `nameid`="+getarg(0)); + query_sql("DELETE FROM `rodex_items` WHERE `nameid`="+getarg(0)); + query_sql("DELETE FROM `auction` WHERE `nameid`="+getarg(0)); + debugmes "Deleting item %d", getarg(0); + + // Del items which SQL can't reach + .@c = getunits(BL_PC, .@players, MAX_CYCLE_PC); + for (.@i = 0; .@i < .@c; .@i++) { + .@am=countitem(getarg(0), .@players[.@i]); + if (.@am) debugmes "DELETE %d items from ACC %d", .@am, .@players[.@i]; + if (.@am) + delitem(getarg(0), .@am, .@players[.@i]); + } + return; +} + +// Delete an acc_reg entry from all players. Full arrays only. Affect num and str db. +// WARNING, irreversible and dangerous! +// DelAccRegFromEveryPlayer( KEY ) +function script DelAccRegFromEveryPlayer { + if (getarg(0, "error") == "error") + return; + + query_sql("DELETE FROM `acc_reg_num_db` WHERE `key`='"+getarg(0)+"'"); + query_sql("DELETE FROM `acc_reg_str_db` WHERE `key`='"+getarg(0)+"'"); + + if (playerattached()) + detachrid(); + + // Del variables which SQL can't reach + .@c = getunits(BL_PC, .@players, MAX_CYCLE_PC); + for (.@i = 0; .@i < .@c; .@i++) { + attachrid(.@players[.@i]); + if (compare(getarg(0), "$")) + setd(getarg(0), ""); + else + setd(getarg(0), 0); + detachrid(); + } + return; +} + +// Delete an char_reg entry from all players. Full arrays only. Affect num and str db. +// WARNING, irreversible and dangerous! +// DelChrRegFromEveryPlayer( KEY ) +function script DelChrRegFromEveryPlayer { + if (getarg(0, "error") == "error") + return; + + query_sql("DELETE FROM `char_reg_num_db` WHERE `key`='"+getarg(0)+"'"); + query_sql("DELETE FROM `char_reg_str_db` WHERE `key`='"+getarg(0)+"'"); + + // Del variables which SQL can't reach + .@c = getunits(BL_PC, .@players, MAX_CYCLE_PC); + for (.@i = 0; .@i < .@c; .@i++) { + if (compare(getarg(0), "$")) + setd(getarg(0), ""); + else + setd(getarg(0), 0); + } + return; +} + +// Delete a quest entry from all players. This includes all counters. Use with caution. +// WARNING, irreversible and dangerous! +// DelQuestFromEveryPlayer( ID ) +function script DelQuestFromEveryPlayer { + if (getarg(0, -1) < 0) + return; + + query_sql("DELETE FROM `quest` WHERE `quest_id`="+getarg(0)); + + // Del quests which SQL can't reach + .@a=playerattached(); + if (.@a) detachrid(); + .@c = getunits(BL_PC, .@players, MAX_CYCLE_PC); + for (.@i = 0; .@i < .@c; .@i++) { + attachrid(.@players[.@i]); + setq(getarg(0), 0, 0, 0, 0); + detachrid(); + } + if (.@a) attachrid(.@a); + return; +} + +// Transforms an item in something else. +// ReplaceItemFromEveryPlayer( OldID, NewID ) +function script ReplaceItemFromEveryPlayer { + if (getarg(0, -1) < 0) + return; + debugmes("* Server update: %d item was replaced by %d", getarg(0), getarg(1)); + query_sql("UPDATE `inventory` SET `nameid`='"+getarg(1)+"' WHERE `nameid`="+getarg(0)); + query_sql("UPDATE `cart_inventory` SET `nameid`='"+getarg(1)+"' WHERE `nameid`="+getarg(0)); + query_sql("UPDATE `storage` SET `nameid`='"+getarg(1)+"' WHERE `nameid`="+getarg(0)); + query_sql("UPDATE `guild_storage` SET `nameid`='"+getarg(1)+"' WHERE `nameid`="+getarg(0)); + query_sql("UPDATE `rodex_items` SET `nameid`='"+getarg(1)+"' WHERE `nameid`="+getarg(0)); + query_sql("UPDATE `auction` SET `nameid`='"+getarg(1)+"' WHERE `nameid`="+getarg(0)); + return; +} + +// Replaces a skill with another ID. +// ReplaceSkillFromEveryPlayer( OldID, NewID ) +function script ReplaceSkillFromEveryPlayer { + if (getarg(0, -1) < 0) + return; + debugmes("* Server update: skill %d was replaced by %d", getarg(0), getarg(1)); + // If new ID already exists, it will skip + query_sql("UPDATE IGNORE `skill` SET `id`='"+getarg(1)+"' WHERE `id`="+getarg(0)); + return; +} + |