forked from ElunaLuaEngine/Eluna
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGlobalMethods.h
3260 lines (3017 loc) · 123 KB
/
GlobalMethods.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
* This program is free software licensed under GPL version 3
* Please see the included DOCS/LICENSE.md for more information
*/
#ifndef GLOBALMETHODS_H
#define GLOBALMETHODS_H
#include "BindingMap.h"
#ifdef AZEROTHCORE
#include "BanMgr.h"
enum BanMode
{
BAN_ACCOUNT = 1,
BAN_CHARACTER = 2,
BAN_IP = 3
};
#endif
/***
* These functions can be used anywhere at any time, including at start-up.
*/
namespace LuaGlobalFunctions
{
/**
* Returns Lua engine's name.
*
* Always returns "ElunaEngine" on Eluna.
*
* @return string engineName
*/
int GetLuaEngine(lua_State* L)
{
Eluna::Push(L, "ElunaEngine");
return 1;
}
/**
* Returns emulator's name.
*
* The result will be either `MaNGOS`, `cMaNGOS`, or `TrinityCore`.
*
* @return string coreName
*/
int GetCoreName(lua_State* L)
{
Eluna::Push(L, CORE_NAME);
return 1;
}
/**
* Returns emulator .conf RealmID
*
* - for MaNGOS returns the realmID as it is stored in the core.
* - for TrinityCore returns the realmID as it is in the conf file.
* @return uint32 realm ID
*/
int GetRealmID(lua_State* L)
{
#if defined(MANGOS) || CMANGOS
Eluna::Push(L, realmID);
#else
Eluna::Push(L, sConfigMgr->GetIntDefault("RealmID", 1));
#endif
return 1;
}
/**
* Returns emulator version
*
* - For TrinityCore returns the date of the last revision, e.g. `2015-08-26 22:53:12 +0300`
* - For cMaNGOS returns the date and time of the last revision, e.g. `2015-09-06 13:18:50`
* - for MaNGOS returns the version number as string, e.g. `21000`
*
* @return string version
*/
int GetCoreVersion(lua_State* L)
{
#ifdef MANGOS
Eluna::Push(L, GitRevision::GetProjectRevision());
#else
Eluna::Push(L, CORE_VERSION);
#endif
return 1;
}
/**
* Returns emulator's supported expansion.
*
* Expansion is 0 for pre-TBC, 1 for TBC, 2 for WotLK, and 3 for Cataclysm.
*
* @return int32 expansion
*/
int GetCoreExpansion(lua_State* L)
{
#ifdef CLASSIC
Eluna::Push(L, 0);
#elif defined(TBC)
Eluna::Push(L, 1);
#elif defined(WOTLK)
Eluna::Push(L, 2);
#elif defined(CATA)
Eluna::Push(L, 3);
#endif
return 1;
}
/**
* Returns [Quest] template
*
* @param uint32 questId : [Quest] entry ID
* @return [Quest] quest
*/
int GetQuest(lua_State* L)
{
uint32 questId = Eluna::CHECKVAL<uint32>(L, 1);
Eluna::Push(L, eObjectMgr->GetQuestTemplate(questId));
return 1;
}
/**
* Finds and Returns [Player] by guid if found
*
* @param ObjectGuid guid : guid of the [Player], you can get it with [Object:GetGUID]
* @return [Player] player
*/
int GetPlayerByGUID(lua_State* L)
{
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
Eluna::Push(L, eObjectAccessor()FindPlayer(guid));
return 1;
}
/**
* Finds and Returns [Player] by name if found
*
* @param string name : name of the [Player]
* @return [Player] player
*/
int GetPlayerByName(lua_State* L)
{
const char* name = Eluna::CHECKVAL<const char*>(L, 1);
Eluna::Push(L, eObjectAccessor()FindPlayerByName(name));
return 1;
}
/**
* Returns game time in seconds
*
* @return uint32 time
*/
int GetGameTime(lua_State* L)
{
#ifdef TRINITY
Eluna::Push(L, GameTime::GetGameTime());
#else
Eluna::Push(L, eWorld->GetGameTime());
#endif
return 1;
}
/**
* Returns a table with all the current [Player]s in the world
*
* Does not return players that may be teleporting or otherwise not on any map.
*
* enum TeamId
* {
* TEAM_ALLIANCE = 0,
* TEAM_HORDE = 1,
* TEAM_NEUTRAL = 2
* };
*
* @param [TeamId] team = TEAM_NEUTRAL : optional check team of the [Player], Alliance, Horde or Neutral (All)
* @param bool onlyGM = false : optional check if GM only
* @return table worldPlayers
*/
int GetPlayersInWorld(lua_State* L)
{
uint32 team = Eluna::CHECKVAL<uint32>(L, 1, TEAM_NEUTRAL);
bool onlyGM = Eluna::CHECKVAL<bool>(L, 2, false);
lua_newtable(L);
int tbl = lua_gettop(L);
uint32 i = 0;
#if defined(MANGOS)
eObjectAccessor()DoForAllPlayers([&](Player* player){
if(player->IsInWorld())
{
if ((team == TEAM_NEUTRAL || player->GetTeamId() == team) && (!onlyGM || player->isGameMaster()))
{
Eluna::Push(L, player);
lua_rawseti(L, tbl, ++i);
}
}
});
#else
{
#if defined TRINITY || AZEROTHCORE
std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
#else
HashMapHolder<Player>::ReadGuard g(HashMapHolder<Player>::GetLock());
#endif
const HashMapHolder<Player>::MapType& m = eObjectAccessor()GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator it = m.begin(); it != m.end(); ++it)
{
if (Player* player = it->second)
{
if (!player->IsInWorld())
continue;
#if defined TRINITY || AZEROTHCORE || CMANGOS
if ((team == TEAM_NEUTRAL || player->GetTeamId() == team) && (!onlyGM || player->IsGameMaster()))
#else
if ((team == TEAM_NEUTRAL || player->GetTeamId() == team) && (!onlyGM || player->isGameMaster()))
#endif
{
Eluna::Push(L, player);
lua_rawseti(L, tbl, ++i);
}
}
}
}
#endif
lua_settop(L, tbl); // push table to top of stack
return 1;
}
/**
* Returns a [Guild] by name.
*
* @param string name
* @return [Guild] guild : the Guild, or `nil` if it doesn't exist
*/
int GetGuildByName(lua_State* L)
{
const char* name = Eluna::CHECKVAL<const char*>(L, 1);
Eluna::Push(L, eGuildMgr->GetGuildByName(name));
return 1;
}
/**
* Returns a [Map] by ID.
*
* @param uint32 mapId : see [Map.dbc](https://github.com/cmangos/issues/wiki/Map.dbc)
* @param uint32 instanceId = 0 : required if the map is an instance, otherwise don't pass anything
* @return [Map] map : the Map, or `nil` if it doesn't exist
*/
int GetMapById(lua_State* L)
{
uint32 mapid = Eluna::CHECKVAL<uint32>(L, 1);
uint32 instance = Eluna::CHECKVAL<uint32>(L, 2, 0);
Eluna::Push(L, eMapMgr->FindMap(mapid, instance));
return 1;
}
/**
* Returns [Guild] by the leader's GUID
*
* @param ObjectGuid guid : the guid of a [Guild] leader
* @return [Guild] guild, or `nil` if it doesn't exist
*/
int GetGuildByLeaderGUID(lua_State* L)
{
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
Eluna::Push(L, eGuildMgr->GetGuildByLeader(guid));
return 1;
}
/**
* Returns the amount of [Player]s in the world.
*
* @return uint32 count
*/
int GetPlayerCount(lua_State* L)
{
Eluna::Push(L, eWorld->GetActiveSessionCount());
return 1;
}
/**
* Builds a [Player]'s GUID
*
* [Player] GUID consist of low GUID and type ID
*
* [Player] and [Creature] for example can have the same low GUID but not GUID.
*
* @param uint32 lowguid : low GUID of the [Player]
* @return ObjectGuid guid
*/
int GetPlayerGUID(lua_State* L)
{
uint32 lowguid = Eluna::CHECKVAL<uint32>(L, 1);
Eluna::Push(L, MAKE_NEW_GUID(lowguid, 0, HIGHGUID_PLAYER));
return 1;
}
/**
* Builds an [Item]'s GUID.
*
* [Item] GUID consist of low GUID and type ID
* [Player] and [Item] for example can have the same low GUID but not GUID.
*
* @param uint32 lowguid : low GUID of the [Item]
* @return ObjectGuid guid
*/
int GetItemGUID(lua_State* L)
{
uint32 lowguid = Eluna::CHECKVAL<uint32>(L, 1);
Eluna::Push(L, MAKE_NEW_GUID(lowguid, 0, HIGHGUID_ITEM));
return 1;
}
/**
* Builds a [GameObject]'s GUID.
*
* A GameObject's GUID consist of entry ID, low GUID and type ID
*
* A [Player] and GameObject for example can have the same low GUID but not GUID.
*
* @param uint32 lowguid : low GUID of the [GameObject]
* @param uint32 entry : entry ID of the [GameObject]
* @return ObjectGuid guid
*/
int GetObjectGUID(lua_State* L)
{
uint32 lowguid = Eluna::CHECKVAL<uint32>(L, 1);
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, MAKE_NEW_GUID(lowguid, entry, HIGHGUID_GAMEOBJECT));
return 1;
}
/**
* Builds a [Creature]'s GUID.
*
* [Creature] GUID consist of entry ID, low GUID and type ID
*
* [Player] and [Creature] for example can have the same low GUID but not GUID.
*
* @param uint32 lowguid : low GUID of the [Creature]
* @param uint32 entry : entry ID of the [Creature]
* @return ObjectGuid guid
*/
int GetUnitGUID(lua_State* L)
{
uint32 lowguid = Eluna::CHECKVAL<uint32>(L, 1);
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, MAKE_NEW_GUID(lowguid, entry, HIGHGUID_UNIT));
return 1;
}
/**
* Returns the low GUID from a GUID.
*
* A GUID consists of a low GUID, type ID, and possibly an entry ID depending on the type ID.
*
* Low GUID is an ID to distinct the objects of the same type.
*
* [Player] and [Creature] for example can have the same low GUID but not GUID.
*
* On TrinityCore all low GUIDs are different for all objects of the same type.
* For example creatures in instances are assigned new GUIDs when the Map is created.
*
* On MaNGOS and cMaNGOS low GUIDs are unique only on the same map.
* For example creatures in instances use the same low GUID assigned for that spawn in the database.
* This is why to identify a creature you have to know the instanceId and low GUID. See [Map:GetIntstanceId]
*
* @param ObjectGuid guid : GUID of an [Object]
* @return uint32 lowguid : low GUID of the [Object]
*/
int GetGUIDLow(lua_State* L)
{
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
Eluna::Push(L, guid.GetCounter());
return 1;
}
/**
* Returns an chat link for an [Item].
*
* enum LocaleConstant
* {
* LOCALE_enUS = 0,
* LOCALE_koKR = 1,
* LOCALE_frFR = 2,
* LOCALE_deDE = 3,
* LOCALE_zhCN = 4,
* LOCALE_zhTW = 5,
* LOCALE_esES = 6,
* LOCALE_esMX = 7,
* LOCALE_ruRU = 8
* };
*
* @param uint32 entry : entry ID of an [Item]
* @param [LocaleConstant] locale = DEFAULT_LOCALE : locale to return the [Item] name in
* @return string itemLink
*/
int GetItemLink(lua_State* L)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 1);
uint8 locale = Eluna::CHECKVAL<uint8>(L, 2, DEFAULT_LOCALE);
if (locale >= TOTAL_LOCALES)
return luaL_argerror(L, 2, "valid LocaleConstant expected");
const ItemTemplate* temp = eObjectMgr->GetItemTemplate(entry);
if (!temp)
return luaL_argerror(L, 1, "valid ItemEntry expected");
std::string name = temp->Name1;
if (ItemLocale const* il = eObjectMgr->GetItemLocale(entry))
ObjectMgr::GetLocaleString(il->Name, static_cast<LocaleConstant>(locale), name);
std::ostringstream oss;
oss << "|c" << std::hex << ItemQualityColors[temp->Quality] << std::dec <<
"|Hitem:" << entry << ":0:" <<
#ifndef CLASSIC
"0:0:0:0:" <<
#endif
"0:0:0:0|h[" << name << "]|h|r";
Eluna::Push(L, oss.str());
return 1;
}
/**
* Returns the type ID from a GUID.
*
* Type ID is different for each type ([Player], [Creature], [GameObject], etc.).
*
* GUID consist of entry ID, low GUID, and type ID.
*
* @param ObjectGuid guid : GUID of an [Object]
* @return int32 typeId : type ID of the [Object]
*/
int GetGUIDType(lua_State* L)
{
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
Eluna::Push(L, static_cast<int>(guid.GetHigh()));
return 1;
}
/**
* Returns the entry ID from a GUID.
*
* GUID consist of entry ID, low GUID, and type ID.
*
* @param ObjectGuid guid : GUID of an [Creature] or [GameObject]
* @return uint32 entry : entry ID, or `0` if `guid` is not a [Creature] or [GameObject]
*/
int GetGUIDEntry(lua_State* L)
{
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
Eluna::Push(L, guid.GetEntry());
return 1;
}
/**
* Returns the area or zone's name.
*
* enum LocaleConstant
* {
* LOCALE_enUS = 0,
* LOCALE_koKR = 1,
* LOCALE_frFR = 2,
* LOCALE_deDE = 3,
* LOCALE_zhCN = 4,
* LOCALE_zhTW = 5,
* LOCALE_esES = 6,
* LOCALE_esMX = 7,
* LOCALE_ruRU = 8
* };
*
* @param uint32 areaOrZoneId : area ID or zone ID
* @param [LocaleConstant] locale = DEFAULT_LOCALE : locale to return the name in
* @return string areaOrZoneName
*/
int GetAreaName(lua_State* L)
{
uint32 areaOrZoneId = Eluna::CHECKVAL<uint32>(L, 1);
uint8 locale = Eluna::CHECKVAL<uint8>(L, 2, DEFAULT_LOCALE);
if (locale >= TOTAL_LOCALES)
return luaL_argerror(L, 2, "valid LocaleConstant expected");
#if defined TRINITY || AZEROTHCORE
AreaTableEntry const* areaEntry = sAreaTableStore.LookupEntry(areaOrZoneId);
#else
AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaOrZoneId);
#endif
if (!areaEntry)
return luaL_argerror(L, 1, "valid Area or Zone ID expected");
#if defined(TRINITY)
Eluna::Push(L, areaEntry->AreaName[locale]);
#else
Eluna::Push(L, areaEntry->area_name[locale]);
#endif
return 1;
}
/**
* Returns the currently active game events.
*
* @return table activeEvents
*/
int GetActiveGameEvents(lua_State* L)
{
lua_newtable(L);
int tbl = lua_gettop(L);
uint32 counter = 1;
GameEventMgr::ActiveEvents const& activeEvents = eGameEventMgr->GetActiveEventList();
for (GameEventMgr::ActiveEvents::const_iterator i = activeEvents.begin(); i != activeEvents.end(); ++i)
{
Eluna::Push(L, *i);
lua_rawseti(L, tbl, counter);
counter++;
}
lua_settop(L, tbl);
return 1;
}
static int RegisterEntryHelper(lua_State* L, int regtype)
{
uint32 id = Eluna::CHECKVAL<uint32>(L, 1);
uint32 ev = Eluna::CHECKVAL<uint32>(L, 2);
luaL_checktype(L, 3, LUA_TFUNCTION);
uint32 shots = Eluna::CHECKVAL<uint32>(L, 4, 0);
lua_pushvalue(L, 3);
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef >= 0)
return Eluna::GetEluna(L)->Register(L, regtype, id, ObjectGuid(), 0, ev, functionRef, shots);
else
luaL_argerror(L, 3, "unable to make a ref to function");
return 0;
}
static int RegisterEventHelper(lua_State* L, int regtype)
{
uint32 ev = Eluna::CHECKVAL<uint32>(L, 1);
luaL_checktype(L, 2, LUA_TFUNCTION);
uint32 shots = Eluna::CHECKVAL<uint32>(L, 3, 0);
lua_pushvalue(L, 2);
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef >= 0)
return Eluna::GetEluna(L)->Register(L, regtype, 0, ObjectGuid(), 0, ev, functionRef, shots);
else
luaL_argerror(L, 2, "unable to make a ref to function");
return 0;
}
static int RegisterUniqueHelper(lua_State* L, int regtype)
{
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
uint32 instanceId = Eluna::CHECKVAL<uint32>(L, 2);
uint32 ev = Eluna::CHECKVAL<uint32>(L, 3);
luaL_checktype(L, 4, LUA_TFUNCTION);
uint32 shots = Eluna::CHECKVAL<uint32>(L, 5, 0);
lua_pushvalue(L, 4);
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef >= 0)
return Eluna::GetEluna(L)->Register(L, regtype, 0, guid, instanceId, ev, functionRef, shots);
else
luaL_argerror(L, 4, "unable to make a ref to function");
return 0;
}
/**
* Registers a server event handler.
*
* enum ServerEvents
* {
* // Server
* SERVER_EVENT_ON_NETWORK_START = 1, // Not Implemented
* SERVER_EVENT_ON_NETWORK_STOP = 2, // Not Implemented
* SERVER_EVENT_ON_SOCKET_OPEN = 3, // Not Implemented
* SERVER_EVENT_ON_SOCKET_CLOSE = 4, // Not Implemented
* SERVER_EVENT_ON_PACKET_RECEIVE = 5, // (event, packet, player) - Player only if accessible. Can return false, newPacket
* SERVER_EVENT_ON_PACKET_RECEIVE_UNKNOWN = 6, // Not Implemented
* SERVER_EVENT_ON_PACKET_SEND = 7, // (event, packet, player) - Player only if accessible. Can return false
*
* // World
* WORLD_EVENT_ON_OPEN_STATE_CHANGE = 8, // (event, open) - Needs core support on Mangos
* WORLD_EVENT_ON_CONFIG_LOAD = 9, // (event, reload)
* // UNUSED = 10,
* WORLD_EVENT_ON_SHUTDOWN_INIT = 11, // (event, code, mask)
* WORLD_EVENT_ON_SHUTDOWN_CANCEL = 12, // (event)
* WORLD_EVENT_ON_UPDATE = 13, // (event, diff)
* WORLD_EVENT_ON_STARTUP = 14, // (event)
* WORLD_EVENT_ON_SHUTDOWN = 15, // (event)
*
* // Eluna
* ELUNA_EVENT_ON_LUA_STATE_CLOSE = 16, // (event) - triggers just before shutting down eluna (on shutdown and restart)
*
* // Map
* MAP_EVENT_ON_CREATE = 17, // (event, map)
* MAP_EVENT_ON_DESTROY = 18, // (event, map)
* MAP_EVENT_ON_GRID_LOAD = 19, // Not Implemented
* MAP_EVENT_ON_GRID_UNLOAD = 20, // Not Implemented
* MAP_EVENT_ON_PLAYER_ENTER = 21, // (event, map, player)
* MAP_EVENT_ON_PLAYER_LEAVE = 22, // (event, map, player)
* MAP_EVENT_ON_UPDATE = 23, // (event, map, diff)
*
* // Area trigger
* TRIGGER_EVENT_ON_TRIGGER = 24, // (event, player, triggerId) - Can return true
*
* // Weather
* WEATHER_EVENT_ON_CHANGE = 25, // (event, zoneId, state, grade)
*
* // Auction house
* AUCTION_EVENT_ON_ADD = 26, // (event, auctionId, owner, item, expireTime, buyout, startBid, currentBid, bidderGUIDLow)
* AUCTION_EVENT_ON_REMOVE = 27, // (event, auctionId, owner, item, expireTime, buyout, startBid, currentBid, bidderGUIDLow)
* AUCTION_EVENT_ON_SUCCESSFUL = 28, // (event, auctionId, owner, item, expireTime, buyout, startBid, currentBid, bidderGUIDLow)
* AUCTION_EVENT_ON_EXPIRE = 29, // (event, auctionId, owner, item, expireTime, buyout, startBid, currentBid, bidderGUIDLow)
*
* // AddOns
* ADDON_EVENT_ON_MESSAGE = 30, // (event, sender, type, prefix, msg, target) - target can be nil/whisper_target/guild/group/channel. Can return false
*
* WORLD_EVENT_ON_DELETE_CREATURE = 31, // (event, creature)
* WORLD_EVENT_ON_DELETE_GAMEOBJECT = 32, // (event, gameobject)
*
* // Eluna
* ELUNA_EVENT_ON_LUA_STATE_OPEN = 33, // (event) - triggers after all scripts are loaded
*
* GAME_EVENT_START = 34, // (event, gameeventid)
* GAME_EVENT_STOP = 35, // (event, gameeventid)
* };
*
* @proto cancel = (event, function)
* @proto cancel = (event, function, shots)
*
* @param uint32 event : server event ID, refer to ServerEvents above
* @param function function : function that will be called when the event occurs
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*
* @return function cancel : a function that cancels the binding when called
*/
int RegisterServerEvent(lua_State* L)
{
return RegisterEventHelper(L, Hooks::REGTYPE_SERVER);
}
/**
* Registers a [Player] event handler.
*
* <pre>
* enum PlayerEvents
* {
* PLAYER_EVENT_ON_CHARACTER_CREATE = 1, // (event, player)
* PLAYER_EVENT_ON_CHARACTER_DELETE = 2, // (event, guid)
* PLAYER_EVENT_ON_LOGIN = 3, // (event, player)
* PLAYER_EVENT_ON_LOGOUT = 4, // (event, player)
* PLAYER_EVENT_ON_SPELL_CAST = 5, // (event, player, spell, skipCheck)
* PLAYER_EVENT_ON_KILL_PLAYER = 6, // (event, killer, killed)
* PLAYER_EVENT_ON_KILL_CREATURE = 7, // (event, killer, killed)
* PLAYER_EVENT_ON_KILLED_BY_CREATURE = 8, // (event, killer, killed)
* PLAYER_EVENT_ON_DUEL_REQUEST = 9, // (event, target, challenger)
* PLAYER_EVENT_ON_DUEL_START = 10, // (event, player1, player2)
* PLAYER_EVENT_ON_DUEL_END = 11, // (event, winner, loser, type)
* PLAYER_EVENT_ON_GIVE_XP = 12, // (event, player, amount, victim) - Can return new XP amount
* PLAYER_EVENT_ON_LEVEL_CHANGE = 13, // (event, player, oldLevel)
* PLAYER_EVENT_ON_MONEY_CHANGE = 14, // (event, player, amount) - Can return new money amount
* PLAYER_EVENT_ON_REPUTATION_CHANGE = 15, // (event, player, factionId, standing, incremental) - Can return new standing
* PLAYER_EVENT_ON_TALENTS_CHANGE = 16, // (event, player, points)
* PLAYER_EVENT_ON_TALENTS_RESET = 17, // (event, player, noCost)
* PLAYER_EVENT_ON_CHAT = 18, // (event, player, msg, Type, lang) - Can return false, newMessage
* PLAYER_EVENT_ON_WHISPER = 19, // (event, player, msg, Type, lang, receiver) - Can return false, newMessage
* PLAYER_EVENT_ON_GROUP_CHAT = 20, // (event, player, msg, Type, lang, group) - Can return false, newMessage
* PLAYER_EVENT_ON_GUILD_CHAT = 21, // (event, player, msg, Type, lang, guild) - Can return false, newMessage
* PLAYER_EVENT_ON_CHANNEL_CHAT = 22, // (event, player, msg, Type, lang, channel) - Can return false, newMessage
* PLAYER_EVENT_ON_EMOTE = 23, // (event, player, emote) - Not triggered on any known emote
* PLAYER_EVENT_ON_TEXT_EMOTE = 24, // (event, player, textEmote, emoteNum, guid)
* PLAYER_EVENT_ON_SAVE = 25, // (event, player)
* PLAYER_EVENT_ON_BIND_TO_INSTANCE = 26, // (event, player, difficulty, mapid, permanent)
* PLAYER_EVENT_ON_UPDATE_ZONE = 27, // (event, player, newZone, newArea)
* PLAYER_EVENT_ON_MAP_CHANGE = 28, // (event, player)
*
* // Custom
* PLAYER_EVENT_ON_EQUIP = 29, // (event, player, item, bag, slot)
* PLAYER_EVENT_ON_FIRST_LOGIN = 30, // (event, player)
* PLAYER_EVENT_ON_CAN_USE_ITEM = 31, // (event, player, itemEntry) - Can return InventoryResult enum value
* PLAYER_EVENT_ON_LOOT_ITEM = 32, // (event, player, item, count)
* PLAYER_EVENT_ON_ENTER_COMBAT = 33, // (event, player, enemy)
* PLAYER_EVENT_ON_LEAVE_COMBAT = 34, // (event, player)
* PLAYER_EVENT_ON_REPOP = 35, // (event, player)
* PLAYER_EVENT_ON_RESURRECT = 36, // (event, player)
* PLAYER_EVENT_ON_LOOT_MONEY = 37, // (event, player, amount)
* PLAYER_EVENT_ON_QUEST_ABANDON = 38, // (event, player, questId)
* PLAYER_EVENT_ON_LEARN_TALENTS = 39, // (event, player, talentId, talentRank, spellid)
* // UNUSED = 40, // (event, player)
* // UNUSED = 41, // (event, player)
* PLAYER_EVENT_ON_COMMAND = 42, // (event, player, command) - player is nil if command used from console. Can return false
* };
* </pre>
*
* @proto cancel = (event, function)
* @proto cancel = (event, function, shots)
*
* @param uint32 event : [Player] event Id, refer to PlayerEvents above
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*
* @return function cancel : a function that cancels the binding when called
*/
int RegisterPlayerEvent(lua_State* L)
{
return RegisterEventHelper(L, Hooks::REGTYPE_PLAYER);
}
/**
* Registers a [Guild] event handler.
*
* <pre>
* enum GuildEvents
* {
* // Guild
* GUILD_EVENT_ON_ADD_MEMBER = 1, // (event, guild, player, rank)
* GUILD_EVENT_ON_REMOVE_MEMBER = 2, // (event, guild, player, isDisbanding)
* GUILD_EVENT_ON_MOTD_CHANGE = 3, // (event, guild, newMotd)
* GUILD_EVENT_ON_INFO_CHANGE = 4, // (event, guild, newInfo)
* GUILD_EVENT_ON_CREATE = 5, // (event, guild, leader, name) // Not on TC
* GUILD_EVENT_ON_DISBAND = 6, // (event, guild)
* GUILD_EVENT_ON_MONEY_WITHDRAW = 7, // (event, guild, player, amount, isRepair) - Can return new money amount
* GUILD_EVENT_ON_MONEY_DEPOSIT = 8, // (event, guild, player, amount) - Can return new money amount
* GUILD_EVENT_ON_ITEM_MOVE = 9, // (event, guild, player, item, isSrcBank, srcContainer, srcSlotId, isDestBank, destContainer, destSlotId) // TODO
* GUILD_EVENT_ON_EVENT = 10, // (event, guild, eventType, plrGUIDLow1, plrGUIDLow2, newRank) // TODO
* GUILD_EVENT_ON_BANK_EVENT = 11, // (event, guild, eventType, tabId, playerGUIDLow, itemOrMoney, itemStackCount, destTabId)
*
* GUILD_EVENT_COUNT
* };
* </pre>
*
* @proto cancel = (event, function)
* @proto cancel = (event, function, shots)
*
* @param uint32 event : [Guild] event Id, refer to GuildEvents above
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*
* @return function cancel : a function that cancels the binding when called
*/
int RegisterGuildEvent(lua_State* L)
{
return RegisterEventHelper(L, Hooks::REGTYPE_GUILD);
}
/**
* Registers a [Group] event handler.
*
* <pre>
* enum GroupEvents
* {
* // Group
* GROUP_EVENT_ON_MEMBER_ADD = 1, // (event, group, guid)
* GROUP_EVENT_ON_MEMBER_INVITE = 2, // (event, group, guid)
* GROUP_EVENT_ON_MEMBER_REMOVE = 3, // (event, group, guid, method, kicker, reason)
* GROUP_EVENT_ON_LEADER_CHANGE = 4, // (event, group, newLeaderGuid, oldLeaderGuid)
* GROUP_EVENT_ON_DISBAND = 5, // (event, group)
* GROUP_EVENT_ON_CREATE = 6, // (event, group, leaderGuid, groupType)
*
* GROUP_EVENT_COUNT
* };
* </pre>
*
* @proto cancel = (event, function)
* @proto cancel = (event, function, shots)
*
* @param uint32 event : [Group] event Id, refer to GroupEvents above
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*
* @return function cancel : a function that cancels the binding when called
*/
int RegisterGroupEvent(lua_State* L)
{
return RegisterEventHelper(L, Hooks::REGTYPE_GROUP);
}
/**
* Registers a [BattleGround] event handler.
*
* <pre>
* enum BGEvents
* {
* BG_EVENT_ON_START = 1, // (event, bg, bgId, instanceId) - Needs to be added to TC
* BG_EVENT_ON_END = 2, // (event, bg, bgId, instanceId, winner) - Needs to be added to TC
* BG_EVENT_ON_CREATE = 3, // (event, bg, bgId, instanceId) - Needs to be added to TC
* BG_EVENT_ON_PRE_DESTROY = 4, // (event, bg, bgId, instanceId) - Needs to be added to TC
* BG_EVENT_COUNT
* };
* </pre>
*
* @proto cancel = (event, function)
* @proto cancel = (event, function, shots)
*
* @param uint32 event : [BattleGround] event Id, refer to BGEvents above
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*
* @return function cancel : a function that cancels the binding when called
*/
int RegisterBGEvent(lua_State* L)
{
return RegisterEventHelper(L, Hooks::REGTYPE_BG);
}
/**
* Registers a [WorldPacket] event handler.
*
* <pre>
* enum PacketEvents
* {
* PACKET_EVENT_ON_PACKET_RECEIVE = 5, // (event, packet, player) - Player only if accessible. Can return false, newPacket
* PACKET_EVENT_ON_PACKET_RECEIVE_UNKNOWN = 6, // Not Implemented
* PACKET_EVENT_ON_PACKET_SEND = 7, // (event, packet, player) - Player only if accessible. Can return false
*
* PACKET_EVENT_COUNT
* };
* </pre>
*
* @proto cancel = (entry, event, function)
* @proto cancel = (entry, event, function, shots)
*
* @param uint32 entry : opcode
* @param uint32 event : packet event Id, refer to PacketEvents above
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*
* @return function cancel : a function that cancels the binding when called
*/
int RegisterPacketEvent(lua_State* L)
{
return RegisterEntryHelper(L, Hooks::REGTYPE_PACKET);
}
/**
* Registers a [Creature] gossip event handler.
*
* <pre>
* enum GossipEvents
* {
* GOSSIP_EVENT_ON_HELLO = 1, // (event, player, object) - Object is the Creature/GameObject/Item. Can return false to do default action. For item gossip can return false to stop spell casting.
* GOSSIP_EVENT_ON_SELECT = 2, // (event, player, object, sender, intid, code, menu_id) - Object is the Creature/GameObject/Item/Player, menu_id is only for player gossip. Can return false to do default action.
* GOSSIP_EVENT_COUNT
* };
* </pre>
*
* @proto cancel = (entry, event, function)
* @proto cancel = (entry, event, function, shots)
*
* @param uint32 entry : [Creature] entry Id
* @param uint32 event : [Creature] gossip event Id, refer to GossipEvents above
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*
* @return function cancel : a function that cancels the binding when called
*/
int RegisterCreatureGossipEvent(lua_State* L)
{
return RegisterEntryHelper(L, Hooks::REGTYPE_CREATURE_GOSSIP);
}
/**
* Registers a [GameObject] gossip event handler.
*
* <pre>
* enum GossipEvents
* {
* GOSSIP_EVENT_ON_HELLO = 1, // (event, player, object) - Object is the Creature/GameObject/Item. Can return false to do default action. For item gossip can return false to stop spell casting.
* GOSSIP_EVENT_ON_SELECT = 2, // (event, player, object, sender, intid, code, menu_id) - Object is the Creature/GameObject/Item/Player, menu_id is only for player gossip. Can return false to do default action.
* GOSSIP_EVENT_COUNT
* };
* </pre>
*
* @proto cancel = (entry, event, function)
* @proto cancel = (entry, event, function, shots)
*
* @param uint32 entry : [GameObject] entry Id
* @param uint32 event : [GameObject] gossip event Id, refer to GossipEvents above
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*
* @return function cancel : a function that cancels the binding when called
*/
int RegisterGameObjectGossipEvent(lua_State* L)
{
return RegisterEntryHelper(L, Hooks::REGTYPE_GAMEOBJECT_GOSSIP);
}
/**
* Registers an [Item] event handler.
*
* <pre>
* enum ItemEvents
* {
* ITEM_EVENT_ON_DUMMY_EFFECT = 1, // (event, caster, spellid, effindex, item)
* ITEM_EVENT_ON_USE = 2, // (event, player, item, target) - Can return false to stop the spell casting
* ITEM_EVENT_ON_QUEST_ACCEPT = 3, // (event, player, item, quest) - Can return true
* ITEM_EVENT_ON_EXPIRE = 4, // (event, player, itemid) - Can return true
* ITEM_EVENT_ON_REMOVE = 5, // (event, player, item) - Can return true
* ITEM_EVENT_COUNT
* };
* </pre>
*
* @proto cancel = (entry, event, function)
* @proto cancel = (entry, event, function, shots)
*
* @param uint32 entry : [Item] entry Id
* @param uint32 event : [Item] event Id, refer to ItemEvents above
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*
* @return function cancel : a function that cancels the binding when called
*/
int RegisterItemEvent(lua_State* L)
{
return RegisterEntryHelper(L, Hooks::REGTYPE_ITEM);
}
/**
* Registers an [Item] gossip event handler.
*
* <pre>
* enum GossipEvents
* {
* GOSSIP_EVENT_ON_HELLO = 1, // (event, player, object) - Object is the Creature/GameObject/Item. Can return false to do default action. For item gossip can return false to stop spell casting.
* GOSSIP_EVENT_ON_SELECT = 2, // (event, player, object, sender, intid, code, menu_id) - Object is the Creature/GameObject/Item/Player, menu_id is only for player gossip. Can return false to do default action.
* GOSSIP_EVENT_COUNT
* };
* </pre>
*
* @proto cancel = (entry, event, function)
* @proto cancel = (entry, event, function, shots)
*
* @param uint32 entry : [Item] entry Id
* @param uint32 event : [Item] gossip event Id, refer to GossipEvents above
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*
* @return function cancel : a function that cancels the binding when called
*/
int RegisterItemGossipEvent(lua_State* L)
{
return RegisterEntryHelper(L, Hooks::REGTYPE_ITEM_GOSSIP);
}
/**
* Registers a [Map] event handler for all instance of a [Map].
*
* <pre>
* enum InstanceEvents
* {
* INSTANCE_EVENT_ON_INITIALIZE = 1, // (event, instance_data, map)
* INSTANCE_EVENT_ON_LOAD = 2, // (event, instance_data, map)
* INSTANCE_EVENT_ON_UPDATE = 3, // (event, instance_data, map, diff)
* INSTANCE_EVENT_ON_PLAYER_ENTER = 4, // (event, instance_data, map, player)
* INSTANCE_EVENT_ON_CREATURE_CREATE = 5, // (event, instance_data, map, creature)
* INSTANCE_EVENT_ON_GAMEOBJECT_CREATE = 6, // (event, instance_data, map, go)
* INSTANCE_EVENT_ON_CHECK_ENCOUNTER_IN_PROGRESS = 7, // (event, instance_data, map)
* INSTANCE_EVENT_COUNT
* };
* </pre>
*
* @param uint32 map_id : ID of a [Map]
* @param uint32 event : [Map] event ID, refer to MapEvents above
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*/
int RegisterMapEvent(lua_State* L)
{
return RegisterEntryHelper(L, Hooks::REGTYPE_MAP);
}
/**
* Registers a [Map] event handler for one instance of a [Map].
*
* <pre>
* enum InstanceEvents
* {
* INSTANCE_EVENT_ON_INITIALIZE = 1, // (event, instance_data, map)
* INSTANCE_EVENT_ON_LOAD = 2, // (event, instance_data, map)
* INSTANCE_EVENT_ON_UPDATE = 3, // (event, instance_data, map, diff)
* INSTANCE_EVENT_ON_PLAYER_ENTER = 4, // (event, instance_data, map, player)
* INSTANCE_EVENT_ON_CREATURE_CREATE = 5, // (event, instance_data, map, creature)
* INSTANCE_EVENT_ON_GAMEOBJECT_CREATE = 6, // (event, instance_data, map, go)
* INSTANCE_EVENT_ON_CHECK_ENCOUNTER_IN_PROGRESS = 7, // (event, instance_data, map)