From c04b0d1c4afc458492e03936cbf43ff42f739377 Mon Sep 17 00:00:00 2001 From: 55Honey <71938210+55Honey@users.noreply.github.com> Date: Thu, 11 Mar 2021 10:46:46 +0100 Subject: [PATCH 1/7] added return of first sent items guid - get the guid of the first item generated in the mail and return it to lua - declaration of mailGUID to check if data was already pushed to lua in a previous walkthrough of the while loop, in case there are multiple items added --- GlobalMethods.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/GlobalMethods.h b/GlobalMethods.h index 4dbf972..01e5bb9 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -2128,6 +2128,7 @@ namespace LuaGlobalFunctions SQLTransaction trans = CharacterDatabase.BeginTransaction(); #endif uint8 addedItems = 0; + uint32 mailGUID = 0; while (addedItems <= MAX_MAIL_ITEMS && i + 2 <= argAmount) { uint32 entry = Eluna::CHECKVAL(L, ++i); @@ -2156,6 +2157,13 @@ namespace LuaGlobalFunctions item->SaveToDB(); #endif draft.AddItem(item); + + if (!mailGUID > 0) + { + mailGUID = item->GetGUIDLow(); + Eluna::Push(L, mailGUID); + } + ++addedItems; } } @@ -2167,7 +2175,7 @@ namespace LuaGlobalFunctions #else draft.SendMailTo(MailReceiver(receiverPlayer, MAKE_NEW_GUID(receiverGUIDLow, 0, HIGHGUID_PLAYER)), sender); #endif - return 0; + return 1; } /** From ce0c5bdc26e3ce50f37988bf1c17b8e82569667a Mon Sep 17 00:00:00 2001 From: 55Honey <71938210+55Honey@users.noreply.github.com> Date: Thu, 11 Mar 2021 11:05:46 +0100 Subject: [PATCH 2/7] changed condition of mailGUID --- GlobalMethods.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GlobalMethods.h b/GlobalMethods.h index 01e5bb9..6c6c5f9 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -2158,7 +2158,7 @@ namespace LuaGlobalFunctions #endif draft.AddItem(item); - if (!mailGUID > 0) + if (mailGUID <= 0) { mailGUID = item->GetGUIDLow(); Eluna::Push(L, mailGUID); From 9941dc1ba355814683d789717751c3f1c568ab17 Mon Sep 17 00:00:00 2001 From: 55Honey <71938210+55Honey@users.noreply.github.com> Date: Thu, 11 Mar 2021 20:48:47 +0100 Subject: [PATCH 3/7] added definition for different cores added definition for Azerothcore and Trinity. Other cores do not return a value. --- GlobalMethods.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/GlobalMethods.h b/GlobalMethods.h index 6c6c5f9..0c1beff 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -2158,12 +2158,19 @@ namespace LuaGlobalFunctions #endif draft.AddItem(item); +#if defined AZEROTHCORE if (mailGUID <= 0) { mailGUID = item->GetGUIDLow(); Eluna::Push(L, mailGUID); } - +#elif defined TRINITY + if (mailGUID <= 0) + { + mailGUID = item->GetGUID(); + Eluna::Push(L, mailGUID); + } +#endif ++addedItems; } } @@ -2175,7 +2182,11 @@ namespace LuaGlobalFunctions #else draft.SendMailTo(MailReceiver(receiverPlayer, MAKE_NEW_GUID(receiverGUIDLow, 0, HIGHGUID_PLAYER)), sender); #endif +#if defined TRINITY || AZEROTHCORE return 1; +#else + return 0; +#endif } /** From 2074daf065b64d296cd29566ab4c0bea3e29f9eb Mon Sep 17 00:00:00 2001 From: 55Honey <71938210+55Honey@users.noreply.github.com> Date: Thu, 11 Mar 2021 20:58:14 +0100 Subject: [PATCH 4/7] Dont change the whole block. just the required line. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Francesco Borzì --- GlobalMethods.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/GlobalMethods.h b/GlobalMethods.h index 0c1beff..3ee9fbd 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -2158,19 +2158,16 @@ namespace LuaGlobalFunctions #endif draft.AddItem(item); + + if (mailGUID <= 0) + { #if defined AZEROTHCORE - if (mailGUID <= 0) - { mailGUID = item->GetGUIDLow(); - Eluna::Push(L, mailGUID); - } #elif defined TRINITY - if (mailGUID <= 0) - { mailGUID = item->GetGUID(); +#endif Eluna::Push(L, mailGUID); } -#endif ++addedItems; } } From 620cb0ff152bf4b4cc1bfcda430cb9c583f9e833 Mon Sep 17 00:00:00 2001 From: 55Honey <71938210+55Honey@users.noreply.github.com> Date: Sat, 13 Mar 2021 20:55:25 +0100 Subject: [PATCH 5/7] new approach: multiple variables Return the guid of items created by SendMail for Azerothcore. Syntax: item1, item2, item3, ... = SendMail(subject, text, receiverGUIDLow, senderGUIDLow, stationary, delay, money, cod, entry1, amount1, entry2, amount2, entry3, amount3...) --- GlobalMethods.h | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/GlobalMethods.h b/GlobalMethods.h index 3ee9fbd..125285f 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -2128,7 +2128,6 @@ namespace LuaGlobalFunctions SQLTransaction trans = CharacterDatabase.BeginTransaction(); #endif uint8 addedItems = 0; - uint32 mailGUID = 0; while (addedItems <= MAX_MAIL_ITEMS && i + 2 <= argAmount) { uint32 entry = Eluna::CHECKVAL(L, ++i); @@ -2157,17 +2156,9 @@ namespace LuaGlobalFunctions item->SaveToDB(); #endif draft.AddItem(item); - - - if (mailGUID <= 0) - { #if defined AZEROTHCORE - mailGUID = item->GetGUIDLow(); -#elif defined TRINITY - mailGUID = item->GetGUID(); + Eluna::Push(L, item->GetGUIDLow()); #endif - Eluna::Push(L, mailGUID); - } ++addedItems; } } @@ -2179,8 +2170,8 @@ namespace LuaGlobalFunctions #else draft.SendMailTo(MailReceiver(receiverPlayer, MAKE_NEW_GUID(receiverGUIDLow, 0, HIGHGUID_PLAYER)), sender); #endif -#if defined TRINITY || AZEROTHCORE - return 1; +#if defined AZEROTHCORE + return addedItems; #else return 0; #endif From 688857b0f2c6e68375646925febd9f175e20f856 Mon Sep 17 00:00:00 2001 From: 55Honey <71938210+55Honey@users.noreply.github.com> Date: Mon, 15 Mar 2021 12:15:38 +0100 Subject: [PATCH 6/7] Added guid returns from SendMail Previously only AC received guid returns from this PR. This commit adds a return for all cores. --- GlobalMethods.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/GlobalMethods.h b/GlobalMethods.h index 125285f..ce610e9 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -2156,7 +2156,9 @@ namespace LuaGlobalFunctions item->SaveToDB(); #endif draft.AddItem(item); -#if defined AZEROTHCORE +#if defined TRINITY + Eluna::Push(L, item->GetGUID().GetCounter()); +#else Eluna::Push(L, item->GetGUIDLow()); #endif ++addedItems; @@ -2170,11 +2172,7 @@ namespace LuaGlobalFunctions #else draft.SendMailTo(MailReceiver(receiverPlayer, MAKE_NEW_GUID(receiverGUIDLow, 0, HIGHGUID_PLAYER)), sender); #endif -#if defined AZEROTHCORE return addedItems; -#else - return 0; -#endif } /** From f9ad7fb7f2599741e464b904ff8499041d605b87 Mon Sep 17 00:00:00 2001 From: 55Honey <71938210+55Honey@users.noreply.github.com> Date: Fri, 19 Mar 2021 17:34:46 +0100 Subject: [PATCH 7/7] added documentation for return of SendMail() added documentation for return of SendMail() --- GlobalMethods.h | 1 + 1 file changed, 1 insertion(+) diff --git a/GlobalMethods.h b/GlobalMethods.h index ce610e9..839d24e 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -2093,6 +2093,7 @@ namespace LuaGlobalFunctions * @param uint32 cod = 0 : cod money amount * @param uint32 entry = 0 : entry of an [Item] to send with mail * @param uint32 amount = 0 : amount of the [Item] to send with mail + * @return uint32 itemGUIDlow : low GUID of the item. Up to 12 values returned, returns nil if no further items are sent */ int SendMail(lua_State* L) {