Advertisement
Guest User

Untitled

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