From 7ee7a25887dce884a66cb82cd4202a8f8f4bb913 Mon Sep 17 00:00:00 2001 From: HAO YAN Date: Thu, 14 Dec 2023 22:39:57 +0800 Subject: [PATCH] Add autoloot script command (#8032) --- doc/script_commands.txt | 15 +++++++++++++++ src/map/script.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 1a601c36e3..3e97c9d69e 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -11390,3 +11390,18 @@ Returns current autoloot value on success. --------------------------------------- +*autoloot({{, }}); + +This command sets the rate of autoloot. +If no rate is provided and the user has autoloot disabled it will default to 10000 = 100% (enabled) or +if the user has autoloot enabled it will default to 0 = 0% (disabled). +Returns true on success and false on failure. + +Example: + autoloot(); // toggle on/off depend on existing autoloot + autoloot(0); // 0.00% or off + autoloot(100); // 1.00% + autoloot(3333); // 33.33% + autoloot(10000); // 100.00% + +--------------------------------------- diff --git a/src/map/script.cpp b/src/map/script.cpp index 04c5c54c72..0bfe6c4241 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -27016,6 +27016,41 @@ BUILDIN_FUNC(has_autoloot) { return SCRIPT_CMD_SUCCESS; } +// =================================== +// *autoloot({{, }}); +// This command sets the rate of autoloot. +// If no rate is provided and the user has autoloot disabled it will default to 10000 = 100% (enabled) or +// if the user has autoloot enabled it will default to 0 = 0% (disabled). +// Returns true on success and false on failure. +// =================================== +BUILDIN_FUNC(autoloot) { + map_session_data *sd = nullptr; + + if (!script_charid2sd(3, sd)) { + script_pushint(st, false); + return SCRIPT_CMD_FAILURE; + } + + int rate; + + if (script_hasdata(st, 2)) { + rate = script_getnum(st, 2); + + if (rate < 0 || rate > 10000) { + ShowWarning("buildin_autoloot: Invalid rate value %d, should be between 0 ~ 10000.\n", rate); + script_pushint(st, false); + return SCRIPT_CMD_FAILURE; + } + } else { + rate = (sd->state.autoloot > 0 ? 0 : 10000); + } + + sd->state.autoloot = rate; + script_pushint(st, true); + + return SCRIPT_CMD_SUCCESS; +} + BUILDIN_FUNC(opentips){ #if PACKETVER < 20171122 ShowError( "buildin_opentips: This command requires PACKETVER 20171122 or newer.\n" ); @@ -27789,6 +27824,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF(isdead, "?"), BUILDIN_DEF(macro_detector, "?"), BUILDIN_DEF(has_autoloot,"?"), + BUILDIN_DEF(autoloot,"??"), BUILDIN_DEF(opentips, "i?"), #include