Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2022
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.66 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 CreatureIndex(self, key)
  42. local methods = getmetatable(self)
  43. if key == "uid" then
  44. return methods.getId(self)
  45. elseif key == "type" then
  46. local creatureType = 0
  47. if methods.isPlayer(self) then
  48. creatureType = THING_TYPE_PLAYER
  49. elseif methods.isMonster(self) then
  50. creatureType = THING_TYPE_MONSTER
  51. elseif methods.isNpc(self) then
  52. creatureType = THING_TYPE_NPC
  53. end
  54. return creatureType
  55. elseif key == "itemid" then
  56. return 1
  57. elseif key == "actionid" then
  58. return 0
  59. end
  60. return methods[key]
  61. end
  62. rawgetmetatable("Player").__index = CreatureIndex
  63. rawgetmetatable("Monster").__index = CreatureIndex
  64. rawgetmetatable("Npc").__index = CreatureIndex
  65. end
  66.  
  67.  
  68. string.boolean = function (input)
  69. local tmp = type(input)
  70. if(tmp == 'boolean') then
  71. return input
  72. end
  73.  
  74. if(tmp == 'number') then
  75. return input > 0
  76. end
  77.  
  78. local str = string.lower(tostring(input))
  79. return (str == "yes" or str == "true" or (tonumber(str) ~= nil and tonumber(str) > 0))
  80. end
  81. getBooleanFromString = string.boolean
  82.  
  83.  
  84. do
  85. local function ItemIndex(self, key)
  86. local methods = getmetatable(self)
  87. if key == "itemid" then
  88. return methods.getId(self)
  89. elseif key == "actionid" then
  90. return methods.getActionId(self)
  91. elseif key == "uid" then
  92. return methods.getUniqueId(self)
  93. elseif key == "type" then
  94. return methods.getSubType(self)
  95. end
  96. return methods[key]
  97. end
  98. rawgetmetatable("Item").__index = ItemIndex
  99. rawgetmetatable("Container").__index = ItemIndex
  100. rawgetmetatable("Teleport").__index = ItemIndex
  101. end
  102.  
  103. function pushThing(thing)
  104. local t = {uid = 0, itemid = 0, type = 0, actionid = 0}
  105. if thing ~= nil then
  106. if thing:isItem() then
  107. t.uid = thing:getUniqueId()
  108. t.itemid = thing:getId()
  109. if ItemType(t.itemid):hasSubType() then
  110. t.type = thing:getSubType()
  111. end
  112. t.actionid = thing:getActionId()
  113. elseif thing:isCreature() then
  114. t.uid = thing:getId()
  115. t.itemid = 1
  116. if thing:isPlayer() then
  117. t.type = THING_TYPE_PLAYER
  118. elseif thing:isMonster() then
  119. t.type = THING_TYPE_MONSTER
  120. else
  121. t.type = THING_TYPE_NPC
  122. end
  123. end
  124. end
  125. return t
  126. end
  127.  
  128. createCombatObject = Combat
  129. setCombatArea = Combat.setArea
  130. setCombatCallback = Combat.setCallback
  131. setCombatCondition = Combat.setCondition
  132. setCombatFormula = Combat.setFormula
  133. setCombatParam = Combat.setParameter
  134.  
  135. createConditionObject = Condition
  136. setConditionParam = Condition.setParameter
  137. setConditionFormula = Condition.setFormula
  138. addDamageCondition = Condition.addDamage
  139. addOutfitCondition = Condition.setOutfit
  140.  
  141. function doCombat(cid, combat, var) return combat:execute(cid, var) end
  142.  
  143. function isCreature(cid) return Creature(cid) ~= nil end
  144. function isPlayer(cid) return Player(cid) ~= nil end
  145. function isMonster(cid) return Monster(cid) ~= nil end
  146. function isSummon(cid) return Creature(cid):getMaster() ~= nil end
  147. function isNpc(cid) return Npc(cid) ~= nil end
  148. function isItem(uid) return Item(uid) ~= nil end
  149. function isContainer(uid) return Container(uid) ~= nil end
  150.  
  151. function getCreatureName(cid) local c = Creature(cid) return c ~= nil and c:getName() or false end
  152. function getCreatureHealth(cid) local c = Creature(cid) return c ~= nil and c:getHealth() or false end
  153. function getCreatureMaxHealth(cid) local c = Creature(cid) return c ~= nil and c:getMaxHealth() or false end
  154. function getCreaturePosition(cid) local c = Creature(cid) return c ~= nil and c:getPosition() or false end
  155. function getCreatureOutfit(cid) local c = Creature(cid) return c ~= nil and c:getOutfit() or false end
  156. function getCreatureSpeed(cid) local c = Creature(cid) return c ~= nil and c:getSpeed() or false end
  157. function getCreatureBaseSpeed(cid) local c = Creature(cid) return c ~= nil and c:getBaseSpeed() or false end
  158.  
  159. function getCreatureTarget(cid)
  160. local c = Creature(cid)
  161. if c ~= nil then
  162. local target = c:getTarget()
  163. return target ~= nil and target:getId() or 0
  164. end
  165. return false
  166. end
  167.  
  168. function getCreatureMaster(cid)
  169. local c = Creature(cid)
  170. if c ~= nil then
  171. local master = c:getMaster()
  172. return master ~= nil and master:getId() or c:getId()
  173. end
  174. return false
  175. end
  176.  
  177. function getCreatureSummons(cid)
  178. local c = Creature(cid)
  179. if c == nil then
  180. return false
  181. end
  182.  
  183. local result = {}
  184. for _, summon in ipairs(c:getSummons()) do
  185. result[#result + 1] = summon:getId()
  186. end
  187. return result
  188. end
  189.  
  190. getCreaturePos = getCreaturePosition
  191.  
  192. function doCreatureAddHealth(cid, health) local c = Creature(cid) return c ~= nil and c:addHealth(health) or false end
  193. function doRemoveCreature(cid) local c = Creature(cid) return c ~= nil and c:remove() or false end
  194. function doCreatureSetLookDir(cid, direction) local c = Creature(cid) return c ~= nil and c:setDirection(direction) or false end
  195. function doCreatureSay(cid, text, type, ...) local c = Creature(cid) return c ~= nil and c:say(text, type, ...) or false end
  196. function doCreatureChangeOutfit(cid, outfit) local c = Creature(cid) return c ~= nil and c:setOutfit(outfit) or false end
  197. function doSetCreatureDropLoot(cid, doDrop) local c = Creature(cid) return c ~= nil and c:setDropLoot(doDrop) or false end
  198. function doChangeSpeed(cid, delta) local c = Creature(cid) return c ~= nil and c:changeSpeed(delta) or false end
  199. function doAddCondition(cid, conditionId) local c = Creature(cid) return c ~= nil and c:addCondition(conditionId) or false end
  200. function doRemoveCondition(cid, conditionType, subId) local c = Creature(cid) return c ~= nil and (c:removeCondition(conditionType, CONDITIONID_COMBAT, subId) or c:removeCondition(conditionType, CONDITIONID_DEFAULT, subId) or true) end
  201.  
  202. doSetCreatureDirection = doCreatureSetLookDir
  203.  
  204. function registerCreatureEvent(cid, name) local c = Creature(cid) return c ~= nil and c:registerEvent(name) or false end
  205. function unregisterCreatureEvent(cid, name) local c = Creature(cid) return c ~= nil and c:unregisterEvent(name) or false end
  206.  
  207. function getPlayerByName(name) local p = Player(name) return p ~= nil and p:getId() or false end
  208. function getIPByPlayerName(name) local p = Player(name) return p ~= nil and p:getIp() or false end
  209. function getPlayerGUID(cid) local p = Player(cid) return p ~= nil and p:getGuid() or false end
  210. function getPlayerIp(cid) local p = Player(cid) return p ~= nil and p:getIp() or false end
  211. function getPlayerAccountType(cid) local p = Player(cid) return p ~= nil and p:getAccountType() or false end
  212. function getPlayerLastLoginSaved(cid) local p = Player(cid) return p ~= nil and p:getLastLoginSaved() or false end
  213. function getPlayerName(cid) local p = Player(cid) return p ~= nil and p:getName() or false end
  214. function getPlayerFreeCap(cid) local p = Player(cid) return p ~= nil and (p:getFreeCapacity() / 100) or false end
  215. function getPlayerPosition(cid) local p = Player(cid) return p ~= nil and p:getPosition() or false end
  216. function getPlayerMagLevel(cid) local p = Player(cid) return p ~= nil and p:getMagicLevel() or false end
  217. function getPlayerAccess(cid)
  218. local player = Player(cid)
  219. if player == nil then
  220. return false
  221. end
  222. return player:getGroup():getAccess() and 1 or 0
  223. end
  224. function getPlayerSkill(cid, skillId) local p = Player(cid) return p ~= nil and p:getSkillLevel(skillId) or false end
  225. function getPlayerMana(cid) local p = Player(cid) return p ~= nil and p:getMana() or false end
  226. function getPlayerMaxMana(cid) local p = Player(cid) return p ~= nil and p:getMaxMana() or false end
  227. function getPlayerLevel(cid) local p = Player(cid) return p ~= nil and p:getLevel() or false end
  228. function getPlayerTown(cid) local p = Player(cid) return p ~= nil and p:getTown():getId() or false end
  229. function getPlayerVocation(cid) local p = Player(cid) return p ~= nil and p:getVocation():getId() or false end
  230. function getPlayerSoul(cid) local p = Player(cid) return p ~= nil and p:getSoul() or false end
  231. function getPlayerSex(cid) local p = Player(cid) return p ~= nil and p:getSex() or false end
  232. function getPlayerStorageValue(cid, key) local p = Player(cid) return p ~= nil and p:getStorageValue(key) or false end
  233. function getPlayerBalance(cid) local p = Player(cid) return p ~= nil and p:getBankBalance() or false end
  234. function getPlayerMoney(cid) local p = Player(cid) return p ~= nil and p:getMoney() or false end
  235. function getPlayerGroupId(cid) local p = Player(cid) return p ~= nil and p:getGroup():getId() or false end
  236. function getPlayerLookDir(cid) local p = Player(cid) return p ~= nil and p:getDirection() or false end
  237. function getPlayerLight(cid) local p = Player(cid) return p ~= nil and p:getLight() or false end
  238. function getPlayerDepotItems(cid, depotId) local p = Player(cid) return p ~= nil and p:getDepotItems(depotId) or false end
  239. function getPlayerSkullType(cid) local p = Player(cid) return p ~= nil and p:getSkull() or false end
  240. function getPlayerLossPercent(cid) local p = Player(cid) return p ~= nil and p:getDeathPenalty() or false end
  241. function getPlayerMount(cid, mountId) local p = Player(cid) return p ~= nil and p:hasMount(mountId) or false end
  242. function getPlayerPremiumDays(cid) local p = Player(cid) return p ~= nil and p:getPremiumDays() or false end
  243. function getPlayerBlessing(cid, blessing) local p = Player(cid) return p ~= nil and p:hasBlessing(blessing) or false end
  244. function getPlayerParty(cid)
  245. local player = Player(cid)
  246. if player == nil then
  247. return false
  248. end
  249.  
  250. local party = player:getParty()
  251. if party == nil then
  252. return nil
  253. end
  254. return party:getLeader():getId()
  255. end
  256. function getPlayerGuildId(cid)
  257. local player = Player(cid)
  258. if player == nil then
  259. return false
  260. end
  261.  
  262. local guild = player:getGuild()
  263. if guild == nil then
  264. return false
  265. end
  266. return guild:getId()
  267. end
  268. function getPlayerGuildLevel(cid) local p = Player(cid) return p ~= nil and p:getGuildLevel() or false end
  269. function getPlayerGuildName(cid)
  270. local player = Player(cid)
  271. if player == nil then
  272. return false
  273. end
  274.  
  275. local guild = player:getGuild()
  276. if guild == nil then
  277. return false
  278. end
  279. return guild:getName()
  280. end
  281. function getPlayerGuildRank(cid)
  282. local player = Player(cid)
  283. if player == nil then
  284. return false
  285. end
  286.  
  287. local guild = player:getGuild()
  288. if guild == nil then
  289. return false
  290. end
  291.  
  292. local rank = guild:getRankByLevel(player:getGuildLevel())
  293. return rank ~= nil and rank.name or false
  294. end
  295. function getPlayerGuildNick(cid) local p = Player(cid) return p ~= nil and p:getGuildNick() or false end
  296. function getPlayerMasterPos(cid) local p = Player(cid) return p ~= nil and p:getTown():getTemplePosition() or false end
  297. function getPlayerItemCount(cid, itemId, ...) local p = Player(cid) return p ~= nil and p:getItemCount(itemId, ...) or false end
  298. function getPlayerSlotItem(cid, slot)
  299. local player = Player(cid)
  300. if player == nil then
  301. return pushThing(nil)
  302. end
  303. return pushThing(player:getSlotItem(slot))
  304. end
  305. function getPlayerItemById(cid, deepSearch, itemId, ...)
  306. local player = Player(cid)
  307. if player == nil then
  308. return pushThing(nil)
  309. end
  310. return pushThing(player:getItemById(itemId, deepSearch, ...))
  311. end
  312. function getPlayerFood(cid)
  313. local player = Player(cid)
  314. if player == nil then
  315. return false
  316. end
  317. local c = player:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT) return c ~= nil and math.floor(c:getTicks() / 1000) or 0
  318. end
  319. function canPlayerLearnInstantSpell(cid, name) local p = Player(cid) return p ~= nil and p:canLearnSpell(name) or false end
  320. function getPlayerLearnedInstantSpell(cid, name) local p = Player(cid) return p ~= nil and p:hasLearnedSpell(name) or false end
  321. function isPlayerGhost(cid) local p = Player(cid) return p ~= nil and p:isInGhostMode() or false end
  322. function isPlayerPzLocked(cid) local p = Player(cid) return p ~= nil and p:isPzLocked() or false end
  323. function isPremium(cid) local p = Player(cid) return p ~= nil and p:isPremium() or false end
  324. function getPlayersByIPAddress(ip, mask)
  325. if mask == nil then mask = 0xFFFFFFFF end
  326. local masked = bit.band(ip, mask)
  327. local result = {}
  328. for _, player in ipairs(Game.getPlayers()) do
  329. if bit.band(player:getIp(), mask) == masked then
  330. result[#result + 1] = player:getId()
  331. end
  332. end
  333. return result
  334. end
  335. function getOnlinePlayers()
  336. local result = {}
  337. for _, player in ipairs(Game.getPlayers()) do
  338. result[#result + 1] = player:getName()
  339. end
  340. return result
  341. end
  342. function getPlayersByAccountNumber(accountNumber)
  343. local result = {}
  344. for _, player in ipairs(Game.getPlayers()) do
  345. if player:getAccountId() == accountNumber then
  346. result[#result + 1] = player:getId()
  347. end
  348. end
  349. return result
  350. end
  351. function getPlayerGUIDByName(name)
  352. local player = Player(name)
  353. if player ~= nil then
  354. return player:getGuid()
  355. end
  356.  
  357. local resultId = db.storeQuery("SELECT `id` FROM `players` WHERE `name` = " .. db.escapeString(name))
  358. if resultId ~= false then
  359. local guid = result.getDataInt(resultId, "id")
  360. result.free(resultId)
  361. return guid
  362. end
  363. return 0
  364. end
  365. function getAccountNumberByPlayerName(name)
  366. local player = Player(name)
  367. if player ~= nil then
  368. return player:getAccountId()
  369. end
  370.  
  371. local resultId = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = " .. db.escapeString(name))
  372. if resultId ~= false then
  373. local accountId = result.getDataInt(resultId, "account_id")
  374. result.free(resultId)
  375. return accountId
  376. end
  377. return 0
  378. end
  379.  
  380. getPlayerAccountBalance = getPlayerBalance
  381. getIpByName = getIPByPlayerName
  382.  
  383. function setPlayerStorageValue(cid, key, value) local p = Player(cid) return p ~= nil and p:setStorageValue(key, value) or false end
  384. function doPlayerSetBalance(cid, balance) local p = Player(cid) return p ~= nil and p:setBankBalance(balance) or false end
  385. function doPlayerAddMoney(cid, money) local p = Player(cid) return p ~= nil and p:addMoney(money) or false end
  386. function doPlayerRemoveMoney(cid, money) local p = Player(cid) return p ~= nil and p:removeMoney(money) or false end
  387. function doPlayerAddSoul(cid, soul) local p = Player(cid) return p ~= nil and p:addSoul(soul) or false end
  388. function doPlayerSetVocation(cid, vocation) local p = Player(cid) return p ~= nil and p:setVocation(Vocation(vocation)) or false end
  389. function doPlayerSetTown(cid, town) local p = Player(cid) return p ~= nil and p:setTown(Town(town)) or false end
  390. function setPlayerGroupId(cid, groupId) local p = Player(cid) return p ~= nil and p:setGroup(Group(groupId)) or false end
  391. function doPlayerSetSex(cid, sex) local p = Player(cid) return p ~= nil and p:setSex(sex) or false end
  392. function doPlayerSetGuildLevel(cid, level) local p = Player(cid) return p ~= nil and p:setGuildLevel(level) or false end
  393. function doPlayerSetGuildNick(cid, nick) local p = Player(cid) return p ~= nil and p:setGuildNick(nick) or false end
  394. function doPlayerSetOfflineTrainingSkill(cid, skillId) local p = Player(cid) return p ~= nil and p:setOfflineTrainingSkill(skillId) or false end
  395. function doShowTextDialog(cid, itemId, text) local p = Player(cid) return p ~= nil and p:showTextDialog(itemId, text) or false end
  396. function doPlayerAddItemEx(cid, uid, ...) local p = Player(cid) return p ~= nil and p:addItemEx(Item(uid), ...) or false end
  397. function doPlayerRemoveItem(cid, itemid, count, ...) local p = Player(cid) return p ~= nil and p:removeItem(itemid, count, ...) or false end
  398. function doPlayerAddPremiumDays(cid, days) local p = Player(cid) return p ~= nil and p:addPremiumDays(days) or false end
  399. function doPlayerRemovePremiumDays(cid, days) local p = Player(cid) return p ~= nil and p:removePremiumDays(days) or false end
  400. function doPlayerAddBlessing(cid, blessing) local p = Player(cid) return p ~= nil and p:addBlessing(blessing) or false end
  401. function doPlayerAddOutfit(cid, lookType, addons) local p = Player(cid) return p ~= nil and p:addOutfitAddon(lookType, addons) or false end
  402. function doPlayerRemOutfit(cid, lookType, addons)
  403. local player = Player(cid)
  404. if player == nil then
  405. return false
  406. end
  407. if addons == 255 then
  408. return player:removeOutfit(lookType)
  409. else
  410. return player:removeOutfitAddon(lookType, addons)
  411. end
  412. end
  413. function canPlayerWearOutfit(cid, lookType, addons) local p = Player(cid) return p ~= nil and p:hasOutfit(lookType, addons) or false end
  414. function doPlayerAddMount(cid, mountId) local p = Player(cid) return p ~= nil and p:addMount(mountId) or false end
  415. function doPlayerRemoveMount(cid, mountId) local p = Player(cid) return p ~= nil and p:removeMount(mountId) or false end
  416. function doPlayerSendCancel(cid, text) local p = Player(cid) return p ~= nil and p:sendCancelMessage(text) or false end
  417. function doPlayerFeed(cid, food) local p = Player(cid) return p ~= nil and p:feed(food) or false end
  418. function playerLearnInstantSpell(cid, name) local p = Player(cid) return p ~= nil and p:learnSpell(name) or false end
  419. function doPlayerPopupFYI(cid, message) local p = Player(cid) return p ~= nil and p:popupFYI(message) or false end
  420. function doSendTutorial(cid, tutorialId) local p = Player(cid) return p ~= nil and p:sendTutorial(tutorialId) or false end
  421. function doAddMapMark(cid, pos, type, description) local p = Player(cid) return p ~= nil and p:addMapMark(pos, type, description or "") or false end
  422. function doPlayerSendTextMessage(cid, type, text, ...) local p = Player(cid) return p ~= nil and p:sendTextMessage(type, text, ...) or false end
  423. function doSendAnimatedText(message, position, color) return Game.sendAnimatedText(message, position, color) end
  424. function doPlayerAddExp(cid, exp, useMult, ...)
  425. local player = Player(cid)
  426. if player == nil then
  427. return false
  428. end
  429.  
  430. if useMult then
  431. exp = exp * Game.getExperienceStage(player:getLevel())
  432. end
  433. return player:addExperience(exp, ...)
  434. end
  435. function doPlayerAddManaSpent(cid, mana) local p = Player(cid) return p ~= nil and p:addManaSpent(mana * configManager.getNumber(configKeys.RATE_MAGIC)) or false end
  436. function doPlayerAddSkillTry(cid, skillid, n) local p = Player(cid) return p ~= nil and p:addSkillTries(skillid, n * configManager.getNumber(configKeys.RATE_SKILL)) or false end
  437. function doPlayerAddMana(cid, mana, ...) local p = Player(cid) return p ~= nil and p:addMana(mana, ...) or false end
  438. function doPlayerJoinParty(cid, leaderId)
  439. local player = Player(cid)
  440. if player == nil then
  441. return false
  442. end
  443.  
  444. if player:getParty() ~= nil then
  445. player:sendTextMessage(MESSAGE_INFO_DESCR, "You are already in a party.")
  446. return true
  447. end
  448.  
  449. local leader = Player(leaderId)
  450. if leader == nil then
  451. return false
  452. end
  453.  
  454. local party = leader:getParty()
  455. if party == nil or party:getLeader() ~= leader then
  456. return true
  457. end
  458.  
  459. for _, invitee in ipairs(party:getInvitees()) do
  460. if player ~= invitee then
  461. return true
  462. end
  463. end
  464.  
  465. party:addMember(player)
  466. return true
  467. end
  468. function getPartyMembers(cid)
  469. local player = Player(cid)
  470. if player == nil then
  471. return false
  472. end
  473.  
  474. local party = player:getParty()
  475. if party == nil then
  476. return false
  477. end
  478.  
  479. local result = {party:getLeader():getId()}
  480. for _, member in ipairs(party:getMembers()) do
  481. result[#result + 1] = member:getId()
  482. end
  483. return result
  484. end
  485.  
  486. doPlayerSendDefaultCancel = doPlayerSendCancel
  487.  
  488. function getMonsterTargetList(cid)
  489. local monster = Monster(cid)
  490. if monster == nil then
  491. return false
  492. end
  493.  
  494. local result = {}
  495. for _, creature in ipairs(monster:getTargetList()) do
  496. if monster:isTarget(creature) then
  497. result[#result + 1] = creature:getId()
  498. end
  499. end
  500. return result
  501. end
  502. function getMonsterFriendList(cid)
  503. local monster = Monster(cid)
  504. if monster == nil then
  505. return false
  506. end
  507.  
  508. local z = monster:getPosition().z
  509.  
  510. local result = {}
  511. for _, creature in ipairs(monster:getFriendList()) do
  512. if not creature:isRemoved() and creature:getPosition().z == z then
  513. result[#result + 1] = creature:getId()
  514. end
  515. end
  516. return result
  517. end
  518. function doSetMonsterTarget(cid, target)
  519. local monster = Monster(cid)
  520. if monster == nil then
  521. return false
  522. end
  523.  
  524. if monster:getMaster() ~= nil then
  525. return true
  526. end
  527.  
  528. local target = Creature(cid)
  529. if target == nil then
  530. return false
  531. end
  532.  
  533. monster:selectTarget(target)
  534. return true
  535. end
  536. function doMonsterChangeTarget(cid)
  537. local monster = Monster(cid)
  538. if monster == nil then
  539. return false
  540. end
  541.  
  542. if monster:getMaster() ~= nil then
  543. return true
  544. end
  545.  
  546. monster:searchTarget(1)
  547. return true
  548. end
  549. function doCreateNpc(name, pos, ...)
  550. local npc = Game.createNpc(name, pos, ...) return npc ~= nil and npc:setMasterPos(pos) or false
  551. end
  552. function doSummonCreature(name, pos, ...)
  553. local m = Game.createMonster(name, pos, ...) return m ~= nil and m:getId() or false
  554. end
  555. function doConvinceCreature(cid, target)
  556. local creature = Creature(cid)
  557. if creature == nil then
  558. return false
  559. end
  560.  
  561. local targetCreature = Creature(target)
  562. if targetCreature == nil then
  563. return false
  564. end
  565.  
  566. targetCreature:setMaster(creature)
  567. return true
  568. end
  569.  
  570. function getTownId(townName) local t = Town(townName) return t ~= nil and t:getId() or false end
  571. function getTownName(townId) local t = Town(townId) return t ~= nil and t:getName() or false end
  572. function getTownTemplePosition(townId) local t = Town(townId) return t ~= nil and t:getTemplePosition() or false end
  573.  
  574. function doSetItemActionId(uid, actionId) local i = Item(uid) return i ~= nil and i:setActionId(actionId) or false end
  575. function doTransformItem(uid, newItemId, ...) local i = Item(uid) return i ~= nil and i:transform(newItemId, ...) or false end
  576. function doChangeTypeItem(uid, newType) local i = Item(uid) return i ~= nil and i:transform(i:getId(), newType) or false end
  577. function doRemoveItem(uid, ...) local i = Item(uid) return i ~= nil and i:remove(...) or false end
  578.  
  579. function getContainerSize(uid) local c = Container(uid) return c ~= nil and c:getSize() or false end
  580. function getContainerCap(uid) local c = Container(uid) return c ~= nil and c:getCapacity() or false end
  581. function getContainerItem(uid, slot)
  582. local container = Container(uid)
  583. if container == nil then
  584. return pushThing(nil)
  585. end
  586. return pushThing(container:getItem(slot))
  587. end
  588.  
  589. function doAddContainerItemEx(uid, virtualId)
  590. local container = Container(uid)
  591. if container == nil then
  592. return false
  593. end
  594.  
  595. local res = container:addItemEx(Item(virtualId))
  596. if res == nil then
  597. return false
  598. end
  599. return res
  600. end
  601.  
  602. function doSendMagicEffect(pos, magicEffect, ...) return Position(pos):sendMagicEffect(magicEffect, ...) end
  603. function doSendDistanceShoot(fromPos, toPos, distanceEffect, ...) return Position(fromPos):sendDistanceEffect(toPos, distanceEffect, ...) end
  604. function isSightClear(fromPos, toPos, floorCheck) return Position(fromPos):isSightClear(toPos, floorCheck) end
  605.  
  606. function getPromotedVocation(vocationId)
  607. local vocation = Vocation(vocationId)
  608. if vocation == nil then
  609. return 0
  610. end
  611.  
  612. local promotedVocation = vocation:getPromotion()
  613. if promotedVocation == nil then
  614. return 0
  615. end
  616. return promotedVocation:getId()
  617. end
  618.  
  619. function getGuildId(guildName)
  620. local resultId = db.storeQuery("SELECT `id` FROM `guilds` WHERE `name` = " .. db.escapeString(guildName))
  621. if resultId == false then
  622. return false
  623. end
  624.  
  625. local guildId = result.getDataInt(resultId, "id")
  626. result.free(resultId)
  627. return guildId
  628. end
  629.  
  630. function getHouseName(houseId) local h = House(houseId) return h ~= nil and h:getName() or false end
  631. function getHouseOwner(houseId) local h = House(houseId) return h ~= nil and h:getOwnerGuid() or false end
  632. function getHouseEntry(houseId) local h = House(houseId) return h ~= nil and h:getExitPosition() or false end
  633. function getHouseTown(houseId) local h = House(houseId) if h == nil then return false end local t = h:getTown() return t ~= nil and t:getId() or false end
  634. function getHouseTilesSize(houseId) local h = House(houseId) return h ~= nil and h:getTileCount() or false end
  635.  
  636. function isItemStackable(itemId) return ItemType(itemId):isStackable() end
  637. function isItemRune(itemId) return ItemType(itemId):isRune() end
  638. function isItemDoor(itemId) return ItemType(itemId):isDoor() end
  639. function isItemContainer(itemId) return ItemType(itemId):isContainer() end
  640. function isItemFluidContainer(itemId) return ItemType(itemId):isFluidContainer() end
  641. function isItemMovable(itemId) return ItemType(itemId):isMovable() end
  642. function isCorpse(uid) local i = Item(uid) return i ~= nil and ItemType(i:getId()):isCorpse() or false end
  643.  
  644. isItemMoveable = isItemMovable
  645. isMoveable = isMovable
  646.  
  647. function getItemName(itemId) return ItemType(itemId):getName() end
  648. function getItemWeight(itemId, ...) return ItemType(itemId):getWeight(...) / 100 end
  649. function getItemDescriptions(itemId)
  650. local itemType = ItemType(itemId)
  651. return {
  652. name = itemType:getName(),
  653. plural = itemType:getPluralName(),
  654. article = itemType:getArticle(),
  655. description = itemType:getDescription()
  656. }
  657. end
  658. function getItemIdByName(name)
  659. local id = ItemType(name):getId()
  660. if id == 0 then
  661. return false
  662. end
  663. return id
  664. end
  665. function getItemWeightByUID(uid, ...)
  666. local item = Item(uid)
  667. if item == nil then
  668. return false
  669. end
  670.  
  671. local itemType = ItemType(item:getId())
  672. return itemType:isStackable() and (itemType:getWeight(item:getCount(), ...) / 100) or (itemType:getWeight(1, ...) / 100)
  673. end
  674. function getItemRWInfo(uid)
  675. local item = Item(uid)
  676. if item == nil then
  677. return false
  678. end
  679.  
  680. local rwFlags = 0
  681. local itemType = ItemType(item:getId())
  682. if itemType:isReadable() then
  683. rwFlags = bit.bor(rwFlags, 1)
  684. end
  685.  
  686. if itemType:isWritable() then
  687. rwFlags = bit.bor(rwFlags, 2)
  688. end
  689. return rwFlags
  690. end
  691. function getContainerCapById(itemId) return ItemType(itemId):getCapacity() end
  692. function getFluidSourceType(itemId) local it = ItemType(itemId) return it.id ~= 0 and it:getFluidSource() or false end
  693. function hasProperty(uid, prop)
  694. local item = Item(uid)
  695. if item == nil then
  696. return false
  697. end
  698.  
  699. local parent = item:getParent()
  700. if parent:isTile() and item == parent:getGround() then
  701. return parent:hasProperty(prop)
  702. else
  703. return item:hasProperty(prop)
  704. end
  705. end
  706.  
  707. function doSetItemText(uid, text)
  708. local item = Item(uid)
  709. if item == nil then
  710. return false
  711. end
  712.  
  713. if text ~= "" then
  714. item:setAttribute(ITEM_ATTRIBUTE_TEXT, text)
  715. else
  716. item:removeAttribute(ITEM_ATTRIBUTE_TEXT)
  717. end
  718. return true
  719. end
  720. function doSetItemSpecialDescription(uid, desc)
  721. local item = Item(uid)
  722. if item == nil then
  723. return false
  724. end
  725.  
  726. if desc ~= "" then
  727. item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, desc)
  728. else
  729. item:removeAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
  730. end
  731. return true
  732. end
  733. function doDecayItem(uid) local i = Item(uid) return i ~= nil and i:decay() or false end
  734.  
  735. function setHouseOwner(id, guid) local h = House(id) return h ~= nil and h:setOwnerGuid(guid) or false end
  736. function getHouseRent(id) local h = House(id) return h ~= nil and h:getRent() or nil end
  737. function getHouseAccessList(id, listId) local h = House(id) return h ~= nil and h:getAccessList(listId) or nil end
  738. function setHouseAccessList(id, listId, listText) local h = House(id) return h ~= nil and h:setAccessList(listId, listText) or false end
  739.  
  740. function getHouseByPlayerGUID(playerGUID)
  741. for _, house in ipairs(Game.getHouses()) do
  742. if house:getOwnerGuid() == playerGUID then
  743. return house:getId()
  744. end
  745. end
  746. return nil
  747. end
  748.  
  749. function getTileHouseInfo(pos)
  750. local t = Tile(pos)
  751. if t == nil then
  752. return false
  753. end
  754. local h = t:getHouse()
  755. return h ~= nil and h:getId() or false
  756. end
  757.  
  758. function getTilePzInfo(position)
  759. local t = Tile(position)
  760. if t == nil then
  761. return false
  762. end
  763. return t:hasFlag(TILESTATE_PROTECTIONZONE)
  764. end
  765.  
  766. function getTileInfo(position)
  767. local t = Tile(position)
  768. if t == nil then
  769. return false
  770. end
  771.  
  772. local ret = pushThing(t:getGround())
  773. ret.protection = t:hasFlag(TILESTATE_PROTECTIONZONE)
  774. ret.nopz = ret.protection
  775. ret.nologout = t:hasFlag(TILESTATE_NOLOGOUT)
  776. ret.refresh = t:hasFlag(TILESTATE_REFRESH)
  777. ret.house = t:getHouse() ~= nil
  778. ret.bed = t:hasFlag(TILESTATE_BED)
  779. ret.depot = t:hasFlag(TILESTATE_DEPOT)
  780.  
  781. ret.things = t:getThingCount()
  782. ret.creatures = t:getCreatureCount()
  783. ret.items = t:getItemCount()
  784. ret.topItems = t:getTopItemCount()
  785. ret.downItems = t:getDownItemCount()
  786. return ret
  787. end
  788.  
  789. function getTileItemByType(position, itemType)
  790. local t = Tile(position)
  791. if t == nil then
  792. return pushThing(nil)
  793. end
  794. return pushThing(t:getItemByType(itemType))
  795. end
  796.  
  797. function getTileItemById(position, itemId, ...)
  798. local t = Tile(position)
  799. if t == nil then
  800. return pushThing(nil)
  801. end
  802. return pushThing(t:getItemById(itemId, ...))
  803. end
  804.  
  805. function getTileThingByPos(position)
  806. local t = Tile(position)
  807. if t == nil then
  808. if position.stackpos == -1 then
  809. return -1
  810. end
  811. return pushThing(nil)
  812. end
  813.  
  814. if position.stackpos == -1 then
  815. return t:getThingCount()
  816. end
  817. return pushThing(t:getThing(position.stackpos))
  818. end
  819.  
  820. function getTileThingByTopOrder(position, topOrder)
  821. local t = Tile(position)
  822. if t == nil then
  823. return pushThing(nil)
  824. end
  825. return pushThing(t:getItemByTopOrder(topOrder))
  826. end
  827.  
  828. function getTopCreature(position)
  829. local t = Tile(position)
  830. if t == nil then
  831. return pushThing(nil)
  832. end
  833. return pushThing(t:getTopCreature())
  834. end
  835.  
  836. function queryTileAddThing(thing, position, ...) local t = Tile(position) return t ~= nil and t:queryAdd(thing, ...) or false end
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845. function doTeleportThing(uid, dest, pushMovement)
  846. if type(uid) == "userdata" then
  847. if uid:isCreature() then
  848. return uid:teleportTo(dest, pushMovement or false)
  849. else
  850. return uid:moveTo(dest)
  851. end
  852. else
  853. if uid >= 0x10000000 then
  854. local creature = Creature(uid)
  855. if creature ~= nil then
  856. return creature:teleportTo(dest, pushMovement or false)
  857. end
  858. else
  859. local item = Item(uid)
  860. if item ~= nil then
  861. return item:moveTo(dest)
  862. end
  863. end
  864. end
  865. return false
  866. end
  867.  
  868. function getThingPos(uid)
  869. local thing
  870. if type(uid) ~= "userdata" then
  871. if uid >= 0x10000000 then
  872. thing = Creature(uid)
  873. else
  874. thing = Item(uid)
  875. end
  876. else
  877. thing = uid
  878. end
  879.  
  880. if thing == nil then
  881. return false
  882. end
  883.  
  884. local stackpos = 0
  885. local tile = thing:getTile()
  886. if tile ~= nil then
  887. stackpos = tile:getThingIndex(thing)
  888. end
  889.  
  890. local position = thing:getPosition()
  891. position.stackpos = stackpos
  892. return position
  893. end
  894.  
  895. function getThingfromPos(pos)
  896. local tile = Tile(pos)
  897. if tile == nil then
  898. return pushThing(nil)
  899. end
  900.  
  901. local thing
  902. if stackpos == STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE then
  903. thing = tile:getTopCreature()
  904. if thing == nil then
  905. local item = tile:getTopDownItem()
  906. if item ~= nil and item:getType():isMovable() then
  907. thing = item
  908. end
  909. end
  910. elseif stackpos == STACKPOS_TOP_FIELD then
  911. thing = tile:getFieldItem()
  912. elseif stackpos == STACKPOS_TOP_CREATURE then
  913. thing = tile:getTopCreature()
  914. else
  915. thing = tile:getThing(pos.stackpos)
  916. end
  917. return pushThing(thing)
  918. end
  919.  
  920. function doRelocate(fromPos, toPos)
  921. if fromPos == toPos then
  922. return false
  923. end
  924.  
  925. local fromTile = Tile(fromPos)
  926. if fromTile == nil then
  927. return false
  928. end
  929.  
  930. if Tile(toPos) == nil then
  931. return false
  932. end
  933.  
  934. for i = fromTile:getThingCount() - 1, 0, -1 do
  935. local thing = fromTile:getThing(i)
  936. if thing ~= nil then
  937. if thing:isItem() then
  938. if ItemType(thing:getId()):isMovable() then
  939. thing:moveTo(toPos)
  940. end
  941. elseif thing:isCreature() then
  942. thing:teleportTo(toPos)
  943. end
  944. end
  945. end
  946. return true
  947. end
  948.  
  949. function getThing(uid)
  950. return uid >= 0x10000000 and pushThing(Creature(uid)) or pushThing(Item(uid))
  951. end
  952.  
  953. function getConfigInfo(info)
  954. if type(info) ~= "string" then
  955. return nil
  956. end
  957. dofile('config.lua')
  958. return _G[info]
  959. end
  960.  
  961. function getWorldCreatures(type)
  962. if type == 0 then
  963. return Game.getPlayerCount()
  964. elseif type == 1 then
  965. return Game.getMonsterCount()
  966. elseif type == 2 then
  967. return Game.getNpcCount()
  968. end
  969. return Game.getPlayerCount() + Game.getMonsterCount() + Game.getNpcCount()
  970. end
  971.  
  972. saveData = saveServer
  973.  
  974. function getGlobalStorageValue(key)
  975. return Game.getStorageValue(key) or -1
  976. end
  977.  
  978. function setGlobalStorageValue(key, value)
  979. Game.setStorageValue(key, value)
  980. return true
  981. end
  982.  
  983. getWorldType = Game.getWorldType
  984.  
  985. numberToVariant = Variant
  986. stringToVariant = Variant
  987. positionToVariant = Variant
  988.  
  989. function targetPositionToVariant(position)
  990. local variant = Variant(position)
  991. variant.type = VARIANT_TARGETPOSITION
  992. return variant
  993. end
  994.  
  995. variantToNumber = Variant.getNumber
  996. variantToString = Variant.getString
  997. variantToPosition = Variant.getPosition
  998.  
  999. function doCreateTeleport(itemId, destination, position)
  1000. local item = Game.createItem(itemId, 1, position)
  1001. if not item:isTeleport() then
  1002. item:remove()
  1003. return false
  1004. end
  1005. item:setDestination(destination)
  1006. return item:getUniqueId()
  1007. end
  1008.  
  1009. function getSpectators(centerPos, rangex, rangey, multifloor, onlyPlayers)
  1010. local result = Game.getSpectators(centerPos, multifloor, onlyPlayers or false, rangex, rangex, rangey, rangey)
  1011. if #result == 0 then
  1012. return nil
  1013. end
  1014.  
  1015. for index, spectator in ipairs(result) do
  1016. result[index] = spectator:getId()
  1017. end
  1018. return result
  1019. end
  1020.  
  1021. function broadcastMessage(message, messageType)
  1022. Game.broadcastMessage(message, messageType)
  1023. print("> Broadcasted message: \"" .. message .. "\".")
  1024. end
  1025.  
  1026. function Guild.addMember(self, player)
  1027. return player:setGuild(guild)
  1028. end
  1029. function Guild.removeMember(self, player)
  1030. return player:getGuild() == self and player:setGuild(nil)
  1031. end
  1032.  
  1033. function isInArray(array, value) return table.contains(array, value) end
  1034.  
  1035. function doCreateItem(itemid, count, pos)
  1036. local tile = Tile(pos)
  1037. if not tile then
  1038. return false
  1039. end
  1040.  
  1041. local item = Game.createItem(itemid, count, pos)
  1042. if item then
  1043. return item:getUniqueId()
  1044. end
  1045. return false
  1046. end
  1047.  
  1048. function doCreateItemEx(itemid, count)
  1049. local item = Game.createItem(itemid, count)
  1050. if item then
  1051. return item:getUniqueId()
  1052. end
  1053. return false
  1054. end
  1055.  
  1056. function doMoveCreature(cid, direction) local c = Creature(cid) return c ~= nil and c:move(direction) end
  1057.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement