diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp --- a/src/script/api/script_object.hpp +++ b/src/script/api/script_object.hpp @@ -347,6 +347,22 @@ namespace ScriptObjectInternal { { ((SanitizeSingleStringHelper(std::get(values))), ...); } + + /** Helper to process a single ClientID argument. */ + template + static inline void SetClientIdHelper(T &data) + { + if constexpr (std::is_same_v) { + if (data == INVALID_CLIENT_ID) data = (ClientID)UINT32_MAX; + } + } + + /** Set all invalid ClientID's to the proper value. */ + template + static inline void SetClientIds(Ttuple &values, std::index_sequence) + { + ((SetClientIdHelper(std::get(values))), ...); + } } template @@ -364,8 +380,8 @@ bool ScriptObject::ScriptDoCommandHelper tile = std::get<0>(args); } - /* Only set p2 when the command does not come from the network. */ - if ((::GetCommandFlags() & CMD_CLIENT_ID) != 0 && std::get<2>(args) == 0) std::get<2>(args) = UINT32_MAX; + /* Only set ClientID parameters when the command does not come from the network. */ + if constexpr ((::GetCommandFlags() & CMD_CLIENT_ID) != 0) ScriptObjectInternal::SetClientIds(args, std::index_sequence_for{}); /* Store the command for command callback validation. */ if (!estimate_only && networking) ScriptObject::SetLastCommand(tile, EndianBufferWriter::FromValue(args), Tcmd);