Repository navigation
Expand file tree
/
Copy pathluascript.h
More file actions
749 lines (675 loc) · 29.9 KB
/
Copy pathluascript.h
File metadata and controls
749 lines (675 loc) · 29.9 KB
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
////////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
////////////////////////////////////////////////////////////////////////
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////
#ifndef __LUASCRIPT__
#define __LUASCRIPT__
#include "otsystem.h"
extern "C"
{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
#include "database.h"
#include "position.h"
enum LuaVariantType_t
{
VARIANT_NONE = 0,
VARIANT_NUMBER,
VARIANT_POSITION,
VARIANT_TARGETPOSITION,
VARIANT_STRING
};
struct LuaVariant
{
LuaVariant()
{
type = VARIANT_NONE;
text = "";
pos = PositionEx();
number = 0;
}
LuaVariantType_t type;
std::string text;
PositionEx pos;
uint32_t number;
};
class Game;
class Thing;
class LuaScriptInterface;
class Creature;
class Player;
class Npc;
class Item;
class Container;
class Combat;
class CombatArea;
class Condition;
struct Outfit_t;
class ScriptEnviroment
{
public:
ScriptEnviroment();
virtual ~ScriptEnviroment();
static bool saveGameState();
static bool loadGameState();
bool getStorage(const uint32_t key, std::string& value) const;
void setStorage(const uint32_t key, const std::string& value) {m_storageMap[key] = value;}
void eraseStorage(const uint32_t key) {m_storageMap.erase(key);}
int32_t getScriptId() {return m_scriptId;}
void setScriptId(int32_t scriptId, LuaScriptInterface* interface)
{m_scriptId = scriptId; m_interface = interface;}
int32_t getCallbackId() {return m_callbackId;}
bool setCallbackId(int32_t callbackId, LuaScriptInterface* interface);
std::string getEventDesc() {return m_eventdesc;}
void setEventDesc(const std::string& desc) {m_eventdesc = desc;}
Position getRealPos() {return m_realPos;}
void setRealPos(const Position& realPos) {m_realPos = realPos;}
Npc* getNpc() const {return m_curNpc;}
void setNpc(Npc* npc) {m_curNpc = npc;}
static uint32_t addCombatArea(CombatArea* area);
static CombatArea* getCombatArea(uint32_t areaId);
static uint32_t addCombatObject(Combat* combat);
static Combat* getCombatObject(uint32_t combatId);
static uint32_t addConditionObject(Condition* condition);
static Condition* getConditionObject(uint32_t conditionId);
Thing* getThingByUID(uint32_t uid);
Item* getItemByUID(uint32_t uid);
Container* getContainerByUID(uint32_t uid);
Creature* getCreatureByUID(uint32_t uid);
Player* getPlayerByUID(uint32_t uid);
uint32_t addThing(Thing* thing);
void insertThing(uint32_t uid, Thing* thing);
void removeThing(uint32_t uid);
static void addTempItem(ScriptEnviroment* env, Item* item);
static void removeTempItem(ScriptEnviroment* env, Item* item);
static void removeTempItem(Item* item);
DBResult* getResultByID(uint32_t id);
uint32_t addResult(DBResult* res);
bool removeResult(uint32_t id);
static void addUniqueThing(Thing* thing);
static void removeUniqueThing(Thing* thing);
static uint32_t getLastConditionId() {return m_lastConditionId;}
static uint32_t getLastCombatId() {return m_lastCombatId;}
static uint32_t getLastAreaId() {return m_lastAreaId;}
void setTimerEvent() {m_timerEvent = true;}
void resetTimerEvent() {m_timerEvent = false;}
LuaScriptInterface* getInterface() {return m_interface;}
void getInfo(int32_t& scriptId, std::string& desc, LuaScriptInterface*& interface, int32_t& callbackId, bool& timerEvent);
void reset();
void resetCallback() {m_callbackId = 0;}
void streamVariant(std::stringstream& stream, const std::string& local, const LuaVariant& var);
void streamThing(std::stringstream& stream, const std::string& local, Thing* thing, uint32_t id = 0);
void streamPosition(std::stringstream& stream, const std::string& local, const PositionEx& position)
{streamPosition(stream, local, position, position.stackpos);}
void streamPosition(std::stringstream& stream, const std::string& local, const Position& position, uint32_t stackpos);
void streamOutfit(std::stringstream& stream, const std::string& local, const Outfit_t& outfit);
private:
typedef std::map<uint64_t, Thing*> ThingMap;
typedef std::vector<const LuaVariant*> VariantVector;
typedef std::map<uint32_t, std::string> StorageMap;
typedef std::map<uint32_t, CombatArea*> AreaMap;
typedef std::map<uint32_t, Combat*> CombatMap;
typedef std::map<uint32_t, Condition*> ConditionMap;
typedef std::list<Item*> ItemList;
typedef std::map<ScriptEnviroment*, ItemList> TempItemListMap;
typedef std::map<uint32_t, DBResult*> DBResultMap;
LuaScriptInterface* m_interface;
int32_t m_scriptId, m_callbackId;
std::string m_eventdesc;
bool m_timerEvent;
ThingMap m_localMap;
DBResultMap m_tempResults;
static TempItemListMap m_tempItems;
static StorageMap m_storageMap;
static ThingMap m_globalMap;
static uint32_t m_lastAreaId;
static AreaMap m_areaMap;
static uint32_t m_lastCombatId;
static CombatMap m_combatMap;
static uint32_t m_lastConditionId;
static ConditionMap m_conditionMap;
int32_t m_lastUID;
bool m_loaded;
Position m_realPos;
Npc* m_curNpc;
};
enum ErrorCode_t
{
LUA_ERROR_PLAYER_NOT_FOUND,
LUA_ERROR_MONSTER_NOT_FOUND,
LUA_ERROR_NPC_NOT_FOUND,
LUA_ERROR_CREATURE_NOT_FOUND,
LUA_ERROR_ITEM_NOT_FOUND,
LUA_ERROR_THING_NOT_FOUND,
LUA_ERROR_TILE_NOT_FOUND,
LUA_ERROR_HOUSE_NOT_FOUND,
LUA_ERROR_COMBAT_NOT_FOUND,
LUA_ERROR_CONDITION_NOT_FOUND,
LUA_ERROR_AREA_NOT_FOUND,
LUA_ERROR_CONTAINER_NOT_FOUND,
LUA_ERROR_VARIANT_NOT_FOUND,
LUA_ERROR_VARIANT_UNKNOWN,
LUA_ERROR_SPELL_NOT_FOUND
};
#define errorEx(a) error(__FUNCTION__, a)
class LuaScriptInterface
{
public:
LuaScriptInterface(std::string interfaceName);
virtual ~LuaScriptInterface();
virtual bool initState();
bool reInitState();
static bool reserveEnv()
{
++m_scriptEnvIndex;
if(m_scriptEnvIndex > 20)
{
--m_scriptEnvIndex;
return false;
}
return true;
}
static void releaseEnv()
{
if(m_scriptEnvIndex >= 0)
{
m_scriptEnv[m_scriptEnvIndex].reset();
--m_scriptEnvIndex;
}
}
bool loadBuffer(const std::string& text, Npc* npc = NULL);
bool loadFile(const std::string& file, Npc* npc = NULL);
bool loadDirectory(const std::string& dir, Npc* npc = NULL);
std::string getName() {return m_interfaceName;}
std::string getScript(int32_t scriptId);
std::string getLastError() const {return m_lastError;}
int32_t getEvent(const std::string& eventName);
lua_State* getState() {return m_luaState;}
static ScriptEnviroment* getEnv()
{
assert(m_scriptEnvIndex >= 0 && m_scriptEnvIndex < 21);
return &m_scriptEnv[m_scriptEnvIndex];
}
bool pushFunction(int32_t functionId);
bool callFunction(uint32_t params);
static int32_t handleFunction(lua_State* L);
void dumpStack(lua_State* L = NULL);
//push/pop common structures
static void pushThing(lua_State* L, Thing* thing, uint32_t id = 0);
static void pushVariant(lua_State* L, const LuaVariant& var);
static void pushPosition(lua_State* L, const PositionEx& position) {pushPosition(L, position, position.stackpos);}
static void pushPosition(lua_State* L, const Position& position, uint32_t stackpos);
static void pushOutfit(lua_State* L, const Outfit_t& outfit);
static void pushCallback(lua_State* L, int32_t callback);
static LuaVariant popVariant(lua_State* L);
static void popPosition(lua_State* L, PositionEx& position);
static void popPosition(lua_State* L, Position& position, uint32_t& stackpos);
static bool popBoolean(lua_State* L);
static int64_t popNumber(lua_State* L);
static double popFloatNumber(lua_State* L);
static std::string popString(lua_State* L);
static int32_t popCallback(lua_State* L);
static Outfit_t popOutfit(lua_State* L);
static int64_t getField(lua_State* L, const char* key);
static uint64_t getFieldUnsigned(lua_State* L, const char* key);
static std::string getFieldString(lua_State* L, const char* key);
static bool getFieldBool(lua_State* L, const char* key);
static void setField(lua_State* L, const char* index, int32_t val);
static void setField(lua_State* L, const char* index, const std::string& val);
static void setFieldBool(lua_State* L, const char* index, bool val);
static void setFieldFloat(lua_State* L, const char* index, double val);
static void createTable(lua_State* L, const char* index);
static void createTable(lua_State* L, const char* index, int32_t narr, int32_t nrec);
static void createTable(lua_State* L, int32_t index);
static void createTable(lua_State* L, int32_t index, int32_t narr, int32_t nrec);
static void pushTable(lua_State* L);
static std::string getGlobalString(lua_State* L, const std::string& _identifier, const std::string& _default = "");
static bool getGlobalBool(lua_State* L, const std::string& _identifier, bool _default = false);
static int32_t getGlobalNumber(lua_State* L, const std::string& _identifier, const int32_t _default = 0);
static double getGlobalDouble(lua_State* L, const std::string& _identifier, const double _default = 0);
static void getValue(const std::string& key, lua_State* L, lua_State* _L);
static void moveValue(lua_State* from, lua_State* to);
static void error(const char* function, const std::string& desc);
protected:
virtual bool closeState();
static std::string getError(ErrorCode_t code);
static bool getArea(lua_State* L, std::list<uint32_t>& list, uint32_t& rows);
virtual void registerFunctions();
//lua functions
static int32_t luaDoRemoveItem(lua_State* L);
static int32_t luaDoFeedPlayer(lua_State* L);
static int32_t luaDoPlayerSendCancel(lua_State* L);
static int32_t luaDoSendDefaultCancel(lua_State* L);
static int32_t luaGetSearchString(lua_State* L);
static int32_t luaGetClosestFreeTile(lua_State* L);
static int32_t luaDoTeleportThing(lua_State* L);
static int32_t luaDoTransformItem(lua_State* L);
static int32_t luaDoSendMagicEffect(lua_State* L);
static int32_t luaDoSendAnimatedText(lua_State* L);
static int32_t luaDoSendDistanceShoot(lua_State* L);
static int32_t luaDoShowTextWindow(lua_State* L);
static int32_t luaDoShowTextDialog(lua_State* L);
static int32_t luaDoDecayItem(lua_State* L);
static int32_t luaDoCreateItem(lua_State* L);
static int32_t luaDoCreateItemEx(lua_State* L);
static int32_t luaDoCreateTeleport(lua_State* L);
static int32_t luaDoCreateMonster(lua_State* L);
static int32_t luaDoCreateNpc(lua_State* L);
static int32_t luaDoSummonMonster(lua_State* L);
static int32_t luaDoConvinceCreature(lua_State* L);
static int32_t luaGetMonsterTargetList(lua_State* L);
static int32_t luaGetMonsterFriendList(lua_State* L);
static int32_t luaDoMonsterSetTarget(lua_State* L);
static int32_t luaDoMonsterChangeTarget(lua_State* L);
static int32_t luaDoAddCondition(lua_State* L);
static int32_t luaDoRemoveCondition(lua_State* L);
static int32_t luaDoRemoveConditions(lua_State* L);
static int32_t luaDoRemoveCreature(lua_State* L);
static int32_t luaDoMoveCreature(lua_State* L);
static int32_t luaDoCreatureSay(lua_State* L);
static int32_t luaDoPlayerAddSkillTry(lua_State* L);
static int32_t luaDoCreatureAddHealth(lua_State* L);
static int32_t luaDoCreatureAddMana(lua_State* L);
static int32_t luaSetCreatureMaxHealth(lua_State* L);
static int32_t luaSetCreatureMaxMana(lua_State* L);
static int32_t luaDoPlayerSetMaxCapacity(lua_State* L);
static int32_t luaDoPlayerAddSpentMana(lua_State* L);
static int32_t luaDoPlayerAddItem(lua_State* L);
static int32_t luaDoPlayerAddItemEx(lua_State* L);
static int32_t luaDoTileAddItemEx(lua_State* L);
static int32_t luaDoAddContainerItemEx(lua_State* L);
static int32_t luaDoRelocate(lua_State* L);
static int32_t luaDoCleanTile(lua_State* L);
static int32_t luaDoPlayerSendTextMessage(lua_State* L);
static int32_t luaDoPlayerSendChannelMessage(lua_State* L);
static int32_t luaDoPlayerSendToChannel(lua_State* L);
static int32_t luaDoPlayerAddMoney(lua_State* L);
static int32_t luaDoPlayerRemoveMoney(lua_State* L);
static int32_t luaDoPlayerTransferMoneyTo(lua_State* L);
static int32_t luaDoPlayerSetPzLocked(lua_State* L);
static int32_t luaDoPlayerSetTown(lua_State* L);
static int32_t luaDoPlayerSetVocation(lua_State* L);
static int32_t luaDoPlayerRemoveItem(lua_State* L);
static int32_t luaDoPlayerAddSoul(lua_State* L);
static int32_t luaDoPlayerAddStamina(lua_State* L);
static int32_t luaDoPlayerSetStamina(lua_State* L);
static int32_t luaDoPlayerAddExperience(lua_State* L);
static int32_t luaDoPlayerSetGuildId(lua_State* L);
static int32_t luaDoPlayerSetGuildLevel(lua_State* L);
static int32_t luaDoPlayerSetGuildNick(lua_State* L);
static int32_t luaDoPlayerSetSex(lua_State* L);
static int32_t luaDoPlayerSetIdleTime(lua_State* L);
static int32_t luaGetPlayerIdleTime(lua_State* L);
static int32_t luaDoSetCreatureLight(lua_State* L);
static int32_t luaDoCreatureSetLookDir(lua_State* L);
static int32_t luaGetCreatureHideHealth(lua_State* L);
static int32_t luaDoCreatureSetHideHealth(lua_State* L);
static int32_t luaGetCreatureSpeakType(lua_State* L);
static int32_t luaDoCreatureSetSpeakType(lua_State* L);
static int32_t luaGetCreatureSkullType(lua_State* L);
static int32_t luaDoCreatureSetSkullType(lua_State* L);
static int32_t luaGetPlayerSkullEnd(lua_State* L);
static int32_t luaDoPlayerSetSkullEnd(lua_State* L);
static int32_t luaDoPlayerSwitchSaving(lua_State* L);
static int32_t luaDoPlayerSave(lua_State* L);
static int32_t luaDoPlayerSendOutfitWindow(lua_State* L);
static int32_t luaDoCreatureExecuteTalkAction(lua_State* L);
static int32_t luaGetCreatureByName(lua_State* L);
static int32_t luaGetPlayerByGUID(lua_State* L);
static int32_t luaGetPlayerByNameWildcard(lua_State* L);
static int32_t luaGetPlayerGUIDByName(lua_State* L);
static int32_t luaGetPlayerNameByGUID(lua_State* L);
static int32_t luaGetPlayersByAccountId(lua_State* L);
static int32_t luaGetAccountIdByName(lua_State* L);
static int32_t luaGetAccountByName(lua_State* L);
static int32_t luaGetAccountIdByAccount(lua_State* L);
static int32_t luaGetAccountByAccountId(lua_State* L);
static int32_t luaGetIpByName(lua_State* L);
static int32_t luaGetPlayersByIp(lua_State* L);
static int32_t luaIsIpBanished(lua_State* L);
static int32_t luaIsPlayerBanished(lua_State* L);
static int32_t luaIsAccountBanished(lua_State* L);
static int32_t luaDoAddIpBanishment(lua_State* L);
static int32_t luaDoAddPlayerBanishment(lua_State* L);
static int32_t luaDoAddAccountBanishment(lua_State* L);
static int32_t luaDoAddNotation(lua_State* L);
static int32_t luaDoAddStatement(lua_State* L);
static int32_t luaDoRemoveIpBanishment(lua_State* L);
static int32_t luaDoRemovePlayerBanishment(lua_State* L);
static int32_t luaDoRemoveAccountBanishment(lua_State* L);
static int32_t luaDoRemoveNotations(lua_State* L);
static int32_t luaDoRemoveStatements(lua_State* L);
static int32_t luaGetNotationsCount(lua_State* L);
static int32_t luaGetStatementsCount(lua_State* L);
static int32_t luaGetBanData(lua_State* L);
static int32_t luaGetBanReason(lua_State* L);
static int32_t luaGetBanAction(lua_State* L);
static int32_t luaGetBanList(lua_State* L);
static int32_t luaGetPlayerRates(lua_State* L);
static int32_t luaDoPlayerSetRate(lua_State* L);
static int32_t luaDoCreatureSetDropLoot(lua_State* L);
static int32_t luaGetPlayerLossPercent(lua_State* L);
static int32_t luaDoPlayerSetLossPercent(lua_State* L);
static int32_t luaDoPlayerSetLossSkill(lua_State* L);
static int32_t luaGetPlayerLossSkill(lua_State* L);
static int32_t luaGetThing(lua_State* L);
static int32_t luaGetThingPosition(lua_State* L);
static int32_t luaDoItemRaidUnref(lua_State* L);
static int32_t luaHasItemProperty(lua_State* L);
static int32_t luaGetThingFromPos(lua_State* L);
static int32_t luaGetTileItemById(lua_State* L);
static int32_t luaGetTileItemByType(lua_State* L);
static int32_t luaGetTileThingByPos(lua_State* L);
static int32_t luaGetTopCreature(lua_State* L);
static int32_t luaGetTileInfo(lua_State* L);
static int32_t luaDoTileQueryAdd(lua_State* L);
static int32_t luaGetHouseInfo(lua_State* L);
static int32_t luaGetHouseAccessList(lua_State* L);
static int32_t luaGetHouseByPlayerGUID(lua_State* L);
static int32_t luaGetHouseFromPos(lua_State* L);
static int32_t luaSetHouseOwner(lua_State* L);
static int32_t luaSetHouseAccessList(lua_State* L);
static int32_t luaDoPlayerSetNameDescription(lua_State* L);
static int32_t luaGetPlayerNameDescription(lua_State* L);
static int32_t luaDoPlayerSetSpecialDescription(lua_State* L);
static int32_t luaGetPlayerSpecialDescription(lua_State* L);
static int32_t luaGetPlayerFood(lua_State* L);
static int32_t luaGetPlayerAccess(lua_State* L);
static int32_t luaGetPlayerGhostAccess(lua_State* L);
static int32_t luaGetPlayerLevel(lua_State* L);
static int32_t luaGetPlayerExperience(lua_State* L);
static int32_t luaGetPlayerMagLevel(lua_State* L);
static int32_t luaGetPlayerSpentMana(lua_State* L);
static int32_t luaGetCreatureMana(lua_State* L);
static int32_t luaGetCreatureMaxMana(lua_State* L);
static int32_t luaGetCreatureHealth(lua_State* L);
static int32_t luaGetCreatureMaxHealth(lua_State* L);
static int32_t luaGetCreatureSpeed(lua_State* L);
static int32_t luaGetCreatureBaseSpeed(lua_State* L);
static int32_t luaGetCreatureTarget(lua_State* L);
static int32_t luaGetCreatureLookDirection(lua_State* L);
static int32_t luaGetPlayerSkillLevel(lua_State* L);
static int32_t luaGetPlayerSkillTries(lua_State* L);
static int32_t luaGetPlayerVocation(lua_State* L);
static int32_t luaGetPlayerTown(lua_State* L);
static int32_t luaGetPlayerItemCount(lua_State* L);
static int32_t luaGetPlayerMoney(lua_State* L);
static int32_t luaGetPlayerSoul(lua_State* L);
static int32_t luaGetPlayerStamina(lua_State* L);
static int32_t luaGetPlayerFreeCap(lua_State* L);
static int32_t luaGetPlayerLight(lua_State* L);
static int32_t luaGetPlayerSlotItem(lua_State* L);
static int32_t luaGetPlayerWeapon(lua_State* L);
static int32_t luaGetPlayerItemById(lua_State* L);
static int32_t luaGetPlayerRequiredMana(lua_State* L);
static int32_t luaGetPlayerRequiredSkillTries(lua_State* L);
static int32_t luaGetPlayerIp(lua_State* L);
static int32_t luaGetPlayerLastLoad(lua_State* L);
static int32_t luaGetPlayerLastLogin(lua_State* L);
static int32_t luaGetPlayerAccountManager(lua_State* L);
static int32_t luaGetPlayerAccountId(lua_State* L);
static int32_t luaGetPlayerAccount(lua_State* L);
static int32_t luaGetPlayerDepotItems(lua_State* L);
static int32_t luaGetPlayerGuildId(lua_State* L);
static int32_t luaGetPlayerGuildName(lua_State* L);
static int32_t luaGetPlayerGuildRank(lua_State* L);
static int32_t luaGetPlayerGuildRankId(lua_State* L);
static int32_t luaGetPlayerGuildLevel(lua_State* L);
static int32_t luaGetPlayerGuildNick(lua_State* L);
static int32_t luaGetPlayerSex(lua_State* L);
static int32_t luaGetPlayerGUID(lua_State* L);
static int32_t luaGetPlayerFlagValue(lua_State* L);
static int32_t luaGetPlayerCustomFlagValue(lua_State* L);
static int32_t luaGetCreatureCondition(lua_State* L);
static int32_t luaHasPlayerClient(lua_State* L);
static int32_t luaGetDepotId(lua_State* L);
static int32_t luaGetVocationInfo(lua_State* L);
static int32_t luaGetGroupInfo(lua_State* L);
static int32_t luaGetMonsterInfo(lua_State* L);
static int32_t luaGetPlayerPromotionLevel(lua_State* L);
static int32_t luaDoPlayerSetPromotionLevel(lua_State* L);
static int32_t luaGetPlayerGroupId(lua_State* L);
static int32_t luaDoPlayerSetGroupId(lua_State* L);
static int32_t luaDoPlayerLearnInstantSpell(lua_State* L);
static int32_t luaDoPlayerUnlearnInstantSpell(lua_State* L);
static int32_t luaGetPlayerLearnedInstantSpell(lua_State* L);
static int32_t luaGetPlayerInstantSpellCount(lua_State* L);
static int32_t luaGetPlayerInstantSpellInfo(lua_State* L);
static int32_t luaGetInstantSpellInfo(lua_State* L);
static int32_t luaGetPlayerPartner(lua_State* L);
static int32_t luaDoPlayerSetPartner(lua_State* L);
static int32_t luaGetPlayerParty(lua_State* L);
static int32_t luaDoPlayerJoinParty(lua_State* L);
static int32_t luaGetPartyMembers(lua_State* L);
static int32_t luaGetCreatureStorage(lua_State* L);
static int32_t luaDoCreatureSetStorage(lua_State* L);
static int32_t luaDoPlayerAddBlessing(lua_State* L);
static int32_t luaGetPlayerBlessing(lua_State* L);
static int32_t luaGetStorage(lua_State* L);
static int32_t luaDoSetStorage(lua_State* L);
static int32_t luaDoPlayerAddOutfit(lua_State* L);
static int32_t luaDoPlayerRemoveOutfit(lua_State* L);
static int32_t luaDoPlayerAddOutfitId(lua_State* L);
static int32_t luaDoPlayerRemoveOutfitId(lua_State* L);
static int32_t luaCanPlayerWearOutfit(lua_State* L);
static int32_t luaCanPlayerWearOutfitId(lua_State* L);
static int32_t luaGetWorldType(lua_State* L);
static int32_t luaSetWorldType(lua_State* L);
static int32_t luaGetWorldTime(lua_State* L);
static int32_t luaGetWorldLight(lua_State* L);
static int32_t luaGetWorldCreatures(lua_State* L);
static int32_t luaGetWorldUpTime(lua_State* L);
static int32_t luaGetGuildId(lua_State* L);
static int32_t luaGetGuildMotd(lua_State* L);
static int32_t luaIsPlayerPzLocked(lua_State* L);
static int32_t luaIsPlayerSaving(lua_State* L);
static int32_t luaIsCreature(lua_State* L);
static int32_t luaIsContainer(lua_State* L);
static int32_t luaIsMovable(lua_State* L);
static int32_t luaGetContainerSize(lua_State* L);
static int32_t luaGetContainerCap(lua_State* L);
static int32_t luaGetContainerItem(lua_State* L);
static int32_t luaDoAddContainerItem(lua_State* L);
static int32_t luaCreateCombatObject(lua_State* L);
static int32_t luaCreateCombatArea(lua_State* L);
static int32_t luaSetCombatArea(lua_State* L);
static int32_t luaSetCombatCondition(lua_State* L);
static int32_t luaSetCombatParam(lua_State* L);
static int32_t luaCreateConditionObject(lua_State* L);
static int32_t luaSetConditionParam(lua_State* L);
static int32_t luaAddDamageCondition(lua_State* L);
static int32_t luaAddOutfitCondition(lua_State* L);
static int32_t luaSetCombatCallBack(lua_State* L);
static int32_t luaSetCombatFormula(lua_State* L);
static int32_t luaSetConditionFormula(lua_State* L);
static int32_t luaDoCombat(lua_State* L);
static int32_t luaDoCombatAreaHealth(lua_State* L);
static int32_t luaDoTargetCombatHealth(lua_State* L);
static int32_t luaDoCombatAreaMana(lua_State* L);
static int32_t luaDoTargetCombatMana(lua_State* L);
static int32_t luaDoCombatAreaCondition(lua_State* L);
static int32_t luaDoTargetCombatCondition(lua_State* L);
static int32_t luaDoCombatAreaDispel(lua_State* L);
static int32_t luaDoTargetCombatDispel(lua_State* L);
static int32_t luaDoChallengeCreature(lua_State* L);
static int32_t luaNumberToVariant(lua_State* L);
static int32_t luaStringToVariant(lua_State* L);
static int32_t luaPositionToVariant(lua_State* L);
static int32_t luaTargetPositionToVariant(lua_State* L);
static int32_t luaVariantToNumber(lua_State* L);
static int32_t luaVariantToString(lua_State* L);
static int32_t luaVariantToPosition(lua_State* L);
static int32_t luaDoChangeSpeed(lua_State* L);
static int32_t luaGetExperienceStage(lua_State* L);
static int32_t luaDoCreatureChangeOutfit(lua_State* L);
static int32_t luaSetCreatureOutfit(lua_State* L);
static int32_t luaGetCreatureOutfit(lua_State* L);
static int32_t luaSetMonsterOutfit(lua_State* L);
static int32_t luaSetItemOutfit(lua_State* L);
static int32_t luaGetCreatureLastPosition(lua_State* L);
static int32_t luaGetCreatureName(lua_State* L);
static int32_t luaGetCreatureMaster(lua_State* L);
static int32_t luaGetCreatureSummons(lua_State* L);
static int32_t luaGetHighscoreString(lua_State* L);
static int32_t luaIsSightClear(lua_State* L);
static int32_t luaIsInArray(lua_State* L);
static int32_t luaAddEvent(lua_State* L);
static int32_t luaStopEvent(lua_State* L);
static int32_t luaRegisterCreatureEvent(lua_State* L);
static int32_t luaGetPlayerBalance(lua_State* L);
static int32_t luaDoPlayerSetBalance(lua_State* L);
static int32_t luaDoPlayerPopupFYI(lua_State* L);
static int32_t luaDoPlayerSendTutorial(lua_State* L);
static int32_t luaDoPlayerSendMailByName(lua_State* L);
static int32_t luaDoPlayerAddMapMark(lua_State* L);
static int32_t luaGetPlayerPremiumDays(lua_State* L);
static int32_t luaDoPlayerAddPremiumDays(lua_State* L);
static int32_t luaGetCreatureNoMove(lua_State* L);
static int32_t luaDoCreatureSetNoMove(lua_State* L);
static int32_t luaGetTownId(lua_State* L);
static int32_t luaGetTownName(lua_State* L);
static int32_t luaGetTownTemplePosition(lua_State* L);
static int32_t luaGetTownHouses(lua_State* L);
static int32_t luaGetSpectators(lua_State* L);
static int32_t luaGetGameState(lua_State* L);
static int32_t luaDoSetGameState(lua_State* L);
static int32_t luaGetChannelUsers(lua_State* L);
static int32_t luaGetPlayersOnline(lua_State* L);
static int32_t luaDoExecuteRaid(lua_State* L);
static int32_t luaDoReloadInfo(lua_State* L);
static int32_t luaDoSaveServer(lua_State* L);
static int32_t luaDoCleanHouse(lua_State* L);
static int32_t luaDoCleanMap(lua_State* L);
static int32_t luaDoRefreshMap(lua_State* L);
static int32_t luaDoUpdateHouseAuctions(lua_State* L);
static int32_t luaGetItemIdByName(lua_State* L);
static int32_t luaGetItemInfo(lua_State* L);
static int32_t luaGetItemWeight(lua_State* L);
static int32_t luaGetItemAttribute(lua_State* L);
static int32_t luaDoItemSetAttribute(lua_State* L);
static int32_t luaDoItemEraseAttribute(lua_State* L);
static int32_t luaGetTalkActionList(lua_State* L);
static int32_t luaGetExperienceStageList(lua_State* L);
static int32_t luaGetWaypointList(lua_State* L);
static int32_t luaGetWaypointPosition(lua_State* L);
static int32_t luaDoWaypointAddTemporial(lua_State* L);
static int32_t luaGetDataDir(lua_State* L);
static int32_t luaGetLogsDir(lua_State* L);
static int32_t luaGetConfigFile(lua_State* L);
static int32_t luaGetConfigValue(lua_State* L);
static int32_t luaGetModList(lua_State* L);
static int32_t luaL_loadmodlib(lua_State* L);
static int32_t luaL_domodlib(lua_State* L);
static int32_t luaL_dodirectory(lua_State* L);
static const luaL_Reg luaDatabaseTable[8];
static int32_t luaDatabaseExecute(lua_State* L);
static int32_t luaDatabaseStoreQuery(lua_State* L);
static int32_t luaDatabaseEscapeString(lua_State* L);
static int32_t luaDatabaseEscapeBlob(lua_State* L);
static int32_t luaDatabaseLastInsertId(lua_State* L);
static int32_t luaDatabaseStringComparison(lua_State* L);
static int32_t luaDatabaseUpdateLimiter(lua_State* L);
static const luaL_Reg luaResultTable[7];
static int32_t luaResultGetDataInt(lua_State* L);
static int32_t luaResultGetDataLong(lua_State* L);
static int32_t luaResultGetDataString(lua_State* L);
static int32_t luaResultGetDataStream(lua_State* L);
static int32_t luaResultNext(lua_State* L);
static int32_t luaResultFree(lua_State* L);
static const luaL_Reg luaBitTable[13];
static int32_t luaBitNot(lua_State* L);
static int32_t luaBitAnd(lua_State* L);
static int32_t luaBitOr(lua_State* L);
static int32_t luaBitXor(lua_State* L);
static int32_t luaBitLeftShift(lua_State* L);
static int32_t luaBitRightShift(lua_State* L);
static int32_t luaBitUNot(lua_State* L);
static int32_t luaBitUAnd(lua_State* L);
static int32_t luaBitUOr(lua_State* L);
static int32_t luaBitUXor(lua_State* L);
static int32_t luaBitULeftShift(lua_State* L);
static int32_t luaBitURightShift(lua_State* L);
static const luaL_Reg luaStdTable[6];
static int32_t luaStdCout(lua_State* L);
static int32_t luaStdCerr(lua_State* L);
static int32_t luaStdClog(lua_State* L);
static int32_t luaStdMD5(lua_State* L);
static int32_t luaStdSHA1(lua_State* L);
lua_State* m_luaState;
std::string m_lastError;
private:
void executeTimer(uint32_t eventIndex);
enum PlayerInfo_t
{
PlayerInfoFood,
PlayerInfoAccess,
PlayerInfoGhostAccess,
PlayerInfoLevel,
PlayerInfoExperience,
PlayerInfoManaSpent,
PlayerInfoVocation,
PlayerInfoTown,
PlayerInfoPromotionLevel,
PlayerInfoSoul,
PlayerInfoFreeCap,
PlayerInfoGuildId,
PlayerInfoGuildName,
PlayerInfoGuildRankId,
PlayerInfoGuildRank,
PlayerInfoGuildLevel,
PlayerInfoGuildNick,
PlayerInfoGroupId,
PlayerInfoGUID,
PlayerInfoAccountId,
PlayerInfoAccount,
PlayerInfoPremiumDays,
PlayerInfoBalance,
PlayerInfoStamina,
PlayerInfoLossSkill,
PlayerInfoMarriage,
PlayerInfoPzLock,
PlayerInfoSaving,
PlayerInfoIp,
PlayerInfoSkullEnd,
PlayerInfoOutfitWindow,
PlayerInfoNameDescription,
PlayerInfoSpecialDescription,
PlayerInfoIdleTime,
PlayerInfoClient,
PlayerInfoLastLoad,
PlayerInfoLastLogin,
PlayerInfoAccountManager
};
static int32_t internalGetPlayerInfo(lua_State* L, PlayerInfo_t info);
int32_t m_runningEventId;
uint32_t m_lastEventTimerId;
std::string m_loadingFile, m_interfaceName;
static ScriptEnviroment m_scriptEnv[21];
static int32_t m_scriptEnvIndex;
//events information
struct LuaTimerEvent
{
int32_t scriptId, function;
std::list<int32_t> parameters;
};
typedef std::map<uint32_t , LuaTimerEvent > LuaTimerEvents;
LuaTimerEvents m_timerEvents;
//script file cache
typedef std::map<int32_t , std::string> ScriptsCache;
ScriptsCache m_cacheFiles;
};
#endif