diff options
Diffstat (limited to 'npc/functions/main.txt')
-rw-r--r-- | npc/functions/main.txt | 123 |
1 files changed, 123 insertions, 0 deletions
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; +} + |