Add autoloot script command (#8032)

This commit is contained in:
HAO YAN 2023-12-14 22:39:57 +08:00 committed by GitHub
parent a7f0aab600
commit 7ee7a25887
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 0 deletions

View File

@ -11390,3 +11390,18 @@ Returns current autoloot value on success.
---------------------------------------
*autoloot({<rate>{, <char_id>}});
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%
---------------------------------------

View File

@ -27016,6 +27016,41 @@ BUILDIN_FUNC(has_autoloot) {
return SCRIPT_CMD_SUCCESS;
}
// ===================================
// *autoloot({<rate>{, <char_id>}});
// 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 <custom/script_def.inc>