Advertisement
Guest User

Untitled

a guest
Feb 18th, 2024
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.61 KB | None | 0 0
  1. TRUE = true
  2. FALSE = false
  3.  
  4. result.getDataInt = result.getNumber
  5. result.getDataLong = result.getNumber
  6. result.getDataString = result.getString
  7. result.getDataStream = result.getStream
  8.  
  9. LUA_ERROR = false
  10. LUA_NO_ERROR = true
  11.  
  12. STACKPOS_GROUND = 0
  13. STACKPOS_FIRST_ITEM_ABOVE_GROUNDTILE = 1
  14. STACKPOS_SECOND_ITEM_ABOVE_GROUNDTILE = 2
  15. STACKPOS_THIRD_ITEM_ABOVE_GROUNDTILE = 3
  16. STACKPOS_FOURTH_ITEM_ABOVE_GROUNDTILE = 4
  17. STACKPOS_FIFTH_ITEM_ABOVE_GROUNDTILE = 5
  18. STACKPOS_TOP_CREATURE = 253
  19. STACKPOS_TOP_FIELD = 254
  20. STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE = 255
  21.  
  22. THING_TYPE_PLAYER = CREATURETYPE_PLAYER + 1
  23. THING_TYPE_MONSTER = CREATURETYPE_MONSTER + 1
  24. THING_TYPE_NPC = CREATURETYPE_NPC + 1
  25.  
  26. COMBAT_POISONDAMAGE = COMBAT_EARTHDAMAGE
  27. CONDITION_EXHAUST = CONDITION_EXHAUST_WEAPON
  28. TALKTYPE_ORANGE_1 = TALKTYPE_MONSTER_SAY
  29. TALKTYPE_ORANGE_2 = TALKTYPE_MONSTER_YELL
  30.  
  31. NORTH = DIRECTION_NORTH
  32. EAST = DIRECTION_EAST
  33. SOUTH = DIRECTION_SOUTH
  34. WEST = DIRECTION_WEST
  35. SOUTHWEST = DIRECTION_SOUTHWEST
  36. SOUTHEAST = DIRECTION_SOUTHEAST
  37. NORTHWEST = DIRECTION_NORTHWEST
  38. NORTHEAST = DIRECTION_NORTHEAST
  39.  
  40. do
  41. local function storageProxy(player)
  42. return setmetatable({}, {
  43. __index = function (self, key)
  44. return player:getStorageValue(key)
  45. end,
  46. __newindex = function (self, key, value)
  47. player:setStorageValue(key, value)
  48. end
  49. })
  50. end
  51.  
  52. local function accountStorageProxy(player)
  53. return setmetatable({}, {
  54. __index = function (self, key)
  55. return Game.getAccountStorageValue(player:getAccountId(), key)
  56. end,
  57. __newindex = function (self, key, value)
  58. Game.setAccountStorageValue(player:getAccountId(), key, value)
  59. end
  60. })
  61. end
  62.  
  63. local function CreatureIndex(self, key)
  64. local methods = getmetatable(self)
  65. if key == "uid" then
  66. return methods.getId(self)
  67. elseif key == "type" then
  68. local creatureType = 0
  69. if methods.isPlayer(self) then
  70. creatureType = THING_TYPE_PLAYER
  71. elseif methods.isMonster(self) then
  72. creatureType = THING_TYPE_MONSTER
  73. elseif methods.isNpc(self) then
  74. creatureType = THING_TYPE_NPC
  75. end
  76. return creatureType
  77. elseif key == "itemid" then
  78. return 1
  79. elseif key == "actionid" then
  80. return 0
  81. elseif key == "storage" then
  82. if methods.isPlayer(self) then
  83. return storageProxy(self)
  84. end
  85. elseif key == "accountStorage" then
  86. if methods.isPlayer(self) then
  87. return accountStorageProxy(self)
  88. end
  89. end
  90.  
  91. return methods[key]
  92. end
  93. rawgetmetatable("Player").__index = CreatureIndex
  94. rawgetmetatable("Monster").__index = CreatureIndex
  95. rawgetmetatable("Npc").__index = CreatureIndex
  96. end
  97.  
  98. do
  99. local function ItemIndex(self, key)
  100. local methods = getmetatable(self)
  101. if key == "itemid" then
  102. return methods.getId(self)
  103. elseif key == "actionid" then
  104. return methods.getActionId(self)
  105. elseif key == "uid" then
  106. return methods.getUniqueId(self)
  107. elseif key == "type" then
  108. return methods.getSubType(self)
  109. end
  110. return methods[key]
  111. end
  112. rawgetmetatable("Item").__index = ItemIndex
  113. rawgetmetatable("Container").__index = ItemIndex
  114. rawgetmetatable("Teleport").__index = ItemIndex
  115. end
  116.  
  117. do
  118. local function ActionNewIndex(self, key, value)
  119. if key == "onUse" then
  120. self:onUse(value)
  121. return
  122. end
  123. rawset(self, key, value)
  124. end
  125. rawgetmetatable("Action").__newindex = ActionNewIndex
  126. end
  127.  
  128. do
  129. local function TalkActionNewIndex(self, key, value)
  130. if key == "onSay" then
  131. self:onSay(value)
  132. return
  133. end
  134. rawset(self, key, value)
  135. end
  136. rawgetmetatable("TalkAction").__newindex = TalkActionNewIndex
  137. end
  138.  
  139. do
  140. local function CreatureEventNewIndex(self, key, value)
  141. if key == "onLogin" then
  142. self:type("login")
  143. self:onLogin(value)
  144. return
  145. elseif key == "onLogout" then
  146. self:type("logout")
  147. self:onLogout(value)
  148. return
  149. elseif key == "onThink" then
  150. self:type("think")
  151. self:onThink(value)
  152. return
  153. elseif key == "onPrepareDeath" then
  154. self:type("preparedeath")
  155. self:onPrepareDeath(value)
  156. return
  157. elseif key == "onDeath" then
  158. self:type("death")
  159. self:onDeath(value)
  160. return
  161. elseif key == "onKill" then
  162. self:type("kill")
  163. self:onKill(value)
  164. return
  165. elseif key == "onAdvance" then
  166. self:type("advance")
  167. self:onAdvance(value)
  168. return
  169. elseif key == "onModalWindow" then
  170. self:type("modalwindow")
  171. self:onModalWindow(value)
  172. return
  173. elseif key == "onTextEdit" then
  174. self:type("textedit")
  175. self:onTextEdit(value)
  176. return
  177. elseif key == "onHealthChange" then
  178. self:type("healthchange")
  179. self:onHealthChange(value)
  180. return
  181. elseif key == "onManaChange" then
  182. self:type("manachange")
  183. self:onManaChange(value)
  184. return
  185. elseif key == "onExtendedOpcode" then
  186. self:type("extendedopcode")
  187. self:onExtendedOpcode(value)
  188. return
  189. end
  190. rawset(self, key, value)
  191. end
  192. rawgetmetatable("CreatureEvent").__newindex = CreatureEventNewIndex
  193. end
  194.  
  195. do
  196. local function MoveEventNewIndex(self, key, value)
  197. if key == "onEquip" then
  198. self:type("equip")
  199. self:onEquip(value)
  200. return
  201. elseif key == "onDeEquip" then
  202. self:type("deequip")
  203. self:onDeEquip(value)
  204. return
  205. elseif key == "onAddItem" then
  206. self:type("additem")
  207. self:onAddItem(value)
  208. return
  209. elseif key == "onRemoveItem" then
  210. self:type("removeitem")
  211. self:onRemoveItem(value)
  212. return
  213. elseif key == "onStepIn" then
  214. self:type("stepin")
  215. self:onStepIn(value)
  216. return
  217. elseif key == "onStepOut" then
  218. self:type("stepout")
  219. self:onStepOut(value)
  220. return
  221. end
  222. rawset(self, key, value)
  223. end
  224. rawgetmetatable("MoveEvent").__newindex = MoveEventNewIndex
  225. end
  226.  
  227. do
  228. local function GlobalEventNewIndex(self, key, value)
  229. if key == "onThink" then
  230. self:onThink(value)
  231. return
  232. elseif key == "onTime" then
  233. self:onTime(value)
  234. return
  235. elseif key == "onStartup" then
  236. self:type("startup")
  237. self:onStartup(value)
  238. return
  239. elseif key == "onShutdown" then
  240. self:type("shutdown")
  241. self:onShutdown(value)
  242. return
  243. elseif key == "onRecord" then
  244. self:type("record")
  245. self:onRecord(value)
  246. return
  247. end
  248. rawset(self, key, value)
  249. end
  250. rawgetmetatable("GlobalEvent").__newindex = GlobalEventNewIndex
  251. end
  252.  
  253. do
  254. local function WeaponNewIndex(self, key, value)
  255. if key == "onUseWeapon" then
  256. self:onUseWeapon(value)
  257. return
  258. end
  259. rawset(self, key, value)
  260. end
  261. rawgetmetatable("Weapon").__newindex = WeaponNewIndex
  262. end
  263.  
  264. do
  265. local function SpellNewIndex(self, key, value)
  266. if key == "onCastSpell" then
  267. self:onCastSpell(value)
  268. return
  269. end
  270. rawset(self, key, value)
  271. end
  272. rawgetmetatable("Spell").__newindex = SpellNewIndex
  273. end
  274.  
  275. do
  276. local function MonsterTypeNewIndex(self, key, value)
  277. if key == "onThink" then
  278. self:eventType(MONSTERS_EVENT_THINK)
  279. self:onThink(value)
  280. return
  281. elseif key == "onAppear" then
  282. self:eventType(MONSTERS_EVENT_APPEAR)
  283. self:onAppear(value)
  284. return
  285. elseif key == "onDisappear" then
  286. self:eventType(MONSTERS_EVENT_DISAPPEAR)
  287. self:onDisappear(value)
  288. return
  289. elseif key == "onMove" then
  290. self:eventType(MONSTERS_EVENT_MOVE)
  291. self:onMove(value)
  292. return
  293. elseif key == "onSay" then
  294. self:eventType(MONSTERS_EVENT_SAY)
  295. self:onSay(value)
  296. return
  297. end
  298. rawset(self, key, value)
  299. end
  300. rawgetmetatable("MonsterType").__newindex = MonsterTypeNewIndex
  301. end
  302.  
  303. function pushThing(thing)
  304. local t = {uid = 0, itemid = 0, type = 0, actionid = 0}
  305. if thing then
  306. if thing:isItem() then
  307. t.uid = thing:getUniqueId()
  308. t.itemid = thing:getId()
  309. if ItemType(t.itemid):hasSubType() then
  310. t.type = thing:getSubType()
  311. end
  312. t.actionid = thing:getActionId()
  313. elseif thing:isCreature() then
  314. t.uid = thing:getId()
  315. t.itemid = 1
  316. if thing:isPlayer() then
  317. t.type = THING_TYPE_PLAYER
  318. elseif thing:isMonster() then
  319. t.type = THING_TYPE_MONSTER
  320. else
  321. t.type = THING_TYPE_NPC
  322. end
  323. end
  324. end
  325. return t
  326. end
  327.  
  328. createCombatObject = Combat
  329. addCombatCondition = Combat.addCondition
  330. setCombatArea = Combat.setArea
  331. setCombatCallback = Combat.setCallback
  332. setCombatFormula = Combat.setFormula
  333. setCombatParam = Combat.setParameter
  334.  
  335. Combat.setCondition = function(...)
  336. print("[Warning - " .. debug.getinfo(2).source:match("@?(.*)") .. "] Function Combat.setCondition was renamed to Combat.addCondition and will be removed in the future")
  337. Combat.addCondition(...)
  338. end
  339.  
  340. setCombatCondition = function(...)
  341. print("[Warning - " .. debug.getinfo(2).source:match("@?(.*)") .. "] Function setCombatCondition was renamed to addCombatCondition and will be removed in the future")
  342. Combat.addCondition(...)
  343. end
  344.  
  345. function doTargetCombatHealth(...) return doTargetCombat(...) end
  346. function doAreaCombatHealth(...) return doAreaCombat(...) end
  347. doCombatAreaHealth = doAreaCombatHealth
  348. function doTargetCombatMana(cid, target, min, max, effect) return doTargetCombat(cid, target, COMBAT_MANADRAIN, min, max, effect) end
  349. doCombatAreaMana = doTargetCombatMana
  350. function doAreaCombatMana(cid, pos, area, min, max, effect) return doAreaCombat(cid, COMBAT_MANADRAIN, pos, area, min, max, effect) end
  351.  
  352. createConditionObject = Condition
  353. setConditionParam = Condition.setParameter
  354. setConditionFormula = Condition.setFormula
  355. addDamageCondition = Condition.addDamage
  356. addOutfitCondition = Condition.setOutfit
  357.  
  358. function doCombat(cid, combat, var) return combat:execute(cid, var) end
  359.  
  360. function isCreature(cid) return Creature(cid) end
  361. function isPlayer(cid) return Player(cid) end
  362. function isMonster(cid) return Monster(cid) end
  363. function isSummon(cid) local c = Creature(cid) return c and c:getMaster() end
  364. function isNpc(cid) return Npc(cid) end
  365. function isItem(uid) return Item(uid) end
  366. function isContainer(uid) return Container(uid) end
  367.  
  368. function getCreatureName(cid) local c = Creature(cid) return c and c:getName() or false end
  369. function getCreatureStorage(uid, key) local c = Creature(uid) return c and c:getStorageValue(key) or false end
  370. function getCreatureHealth(cid) local c = Creature(cid) return c and c:getHealth() or false end
  371. function getCreatureMaxHealth(cid) local c = Creature(cid) return c and c:getMaxHealth() or false end
  372. function getCreatureMana(cid) local c = Creature(cid) return c and c:getMana() or false end
  373. function getCreatureMaxMana(cid) local c = Creature(cid) return c and c:getMaxMana() or false end
  374. function getCreaturePosition(cid) local c = Creature(cid) return c and c:getPosition() or false end
  375. function getCreatureOutfit(cid) local c = Creature(cid) return c and c:getOutfit() or false end
  376. function getCreatureSpeed(cid) local c = Creature(cid) return c and c:getSpeed() or false end
  377. function getCreatureBaseSpeed(cid) local c = Creature(cid) return c and c:getBaseSpeed() or false end
  378. function getCreatureLookDirection(cid) local c = Creature(cid) return c and c:getDirection() or false end
  379. function getCreatureHideHealth(cid) local c = Creature(cid) return c and c:isHealthHidden() or false end
  380. function getCreatureSkullType(cid) local c = Creature(cid) return c and c:getSkull() or false end
  381. function getCreatureNoMove(cid) local c = Creature(cid) return c and c:isMovementBlocked() or false end
  382.  
  383. function getCreatureTarget(cid)
  384. local c = Creature(cid)
  385. if c then
  386. local target = c:getTarget()
  387. return target and target:getId() or 0
  388. end
  389. return false
  390. end
  391.  
  392. function getCreatureMaster(cid)
  393. local c = Creature(cid)
  394. if c then
  395. local master = c:getMaster()
  396. return master and master:getId() or c:getId()
  397. end
  398. return false
  399. end
  400.  
  401. function getCreatureSummons(cid)
  402. local c = Creature(cid)
  403. if c == nil then
  404. return false
  405. end
  406.  
  407. local result = {}
  408. for _, summon in ipairs(c:getSummons()) do
  409. result[#result + 1] = summon:getId()
  410. end
  411. return result
  412. end
  413.  
  414. getCreaturePos = getCreaturePosition
  415.  
  416. function doCreatureAddHealth(cid, health) local c = Creature(cid) return c and c:addHealth(health) or false end
  417. function doCreatureAddMana(cid, mana) local c = Creature(cid) return c and c:addMana(mana) or false end
  418. function doRemoveCreature(cid) local c = Creature(cid) return c and c:remove() or false end
  419. function doCreatureSetStorage(uid, key, value) local c = Creature(uid) return c and c:setStorageValue(key, value) or false end
  420. function doCreatureSetLookDir(cid, direction) local c = Creature(cid) return c and c:setDirection(direction) or false end
  421. function doCreatureSetSkullType(cid, skull) local c = Creature(cid) return c and c:setSkull(skull) or false end
  422. function setCreatureMaxHealth(cid, health) local c = Creature(cid) return c and c:setMaxHealth(health) or false end
  423. function setCreatureMaxMana(cid, mana) local c = Creature(cid) return c and c:setMaxMana(mana) or false end
  424. function doCreatureSetHideHealth(cid, hide) local c = Creature(cid) return c and c:setHiddenHealth(hide) or false end
  425. function doCreatureSetNoMove(cid, block) local c = Creature(cid) return c and c:setMovementBlocked(block) or false end
  426. function doCreatureSay(cid, text, type, ...) local c = Creature(cid) return c and c:say(text, type, ...) or false end
  427. function doCreatureChangeOutfit(cid, outfit) local c = Creature(cid) return c and c:setOutfit(outfit) or false end
  428. function doSetCreatureDropLoot(cid, doDrop) local c = Creature(cid) return c and c:setDropLoot(doDrop) or false end
  429. doCreatureSetDropLoot = doSetCreatureDropLoot
  430. function doChangeSpeed(cid, delta) local c = Creature(cid) return c and c:changeSpeed(delta) or false end
  431. function doAddCondition(cid, conditionId) local c = Creature(cid) return c and c:addCondition(conditionId) or false end
  432. function doRemoveCondition(cid, conditionType, subId) local c = Creature(cid) return c and (c:removeCondition(conditionType, CONDITIONID_COMBAT, subId) or c:removeCondition(conditionType, CONDITIONID_DEFAULT, subId) or true) end
  433. function getCreatureCondition(cid, type, subId) local c = Creature(cid) return c and c:hasCondition(type, subId) or false end
  434.  
  435. doCreatureSetLookDirection = doCreatureSetLookDir
  436. doSetCreatureDirection = doCreatureSetLookDir
  437.  
  438. function registerCreatureEvent(cid, name) local c = Creature(cid) return c and c:registerEvent(name) or false end
  439. function unregisterCreatureEvent(cid, name) local c = Creature(cid) return c and c:unregisterEvent(name) or false end
  440.  
  441. function getPlayerByName(name) local p = Player(name) return p and p:getId() or false end
  442. function getIPByPlayerName(name) local p = Player(name) return p and p:getIp() or false end
  443. function getPlayerGUID(cid) local p = Player(cid) return p and p:getGuid() or false end
  444. function getPlayerNameDescription(cid, distance) local p = Player(cid) return p and p:getDescription(distance) or false end
  445. function getPlayerSpecialDescription() debugPrint("Deprecated function, use Player:onLook event instead.") return true end
  446. function getPlayerAccountId(cid) local p = Player(cid) return p and p:getAccountId() or false end
  447. getPlayerAccount = getPlayerAccountId
  448. function getPlayerIp(cid) local p = Player(cid) return p and p:getIp() or false end
  449. function getPlayerAccountType(cid) local p = Player(cid) return p and p:getAccountType() or false end
  450. function getPlayerLastLoginSaved(cid) local p = Player(cid) return p and p:getLastLoginSaved() or false end
  451. getPlayerLastLogin = getPlayerLastLoginSaved
  452. function getPlayerName(cid) local p = Player(cid) return p and p:getName() or false end
  453. getPlayerNameDescription = getPlayerName
  454. function getPlayerFreeCap(cid) local p = Player(cid) return p and (p:getFreeCapacity() / 100) or false end
  455. function getPlayerPosition(cid) local p = Player(cid) return p and p:getPosition() or false end
  456. function getPlayerMagLevel(cid) local p = Player(cid) return p and p:getMagicLevel() or false end
  457. function getPlayerSpentMana(cid) local p = Player(cid) return p and p:getManaSpent() or false end
  458. function getPlayerRequiredMana(cid, magicLevel) local p = Player(cid) return p and p:getVocation():getRequiredManaSpent(magicLevel) or false end
  459. function getPlayerRequiredSkillTries(cid, skillId) local p = Player(cid) return p and p:getVocation():getRequiredSkillTries(skillId) or false end
  460. function getPlayerAccess(cid)
  461. local player = Player(cid)
  462. if player == nil then
  463. return false
  464. end
  465. return player:getGroup():getAccess() and 1 or 0
  466. end
  467. function getPlayerSkill(cid, skillId) local p = Player(cid) return p and p:getSkillLevel(skillId) or false end
  468. getPlayerSkillLevel = getPlayerSkill
  469. function getPlayerSkillTries(cid, skillId) local p = Player(cid) return p and p:getSkillTries(skillId) or false end
  470. function getPlayerMana(cid) local p = Player(cid) return p and p:getMana() or false end
  471. function getPlayerMaxMana(cid) local p = Player(cid) return p and p:getMaxMana() or false end
  472. function getPlayerLevel(cid) local p = Player(cid) return p and p:getLevel() or false end
  473. function getPlayerExperience(cid) local p = Player(cid) return p and p:getExperience() or false end
  474. function getPlayerTown(cid) local p = Player(cid) return p and p:getTown():getId() or false end
  475. function getPlayerVocation(cid) local p = Player(cid) return p and p:getVocation():getId() or false end
  476. function getPlayerSoul(cid) local p = Player(cid) return p and p:getSoul() or false end
  477. function getPlayerSex(cid) local p = Player(cid) return p and p:getSex() or false end
  478. function getPlayerStorageValue(cid, key) local p = Player(cid) return p and p:getStorageValue(key) or false end
  479. function getPlayerBalance(cid) local p = Player(cid) return p and p:getBankBalance() or false end
  480. function getPlayerMoney(cid) local p = Player(cid) return p and p:getMoney() or false end
  481. function getPlayerGroupId(cid) local p = Player(cid) return p and p:getGroup():getId() or false end
  482. function getPlayerLookDir(cid) local p = Player(cid) return p and p:getDirection() or false end
  483. function getPlayerLight(cid) local p = Player(cid) return p and p:getLight() or false end
  484. function getPlayerDepotItems(cid, depotId) local p = Player(cid) return p and p:getDepotItems(depotId) or false end
  485. function getPlayerStamina(cid) local p = Player(cid) return p and p:getStamina() or false end
  486. function getPlayerSkullType(cid) local p = Player(cid) return p and p:getSkull() or false end
  487. function getPlayerLossPercent(cid) local p = Player(cid) return p and p:getDeathPenalty() or false end
  488. function getPlayerPremiumDays(cid) local p = Player(cid) return p and p:getPremiumDays() or false end
  489. function getPlayerBlessing(cid, blessing) local p = Player(cid) return p and p:hasBlessing(blessing) or false end
  490. function getPlayerFlagValue(cid, flag) local p = Player(cid) return p ~= nil and p:hasFlag(flag) or false end
  491. function getPlayerCustomFlagValue() debugPrint("Deprecated function, use player:hasFlag(flag) instead.") return true end
  492.  
  493. function getPlayerParty(cid)
  494. local player = Player(cid)
  495. if player == nil then
  496. return false
  497. end
  498.  
  499. local party = player:getParty()
  500. if party == nil then
  501. return nil
  502. end
  503. return party:getLeader():getId()
  504. end
  505. function getPlayerGuildId(cid)
  506. local player = Player(cid)
  507. if player == nil then
  508. return false
  509. end
  510.  
  511. local guild = player:getGuild()
  512. if guild == nil then
  513. return false
  514. end
  515. return guild:getId()
  516. end
  517. function getPlayerGuildLevel(cid) local p = Player(cid) return p and p:getGuildLevel() or false end
  518. function getPlayerGuildName(cid)
  519. local player = Player(cid)
  520. if player == nil then
  521. return false
  522. end
  523.  
  524. local guild = player:getGuild()
  525. if guild == nil then
  526. return false
  527. end
  528. return guild:getName()
  529. end
  530. function getPlayerGuildRank(cid)
  531. local player = Player(cid)
  532. if player == nil then
  533. return false
  534. end
  535.  
  536. local guild = player:getGuild()
  537. if guild == nil then
  538. return false
  539. end
  540.  
  541. local rank = guild:getRankByLevel(player:getGuildLevel())
  542. return rank and rank.name or false
  543. end
  544. function getPlayerGuildRankId(cid) local p = Player(cid) return p and p:getGuildLevel() or false end
  545. function getPlayerGuildNick(cid) local p = Player(cid) return p and p:getGuildNick() or false end
  546. function getPlayerMasterPos(cid) local p = Player(cid) return p and p:getTown():getTemplePosition() or false end
  547. function getPlayerItemCount(cid, itemId, ...) local p = Player(cid) return p and p:getItemCount(itemId, ...) or false end
  548. function getPlayerWeapon(cid) local p = Player(cid) return p and p:getWeaponType() or false end
  549. function getPlayerSlotItem(cid, slot)
  550. local player = Player(cid)
  551. if player == nil then
  552. return pushThing(nil)
  553. end
  554. return pushThing(player:getSlotItem(slot))
  555. end
  556. function getPlayerItemById(cid, deepSearch, itemId, ...)
  557. local player = Player(cid)
  558. if player == nil then
  559. return pushThing(nil)
  560. end
  561. return pushThing(player:getItemById(itemId, deepSearch, ...))
  562. end
  563. function getPlayerFood(cid)
  564. local player = Player(cid)
  565. if player == nil then
  566. return false
  567. end
  568. local c = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT) return c and math.floor(c:getTicks() / 1000) or 0
  569. end
  570. function canPlayerLearnInstantSpell(cid, name) local p = Player(cid) return p and p:canLearnSpell(name) or false end
  571. function getPlayerLearnedInstantSpell(cid, name) local p = Player(cid) return p and p:hasLearnedSpell(name) or false end
  572. function isPlayerGhost(cid) local p = Player(cid) return p and p:isInGhostMode() or false end
  573. function isPlayerPzLocked(cid) local p = Player(cid) return p and p:isPzLocked() or false end
  574. function isPremium(cid) local p = Player(cid) return p and p:isPremium() or false end
  575. function getPlayersByIPAddress(ip, mask)
  576. if mask == nil then mask = 0xFFFFFFFF end
  577. local masked = bit.band(ip, mask)
  578. local result = {}
  579. for _, player in ipairs(Game.getPlayers()) do
  580. if bit.band(player:getIp(), mask) == masked then
  581. result[#result + 1] = player:getId()
  582. end
  583. end
  584. return result
  585. end
  586. getPlayersByIp = getPlayersByIPAddress
  587. function getOnlinePlayers()
  588. local result = {}
  589. for _, player in ipairs(Game.getPlayers()) do
  590. result[#result + 1] = player:getName()
  591. end
  592. return result
  593. end
  594. getPlayersOnline = getOnlinePlayers
  595. function getPlayersByAccountNumber(accountNumber)
  596. local result = {}
  597. for _, player in ipairs(Game.getPlayers()) do
  598. if player:getAccountId() == accountNumber then
  599. result[#result + 1] = player:getId()
  600. end
  601. end
  602. return result
  603. end
  604. function getPlayerGUIDByName(name)
  605. local player = Player(name)
  606. if player then
  607. return player:getGuid()
  608. end
  609.  
  610. local resultId = db.storeQuery("SELECT `id` FROM `players` WHERE `name` = " .. db.escapeString(name))
  611. if resultId ~= false then
  612. local guid = result.getNumber(resultId, "id")
  613. result.free(resultId)
  614. return guid
  615. end
  616. return 0
  617. end
  618. function getAccountNumberByPlayerName(name)
  619. local player = Player(name)
  620. if player then
  621. return player:getAccountId()
  622. end
  623.  
  624. local resultId = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = " .. db.escapeString(name))
  625. if resultId ~= false then
  626. local accountId = result.getNumber(resultId, "account_id")
  627. result.free(resultId)
  628. return accountId
  629. end
  630. return 0
  631. end
  632.  
  633. getPlayerAccountBalance = getPlayerBalance
  634. getIpByName = getIPByPlayerName
  635.  
  636. function setPlayerStorageValue(cid, key, value) local p = Player(cid) return p and p:setStorageValue(key, value) or false end
  637. function doPlayerSetNameDescription() debugPrint("Deprecated function, use Player:onLook event instead.") return true end
  638. function doPlayerSendChannelMessage(cid, author, message, SpeakClasses, channel) local p = Player(cid) return p and p:sendChannelMessage(author, message, SpeakClasses, channel) or false end
  639. function doPlayerSetMaxCapacity(cid, cap) local p = Player(cid) return p and p:setCapacity(cap) or false end
  640. function doPlayerSetSpecialDescription() debugPrint("Deprecated function, use Player:onLook event instead.") return true end
  641. function doPlayerSetBalance(cid, balance) local p = Player(cid) return p and p:setBankBalance(balance) or false end
  642. function doPlayerSetPromotionLevel(cid, level) local p = Player(cid) return p and p:setVocation(p:getVocation():getPromotion()) or false end
  643. function doPlayerAddMoney(cid, money) local p = Player(cid) return p and p:addMoney(money) or false end
  644. function doPlayerRemoveMoney(cid, money) local p = Player(cid) return p and p:removeMoney(money) or false end
  645. function doPlayerTakeItem(cid, itemid, count) local p = Player(cid) return p and p:removeItem(itemid, count) or false end
  646. function doPlayerTransferMoneyTo(cid, target, money)
  647. if not isValidMoney(money) then
  648. return false
  649. end
  650. local p = Player(cid)
  651. return p and p:transferMoneyTo(target, money) or false
  652. end
  653. function doPlayerSave(cid) local p = Player(cid) return p and p:save() or false end
  654. function doPlayerAddSoul(cid, soul) local p = Player(cid) return p and p:addSoul(soul) or false end
  655. function doPlayerSetVocation(cid, vocation) local p = Player(cid) return p and p:setVocation(Vocation(vocation)) or false end
  656. function doPlayerSetTown(cid, town) local p = Player(cid) return p and p:setTown(Town(town)) or false end
  657. function setPlayerGroupId(cid, groupId) local p = Player(cid) return p and p:setGroup(Group(groupId)) or false end
  658. doPlayerSetGroupId = setPlayerGroupId
  659. function doPlayerSetSex(cid, sex) local p = Player(cid) return p and p:setSex(sex) or false end
  660. function doPlayerSetGuildLevel(cid, level) local p = Player(cid) return p and p:setGuildLevel(level) or false end
  661. function doPlayerSetGuildNick(cid, nick) local p = Player(cid) return p and p:setGuildNick(nick) or false end
  662. function doPlayerSetOfflineTrainingSkill(cid, skillId) local p = Player(cid) return p and p:setOfflineTrainingSkill(skillId) or false end
  663. function doShowTextDialog(cid, itemId, text) local p = Player(cid) return p and p:showTextDialog(itemId, text) or false end
  664. function doPlayerAddItemEx(cid, uid, ...) local p = Player(cid) return p and p:addItemEx(Item(uid), ...) or false end
  665. function doPlayerRemoveItem(cid, itemid, count, ...) local p = Player(cid) return p and p:removeItem(itemid, count, ...) or false end
  666. function doPlayerAddPremiumDays(cid, days) local p = Player(cid) return p and p:addPremiumDays(days) or false end
  667. function doPlayerRemovePremiumDays(cid, days) local p = Player(cid) return p and p:removePremiumDays(days) or false end
  668. function doPlayerSetStamina(cid, minutes) local p = Player(cid) return p and p:setStamina(minutes) or false end
  669. function doPlayerAddBlessing(cid, blessing) local p = Player(cid) return p and p:addBlessing(blessing) or false end
  670. function doPlayerAddOutfit(cid, lookType, addons) local p = Player(cid) return p and p:addOutfitAddon(lookType, addons) or false end
  671. function doPlayerRemOutfit(cid, lookType, addons)
  672. local player = Player(cid)
  673. if player == nil then
  674. return false
  675. end
  676. if addons == 255 then
  677. return player:removeOutfit(lookType)
  678. else
  679. return player:removeOutfitAddon(lookType, addons)
  680. end
  681. end
  682. doPlayerRemoveOutfit = doPlayerRemOutfit
  683. function canPlayerWearOutfit(cid, lookType, addons) local p = Player(cid) return p and p:hasOutfit(lookType, addons) or false end
  684. function doPlayerSendOutfitWindow(cid) local p = Player(cid) return p and p:sendOutfitWindow() or false end
  685. function doPlayerSendCancel(cid, text) local p = Player(cid) return p and p:sendCancelMessage(text) or false end
  686. function doPlayerFeed(cid, food) local p = Player(cid) return p and p:feed(food) or false end
  687. function playerLearnInstantSpell(cid, name) local p = Player(cid) return p and p:learnSpell(name) or false end
  688. doPlayerLearnInstantSpell = playerLearnInstantSpell
  689. function doPlayerUnlearnInstantSpell(cid, name) local p = Player(cid) return p and p:forgetSpell(name) or false end
  690. function doPlayerPopupFYI(cid, message) local p = Player(cid) return p and p:popupFYI(message) or false end
  691. function doSendTutorial(cid, tutorialId) local p = Player(cid) return p and p:sendTutorial(tutorialId) or false end
  692. doPlayerSendTutorial = doSendTutorial
  693. function doAddMapMark(cid, pos, type, description) local p = Player(cid) return p and p:addMapMark(pos, type, description or "") or false end
  694. doPlayerAddMapMark = doAddMapMark
  695. function doPlayerSendTextMessage(cid, type, text, ...) local p = Player(cid) return p and p:sendTextMessage(type, text, ...) or false end
  696. function doSendAnimatedText() debugPrint("Deprecated function.") return true end
  697. function getPlayerAccountManager() debugPrint("Deprecated function.") return true end
  698. function doPlayerSetExperienceRate() debugPrint("Deprecated function, use Player:onGainExperience event instead.") return true end
  699. function doPlayerSetSkillLevel(cid, skillId, value, ...) local p = Player(cid) return p and p:addSkill(skillId, value, ...) end
  700. function doPlayerSetMagicLevel(cid, value) local p = Player(cid) return p and p:addMagicLevel(value) end
  701. function doPlayerAddLevel(cid, amount, round) local p = Player(cid) return p and p:addLevel(amount, round) end
  702. function doPlayerAddExp(cid, exp, useMult, ...)
  703. local player = Player(cid)
  704. if player == nil then
  705. return false
  706. end
  707.  
  708. if useMult then
  709. exp = exp * Game.getExperienceStage(player:getLevel())
  710. end
  711. return player:addExperience(exp, ...)
  712. end
  713. doPlayerAddExperience = doPlayerAddExp
  714. function doPlayerAddManaSpent(cid, mana) local p = Player(cid) return p and p:addManaSpent(mana) or false end
  715. doPlayerAddSpentMana = doPlayerAddManaSpent
  716. function doPlayerAddSkillTry(cid, skillid, n) local p = Player(cid) return p and p:addSkillTries(skillid, n) or false end
  717. function doPlayerAddMana(cid, mana, ...) local p = Player(cid) return p and p:addMana(mana, ...) or false end
  718. function doPlayerJoinParty(cid, leaderId)
  719. local player = Player(cid)
  720. if player == nil then
  721. return false
  722. end
  723.  
  724. if player:getParty() then
  725. player:sendTextMessage(MESSAGE_INFO_DESCR, "You are already in a party.")
  726. return true
  727. end
  728.  
  729. local leader = Player(leaderId)
  730. if leader == nil then
  731. return false
  732. end
  733.  
  734. local party = leader:getParty()
  735. if party == nil or party:getLeader() ~= leader then
  736. return true
  737. end
  738.  
  739. for _, invitee in ipairs(party:getInvitees()) do
  740. if player ~= invitee then
  741. return true
  742. end
  743. end
  744.  
  745. party:addMember(player)
  746. return true
  747. end
  748. function getPartyMembers(cid)
  749. local player = Player(cid)
  750. if player == nil then
  751. return false
  752. end
  753.  
  754. local party = player:getParty()
  755. if party == nil then
  756. return false
  757. end
  758.  
  759. local result = {party:getLeader():getId()}
  760. for _, member in ipairs(party:getMembers()) do
  761. result[#result + 1] = member:getId()
  762. end
  763. return result
  764. end
  765.  
  766. doPlayerSendDefaultCancel = doPlayerSendCancel
  767.  
  768. function getMonsterTargetList(cid)
  769. local monster = Monster(cid)
  770. if monster == nil then
  771. return false
  772. end
  773.  
  774. local result = {}
  775. for _, creature in ipairs(monster:getTargetList()) do
  776. if monster:isTarget(creature) then
  777. result[#result + 1] = creature:getId()
  778. end
  779. end
  780. return result
  781. end
  782. function getMonsterFriendList(cid)
  783. local monster = Monster(cid)
  784. if monster == nil then
  785. return false
  786. end
  787.  
  788. local z = monster:getPosition().z
  789.  
  790. local result = {}
  791. for _, creature in ipairs(monster:getFriendList()) do
  792. if not creature:isRemoved() and creature:getPosition().z == z then
  793. result[#result + 1] = creature:getId()
  794. end
  795. end
  796. return result
  797. end
  798. function doSetMonsterTarget(cid, target)
  799. local monster = Monster(cid)
  800. if monster == nil then
  801. return false
  802. end
  803.  
  804. if monster:getMaster() then
  805. return true
  806. end
  807.  
  808. local target = Creature(cid)
  809. if target == nil then
  810. return false
  811. end
  812.  
  813. monster:selectTarget(target)
  814. return true
  815. end
  816. doMonsterSetTarget = doSetMonsterTarget
  817. function doMonsterChangeTarget(cid)
  818. local monster = Monster(cid)
  819. if monster == nil then
  820. return false
  821. end
  822.  
  823. if monster:getMaster() then
  824. return true
  825. end
  826.  
  827. monster:searchTarget(1)
  828. return true
  829. end
  830. function doCreateNpc(name, pos, ...)
  831. local npc = Game.createNpc(name, pos, ...) return npc and npc:setMasterPos(pos) or false
  832. end
  833. function doSummonCreature(name, pos, ...)
  834. local m = Game.createMonster(name, pos, ...) return m and m:getId() or false
  835. end
  836. doCreateMonster = doSummonCreature
  837. function doConvinceCreature(cid, target)
  838. local creature = Creature(cid)
  839. if creature == nil then
  840. return false
  841. end
  842.  
  843. local targetCreature = Creature(target)
  844. if targetCreature == nil then
  845. return false
  846. end
  847.  
  848. creature:addSummon(targetCreature)
  849. return true
  850. end
  851. function doSummonMonster(cid, name)
  852. local player = Player(cid)
  853. local position = player:getPosition()
  854. local monster = Game.createMonster(name, position)
  855. if monster then
  856. player:addSummon(monster)
  857. monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
  858. else
  859. player:sendCancelMessage("There is not enough room.")
  860. position:sendMagicEffect(CONST_ME_POFF)
  861. end
  862. return true
  863. end
  864.  
  865. function getTownId(townName) local t = Town(townName) return t and t:getId() or false end
  866. function getTownName(townId) local t = Town(townId) return t and t:getName() or false end
  867. function getTownTemplePosition(townId) local t = Town(townId) return t and t:getTemplePosition() or false end
  868.  
  869. function doSetItemActionId(uid, actionId) local i = Item(uid) return i and i:setActionId(actionId) or false end
  870. function doTransformItem(uid, newItemId, ...) local i = Item(uid) return i and i:transform(newItemId, ...) or false end
  871. function doChangeTypeItem(uid, newType) local i = Item(uid) return i and i:transform(i:getId(), newType) or false end
  872. function doRemoveItem(uid, ...) local i = Item(uid) return i and i:remove(...) or false end
  873.  
  874. function getContainerSize(uid) local c = Container(uid) return c and c:getSize() or false end
  875. function getContainerCap(uid) local c = Container(uid) return c and c:getCapacity() or false end
  876. function getContainerItem(uid, slot)
  877. local container = Container(uid)
  878. if container == nil then
  879. return pushThing(nil)
  880. end
  881. return pushThing(container:getItem(slot))
  882. end
  883.  
  884. function doAddContainerItemEx(uid, virtualId)
  885. local container = Container(uid)
  886. if container == nil then
  887. return false
  888. end
  889.  
  890. local res = container:addItemEx(Item(virtualId))
  891. if res == nil then
  892. return false
  893. end
  894. return res
  895. end
  896.  
  897. function doSendMagicEffect(pos, magicEffect, ...) return Position(pos):sendMagicEffect(magicEffect, ...) end
  898. function doSendDistanceShoot(fromPos, toPos, distanceEffect, ...) return Position(fromPos):sendDistanceEffect(toPos, distanceEffect, ...) end
  899. function isSightClear(fromPos, toPos, floorCheck) return Position(fromPos):isSightClear(toPos, floorCheck) end
  900.  
  901. function getPromotedVocation(vocationId)
  902. local vocation = Vocation(vocationId)
  903. if vocation == nil then
  904. return 0
  905. end
  906.  
  907. local promotedVocation = vocation:getPromotion()
  908. if promotedVocation == nil then
  909. return 0
  910. end
  911. return promotedVocation:getId()
  912. end
  913. getPlayerPromotionLevel = getPromotedVocation
  914.  
  915. function getGuildId(guildName)
  916. local resultId = db.storeQuery("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(guildName))
  917. if resultId == false then
  918. return false
  919. end
  920.  
  921. local guildId = result.getNumber(resultId, "id")
  922. result.free(resultId)
  923. return guildId
  924. end
  925.  
  926. function getHouseName(houseId) local h = House(houseId) return h and h:getName() or false end
  927. function getHouseOwner(houseId) local h = House(houseId) return h and h:getOwnerGuid() or false end
  928. function getHouseEntry(houseId) local h = House(houseId) return h and h:getExitPosition() or false end
  929. function getHouseTown(houseId) local h = House(houseId) if h == nil then return false end local t = h:getTown() return t and t:getId() or false end
  930. function getHouseTilesSize(houseId) local h = House(houseId) return h and h:getTileCount() or false end
  931.  
  932. function isItemStackable(itemId) return ItemType(itemId):isStackable() end
  933. function isItemRune(itemId) return ItemType(itemId):isRune() end
  934. function isItemDoor(itemId) return ItemType(itemId):isDoor() end
  935. function isItemContainer(itemId) return ItemType(itemId):isContainer() end
  936. function isItemFluidContainer(itemId) return ItemType(itemId):isFluidContainer() end
  937. function isItemMovable(itemId) return ItemType(itemId):isMovable() end
  938. function isCorpse(uid) local i = Item(uid) return i and ItemType(i:getId()):isCorpse() or false end
  939.  
  940. isItemMoveable = isItemMovable
  941. isMoveable = isMovable
  942.  
  943. function getItemName(itemId) return ItemType(itemId):getName() end
  944. getItemNameById = getItemName
  945. function getItemWeight(itemId, ...) return ItemType(itemId):getWeight(...) / 100 end
  946. function getItemDescriptions(itemId)
  947. local itemType = ItemType(itemId)
  948. return {
  949. name = itemType:getName(),
  950. plural = itemType:getPluralName(),
  951. article = itemType:getArticle(),
  952. description = itemType:getDescription()
  953. }
  954. end
  955. function getItemIdByName(name)
  956. local id = ItemType(name):getId()
  957. if id == 0 then
  958. return false
  959. end
  960. return id
  961. end
  962. function getItemWeightByUID(uid, ...)
  963. local item = Item(uid)
  964. if item == nil then
  965. return false
  966. end
  967.  
  968. local itemType = ItemType(item:getId())
  969. return itemType:isStackable() and (itemType:getWeight(item:getCount(), ...) / 100) or (itemType:getWeight(1, ...) / 100)
  970. end
  971. function getItemRWInfo(uid)
  972. local item = Item(uid)
  973. if item == nil then
  974. return false
  975. end
  976.  
  977. local rwFlags = 0
  978. local itemType = ItemType(item:getId())
  979. if itemType:isReadable() then
  980. rwFlags = bit.bor(rwFlags, 1)
  981. end
  982.  
  983. if itemType:isWritable() then
  984. rwFlags = bit.bor(rwFlags, 2)
  985. end
  986. return rwFlags
  987. end
  988. function getContainerCapById(itemId) return ItemType(itemId):getCapacity() end
  989. function getFluidSourceType(itemId) local it = ItemType(itemId) return it.id ~= 0 and it:getFluidSource() or false end
  990. function hasProperty(uid, prop)
  991. local item = Item(uid)
  992. if item == nil then
  993. return false
  994. end
  995.  
  996. local parent = item:getParent()
  997. if parent:isTile() and item == parent:getGround() then
  998. return parent:hasProperty(prop)
  999. else
  1000. return item:hasProperty(prop)
  1001. end
  1002. end
  1003.  
  1004. function doSetItemText(uid, text)
  1005. local item = Item(uid)
  1006. if item == nil then
  1007. return false
  1008. end
  1009.  
  1010. if text ~= "" then
  1011. item:setAttribute(ITEM_ATTRIBUTE_TEXT, text)
  1012. else
  1013. item:removeAttribute(ITEM_ATTRIBUTE_TEXT)
  1014. end
  1015. return true
  1016. end
  1017. function doSetItemSpecialDescription(uid, desc)
  1018. local item = Item(uid)
  1019. if item == nil then
  1020. return false
  1021. end
  1022.  
  1023. if desc ~= "" then
  1024. item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, desc)
  1025. else
  1026. item:removeAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
  1027. end
  1028. return true
  1029. end
  1030. function doDecayItem(uid) local i = Item(uid) return i and i:decay() or false end
  1031.  
  1032. function setHouseOwner(id, guid) local h = House(id) return h and h:setOwnerGuid(guid) or false end
  1033. function getHouseRent(id) local h = House(id) return h and h:getRent() or nil end
  1034. function getHouseAccessList(id, listId) local h = House(id) return h and h:getAccessList(listId) or nil end
  1035. function setHouseAccessList(id, listId, listText) local h = House(id) return h and h:setAccessList(listId, listText) or false end
  1036.  
  1037. function getHouseByPlayerGUID(playerGUID)
  1038. for _, house in ipairs(Game.getHouses()) do
  1039. if house:getOwnerGuid() == playerGUID then
  1040. return house:getId()
  1041. end
  1042. end
  1043. return nil
  1044. end
  1045.  
  1046. function getTileHouseInfo(pos)
  1047. local t = Tile(pos)
  1048. if t == nil then
  1049. return false
  1050. end
  1051. local h = t:getHouse()
  1052. return h and h:getId() or false
  1053. end
  1054.  
  1055. function getTilePzInfo(position)
  1056. local t = Tile(position)
  1057. if t == nil then
  1058. return false
  1059. end
  1060. return t:hasFlag(TILESTATE_PROTECTIONZONE)
  1061. end
  1062.  
  1063. function getTileInfo(position)
  1064. local t = Tile(position)
  1065. if t == nil then
  1066. return false
  1067. end
  1068.  
  1069. local ret = pushThing(t:getGround())
  1070. ret.protection = t:hasFlag(TILESTATE_PROTECTIONZONE)
  1071. ret.nopz = ret.protection
  1072. ret.nologout = t:hasFlag(TILESTATE_NOLOGOUT)
  1073. ret.refresh = t:hasFlag(TILESTATE_REFRESH)
  1074. ret.house = t:getHouse() ~= nil
  1075. ret.bed = t:hasFlag(TILESTATE_BED)
  1076. ret.depot = t:hasFlag(TILESTATE_DEPOT)
  1077.  
  1078. ret.things = t:getThingCount()
  1079. ret.creatures = t:getCreatureCount()
  1080. ret.items = t:getItemCount()
  1081. ret.topItems = t:getTopItemCount()
  1082. ret.downItems = t:getDownItemCount()
  1083. return ret
  1084. end
  1085.  
  1086. function getTileItemByType(position, itemType)
  1087. local t = Tile(position)
  1088. if t == nil then
  1089. return pushThing(nil)
  1090. end
  1091. return pushThing(t:getItemByType(itemType))
  1092. end
  1093.  
  1094. function getTileItemById(position, itemId, ...)
  1095. local t = Tile(position)
  1096. if t == nil then
  1097. return pushThing(nil)
  1098. end
  1099. return pushThing(t:getItemById(itemId, ...))
  1100. end
  1101.  
  1102. function getTileThingByPos(position)
  1103. local t = Tile(position)
  1104. if t == nil then
  1105. if position.stackpos == -1 then
  1106. return -1
  1107. end
  1108. return pushThing(nil)
  1109. end
  1110.  
  1111. if position.stackpos == -1 then
  1112. return t:getThingCount()
  1113. end
  1114. return pushThing(t:getThing(position.stackpos))
  1115. end
  1116.  
  1117. function getTileThingByTopOrder(position, topOrder)
  1118. local t = Tile(position)
  1119. if t == nil then
  1120. return pushThing(nil)
  1121. end
  1122. return pushThing(t:getItemByTopOrder(topOrder))
  1123. end
  1124.  
  1125. function getTopCreature(position)
  1126. local t = Tile(position)
  1127. if t == nil then
  1128. return pushThing(nil)
  1129. end
  1130. return pushThing(t:getTopCreature())
  1131. end
  1132.  
  1133. function queryTileAddThing(thing, position, ...) local t = Tile(position) return t and t:queryAdd(thing, ...) or false end
  1134.  
  1135. function doTeleportThing(uid, dest, pushMovement)
  1136. if type(uid) == "userdata" then
  1137. if uid:isCreature() then
  1138. return uid:teleportTo(dest, pushMovement or false)
  1139. else
  1140. return uid:moveTo(dest)
  1141. end
  1142. else
  1143. if uid >= 0x10000000 then
  1144. local creature = Creature(uid)
  1145. if creature then
  1146. return creature:teleportTo(dest, pushMovement or false)
  1147. end
  1148. else
  1149. local item = Item(uid)
  1150. if item then
  1151. return item:moveTo(dest)
  1152. end
  1153. end
  1154. end
  1155. return false
  1156. end
  1157.  
  1158. function getThingPos(uid)
  1159. local thing
  1160. if type(uid) ~= "userdata" then
  1161. if uid >= 0x10000000 then
  1162. thing = Creature(uid)
  1163. else
  1164. thing = Item(uid)
  1165. end
  1166. else
  1167. thing = uid
  1168. end
  1169.  
  1170. if thing == nil then
  1171. return false
  1172. end
  1173.  
  1174. local stackpos = 0
  1175. local tile = thing:getTile()
  1176. if tile then
  1177. stackpos = tile:getThingIndex(thing)
  1178. end
  1179.  
  1180. local position = thing:getPosition()
  1181. position.stackpos = stackpos
  1182. return position
  1183. end
  1184. getThingPosition = getThingPos
  1185.  
  1186. function getThingfromPos(pos)
  1187. local tile = Tile(pos)
  1188. if tile == nil then
  1189. return pushThing(nil)
  1190. end
  1191.  
  1192. local thing
  1193. local stackpos = pos.stackpos or 0
  1194. if stackpos == STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE then
  1195. thing = tile:getTopCreature()
  1196. if thing == nil then
  1197. local item = tile:getTopDownItem()
  1198. if item and item:getType():isMovable() then
  1199. thing = item
  1200. end
  1201. end
  1202. elseif stackpos == STACKPOS_TOP_FIELD then
  1203. thing = tile:getFieldItem()
  1204. elseif stackpos == STACKPOS_TOP_CREATURE then
  1205. thing = tile:getTopCreature()
  1206. else
  1207. thing = tile:getThing(stackpos)
  1208. end
  1209. return pushThing(thing)
  1210. end
  1211.  
  1212. function doRelocate(fromPos, toPos)
  1213. if fromPos == toPos then
  1214. return false
  1215. end
  1216.  
  1217. local fromTile = Tile(fromPos)
  1218. if fromTile == nil then
  1219. return false
  1220. end
  1221.  
  1222. if Tile(toPos) == nil then
  1223. return false
  1224. end
  1225.  
  1226. for i = fromTile:getThingCount() - 1, 0, -1 do
  1227. local thing = fromTile:getThing(i)
  1228. if thing then
  1229. if thing:isItem() then
  1230. if ItemType(thing:getId()):isMovable() then
  1231. thing:moveTo(toPos)
  1232. end
  1233. elseif thing:isCreature() then
  1234. thing:teleportTo(toPos)
  1235. end
  1236. end
  1237. end
  1238. return true
  1239. end
  1240.  
  1241. function getThing(uid)
  1242. return uid >= 0x10000000 and pushThing(Creature(uid)) or pushThing(Item(uid))
  1243. end
  1244.  
  1245. function getConfigInfo(info)
  1246. if type(info) ~= "string" then
  1247. return nil
  1248. end
  1249. dofile('config.lua')
  1250. return _G[info]
  1251. end
  1252.  
  1253. function getWorldCreatures(type)
  1254. if type == 0 then
  1255. return Game.getPlayerCount()
  1256. elseif type == 1 then
  1257. return Game.getMonsterCount()
  1258. elseif type == 2 then
  1259. return Game.getNpcCount()
  1260. end
  1261. return Game.getPlayerCount() + Game.getMonsterCount() + Game.getNpcCount()
  1262. end
  1263.  
  1264. saveData = saveServer
  1265.  
  1266. function getGlobalStorageValue(key)
  1267. return Game.getStorageValue(key) or -1
  1268. end
  1269. getStorage = getGlobalStorageValue
  1270. function setGlobalStorageValue(key, value)
  1271. Game.setStorageValue(key, value)
  1272. return true
  1273. end
  1274. doSetStorage = setGlobalStorageValue
  1275. getWorldType = Game.getWorldType
  1276.  
  1277. function setWorldType(type)
  1278. return Game.setWorldType(type)
  1279. end
  1280.  
  1281. function getGameState()
  1282. return Game.getGameState()
  1283. end
  1284.  
  1285. function doSetGameState(state)
  1286. return Game.setGameState(state)
  1287. end
  1288.  
  1289. function doExecuteRaid(raidName)
  1290. return Game.startRaid(raidName)
  1291. end
  1292.  
  1293. numberToVariant = Variant
  1294. stringToVariant = Variant
  1295. positionToVariant = Variant
  1296.  
  1297. function targetPositionToVariant(position)
  1298. local variant = Variant(position)
  1299. variant.type = VARIANT_TARGETPOSITION
  1300. return variant
  1301. end
  1302.  
  1303. variantToNumber = Variant.getNumber
  1304. variantToString = Variant.getString
  1305. variantToPosition = Variant.getPosition
  1306.  
  1307. function doCreateTeleport(itemId, destination, position)
  1308. local item = Game.createItem(itemId, 1, position)
  1309. if not item:isTeleport() then
  1310. item:remove()
  1311. return false
  1312. end
  1313. item:setDestination(destination)
  1314. return item:getUniqueId()
  1315. end
  1316.  
  1317. function getSpectators(centerPos, rangex, rangey, multifloor, onlyPlayers)
  1318. local result = Game.getSpectators(centerPos, multifloor, onlyPlayers or false, rangex, rangex, rangey, rangey)
  1319. if #result == 0 then
  1320. return nil
  1321. end
  1322.  
  1323. for index, spectator in ipairs(result) do
  1324. result[index] = spectator:getId()
  1325. end
  1326. return result
  1327. end
  1328.  
  1329. function broadcastMessage(message, messageType)
  1330. Game.broadcastMessage(message, messageType)
  1331. print("> Broadcasted message: \"" .. message .. "\".")
  1332. end
  1333. doBroadcastMessage = broadcastMessage
  1334.  
  1335. function Guild.addMember(self, player)
  1336. return player:setGuild(self)
  1337. end
  1338. function Guild.removeMember(self, player)
  1339. return player:getGuild() == self and player:setGuild(nil)
  1340. end
  1341.  
  1342. function getPlayerInstantSpellCount(cid) local p = Player(cid) return p and #p:getInstantSpells() end
  1343. function getPlayerInstantSpellInfo(cid, spellId)
  1344. local player = Player(cid)
  1345. if not player then
  1346. return false
  1347. end
  1348.  
  1349. local spell = Spell(spellId)
  1350. if not spell or not player:canCast(spell) then
  1351. return false
  1352. end
  1353.  
  1354. return spell
  1355. end
  1356.  
  1357. function doSetItemOutfit(cid, item, time) local c = Creature(cid) return c and c:setItemOutfit(item, time) end
  1358. function doSetMonsterOutfit(cid, name, time) local c = Creature(cid) return c and c:setMonsterOutfit(name, time) end
  1359. function doSetCreatureOutfit(cid, outfit, time)
  1360. local creature = Creature(cid)
  1361. if not creature then
  1362. return false
  1363. end
  1364.  
  1365. local condition = Condition(CONDITION_OUTFIT)
  1366. condition:setOutfit(outfit)
  1367. condition:setTicks(time)
  1368. creature:addCondition(condition)
  1369.  
  1370. return true
  1371. end
  1372.  
  1373. function doTileAddItemEx(pos, uid, flags)
  1374. local tile = Tile(pos)
  1375. if not tile then
  1376. return false
  1377. end
  1378.  
  1379. local item = Item(uid)
  1380. if item then
  1381. return tile:addItemEx(item, flags)
  1382. end
  1383.  
  1384. return false
  1385. end
  1386.  
  1387. function isInArray(array, value) return table.contains(array, value) end
  1388.  
  1389. function doCreateItem(itemid, count, pos)
  1390. local tile = Tile(pos)
  1391. if not tile then
  1392. return false
  1393. end
  1394.  
  1395. local item = Game.createItem(itemid, count, pos)
  1396. if item then
  1397. return item:getUniqueId()
  1398. end
  1399. return false
  1400. end
  1401.  
  1402. function doCreateItemEx(itemid, count)
  1403. local item = Game.createItem(itemid, count)
  1404. if item then
  1405. return item:getUniqueId()
  1406. end
  1407. return false
  1408. end
  1409.  
  1410. function doMoveCreature(cid, direction) local c = Creature(cid) return c ~= nil and c:move(direction) end
  1411.  
  1412. function createFunctions(class)
  1413. local exclude = {[2] = {"is"}, [3] = {"get", "set", "add", "can"}, [4] = {"need"}}
  1414. local temp = {}
  1415. for name, func in pairs(class) do
  1416. local add = true
  1417. for strLen, strTable in pairs(exclude) do
  1418. if table.contains(strTable, name:sub(1, strLen)) then
  1419. add = false
  1420. end
  1421. end
  1422. if add then
  1423. local str = name:sub(1, 1):upper() .. name:sub(2)
  1424. local getFunc = function(self) return func(self) end
  1425. local setFunc = function(self, ...) return func(self, ...) end
  1426. local get = "get" .. str
  1427. local set = "set" .. str
  1428. if not (rawget(class, get) and rawget(class, set)) then
  1429. table.insert(temp, {set, setFunc, get, getFunc})
  1430. end
  1431. end
  1432. end
  1433. for _, func in ipairs(temp) do
  1434. rawset(class, func[1], func[2])
  1435. rawset(class, func[3], func[4])
  1436. end
  1437. end
  1438.  
  1439. function isNumber(str)
  1440. return tonumber(str) ~= nil
  1441. end
  1442.  
  1443. function doSetCreatureLight(cid, lightLevel, lightColor, time)
  1444. local creature = Creature(cid)
  1445. if not creature then
  1446. return false
  1447. end
  1448.  
  1449. local condition = Condition(CONDITION_LIGHT)
  1450. condition:setParameter(CONDITION_PARAM_LIGHT_LEVEL, lightLevel)
  1451. condition:setParameter(CONDITION_PARAM_LIGHT_COLOR, lightColor)
  1452. condition:setTicks(time)
  1453. creature:addCondition(condition)
  1454. return true
  1455. end
  1456.  
  1457. function getExperienceForLevel(level) return Game.getExperienceForLevel(level) end
  1458.  
  1459. do
  1460. local combats = {
  1461. [COMBAT_PHYSICALDAMAGE] = 'physical',
  1462. [COMBAT_ENERGYDAMAGE] = 'energy',
  1463. [COMBAT_EARTHDAMAGE] = 'earth',
  1464. [COMBAT_FIREDAMAGE] = 'fire',
  1465. [COMBAT_UNDEFINEDDAMAGE] = 'undefined',
  1466. [COMBAT_LIFEDRAIN] = 'lifedrain',
  1467. [COMBAT_MANADRAIN] = 'manadrain',
  1468. [COMBAT_HEALING] = 'healing',
  1469. [COMBAT_DROWNDAMAGE] = 'drown',
  1470. [COMBAT_ICEDAMAGE] = 'ice',
  1471. [COMBAT_HOLYDAMAGE] = 'holy',
  1472. [COMBAT_DEATHDAMAGE] = 'death'
  1473. }
  1474.  
  1475. function getCombatName(combat)
  1476. return combats[combat]
  1477. end
  1478. end
  1479.  
  1480. do
  1481. local skills = {
  1482. [SKILL_FIST] = 'fist fighting',
  1483. [SKILL_CLUB] = 'club fighting',
  1484. [SKILL_SWORD] = 'sword fighting',
  1485. [SKILL_AXE] = 'axe fighting',
  1486. [SKILL_DISTANCE] = 'distance fighting',
  1487. [SKILL_SHIELD] = 'shielding',
  1488. [SKILL_FISHING] = 'fishing',
  1489. [SKILL_MAGLEVEL] = 'magic level',
  1490. [SKILL_LEVEL] = 'level'
  1491. }
  1492.  
  1493. function getSkillName(skill)
  1494. return skills[skill] or 'unknown'
  1495. end
  1496. end
  1497.  
  1498. do
  1499. local specialSkills = {
  1500. [SPECIALSKILL_CRITICALHITCHANCE] = 'critical hit chance',
  1501. [SPECIALSKILL_CRITICALHITAMOUNT] = 'critical extra damage',
  1502. [SPECIALSKILL_LIFELEECHCHANCE] = 'hitpoints leech chance',
  1503. [SPECIALSKILL_LIFELEECHAMOUNT] = 'hitpoints leech amount',
  1504. [SPECIALSKILL_MANALEECHCHANCE] = 'manapoints leech chance',
  1505. [SPECIALSKILL_MANALEECHAMOUNT] = 'manapoints leech amount'
  1506. }
  1507.  
  1508. function getSpecialSkillName(specialSkill)
  1509. return specialSkills[specialSkill] or 'unknown'
  1510. end
  1511. end
  1512.  
  1513. function indexToCombatType(idx)
  1514. return bit.lshift(1, idx)
  1515. end
  1516.  
  1517. function showpos(v)
  1518. return v > 0 and '+' or '-'
  1519. end
  1520.  
  1521. -- this is a fix for lua52 or higher which has the function renamed to table.unpack, while luajit still uses unpack
  1522. if unpack == nil then unpack = table.unpack end
  1523.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement