Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.03 KB | None | 0 0
  1. function harmfulStatesDetector(cid, bucle)
  2. local str, t = '', {}
  3. for key, var in pairs (bucle) do
  4. if getPlayerStorageValue(cid, key) == 0 then
  5. local sms = var.state[getPlayerStorageValue(cid, LENGUAGE_STORAGE)]
  6. table.insert(t, sms)
  7. end
  8. end
  9. if table.maxn(t) > 0 then
  10. for i = 1, table.maxn(t) do
  11. str = str .. t[i]
  12. if i == table.maxn(t) - 1 then
  13. str = str .. " & "
  14. elseif i ~= table.maxn(t) then
  15. str = str .. ', '
  16. end
  17. end
  18. end
  19. return str
  20. end
  21.  
  22. function harmfulStatesCost(cid, bucle)
  23. local str, mon = "", 0
  24. for key, var in pairs (bucle) do
  25. if getPlayerStorageValue(cid, key) == 0 then
  26. mon = mon + var.price
  27. end
  28. end
  29. return mon
  30. end
  31.  
  32. function doSendTranslateMessage(cid, tab)
  33. local sms = tab[getPlayerStorageValue(cid, LENGUAGE_STORAGE)]
  34. return (sms and doPlayerSendCancel(cid, sms) or print("ERROR: " .. getCreatureName(cid) .. " no tiene lenguage seleccionado."))
  35. end
  36.  
  37. function doDeterioratingWeapon(cid, item, tabla, tries)
  38. local Translate = {
  39. [ENG_VALUE] = "With use your " .. getItemNameById(item.itemid) .. " has broken.",
  40. [ESP_VALUE] = "Con el uso tu " .. getItemNameById(item.itemid) .. " se ha roto.",
  41. [POR_VALUE] = "Com o uso sua " .. getItemNameById(item.itemid) .. " rompeu-se.",
  42. }
  43. local sms = Translate[getPlayerStorageValue(cid, LENGUAGE_STORAGE)]
  44. if string.find(getItemSpecialDescription(item.uid), "Quality") then
  45. local qualityNow = string.gsub(getItemSpecialDescription(item.uid), "Quality: ", "")
  46. if tonumber(qualityNow) > 0 then
  47. doSetItemSpecialDescription(item.uid, "Quality: " .. (qualityNow - 1))
  48. if tonumber(qualityNow) == 1 then
  49. doTransformItem(item.uid, tabla.broken)
  50. if sms then doPlayerSendCancel(cid, sms) end
  51. doSetItemSpecialDescription(item.uid, "Quality: Broken")
  52. doSendMagicEffect(getThingPos(item.uid), CONST_ME_POFF)
  53. end
  54. else
  55. if sms then doPlayerSendCancel(cid, sms) end
  56. return true
  57. end
  58. else
  59. doSetItemSpecialDescription(item.uid, "Quality: " .. tries)
  60. end
  61. return true
  62. end
  63.  
  64. ---------- Crafting Food, Armory, etc... ----------
  65.  
  66. function table.get(t) -- Adquiere Arrays
  67. local msg = ''
  68. for num = 1, table.maxn(t) do
  69. msg = msg .. t[num]
  70. if num == 1 then
  71. msg = '{' .. msg .. ', '
  72. elseif num ~= table.maxn(t) then
  73. msg = msg .. ', '
  74. else
  75. msg = msg .. '}'
  76. end
  77. end
  78. return msg
  79. end
  80.  
  81. function getTabItemsId(recipe) -- Adquiere el Id de todos los objetos de la tabla del script.
  82. local t = {}
  83. for _, v in ipairs(recipe) do
  84. table.insert(t, v[1])
  85. end
  86. return t
  87. end
  88. function getTabItemsCount(recipe) -- Adquiere las cantidad de todos los objetos de la tabla del script.
  89. local t = {}
  90. for _, v in ipairs(recipe) do
  91. table.insert(t, v[2])
  92. end
  93. return t
  94. end
  95.  
  96. function getBagItemsId(uid, recipe) -- Adquiere el Id de todos los objetos de la mochila.
  97. local t = {}
  98. for i = 0, #recipe do
  99. local item = getContainerItem(uid, i)
  100. if item.itemid ~= 0 then
  101. table.insert(t, item.itemid)
  102. end
  103. end
  104. return t
  105. end
  106.  
  107. function getBagItemsUid(uid, recipe) -- Adquiere el uid de todos los objetos de la mochila. (Para removerlos)
  108. local t = {}
  109. for i = 0, #recipe do
  110. local item = getContainerItem(uid, i)
  111. if item.itemid ~= 0 then
  112. table.insert(t, item.uid)
  113. end
  114. end
  115. return t
  116. end
  117.  
  118. function getBagItemsCount(uid, recipe) -- Adquiere las cantidad de todos los objetos de la mochila.
  119. local t = {}
  120. for i = 0, #recipe do
  121. local item = getContainerItem(uid, i)
  122. if item.itemid ~= 0 then
  123. table.insert(t, (not isItemStackable(item.itemid) and 1 or item.type))
  124. end
  125. end
  126. return t
  127. end
  128. --------------------------------------------------
  129.  
  130. function getItemCountName(id, count) -- Imprime la cantidad del objeto, y su nombre en singular/plural dependiendo de su cantidad.
  131. return (count and count .. " " .. (count ~= 1 and getItemPluralNameById(id) or getItemNameById(id)) or getItemNameById(id))
  132. end
  133.  
  134. function getInaccessMsg(cid, t, key, leng) -- Se envia un mensaje u otro dependiendo de si el jugador aún no empezó la misión, o si ya la terminó.
  135. local msg = {}
  136. if getPlayerStorageValue(cid, key) < t[1] then -- Misión inempezada.
  137. msg = leng.Unbegun
  138. elseif getPlayerStorageValue(cid, key) > table.maxn(t) then -- Misión finalizada.
  139. msg = leng.Finished
  140. end
  141. return msg
  142. end
  143.  
  144. function isNpcAvailable(cid, t, key) -- El NPC envia un mensaje u otro dependiendo de si el jugador aún no puede cumplir ninguna misión, o si ya las ha terminado todas.
  145. local minKey = {}
  146. for k in pairs(t) do if tonumber(k) then minKey = k break end end
  147. if getPlayerStorageValue(cid, key) < minKey then -- Npc no empezado.
  148. minKey = t.Unbegun
  149. elseif getPlayerStorageValue(cid, key) > table.maxn(t) then -- Npc finalizado.
  150. minKey = t.AllOver
  151. end
  152. if t.Standby then
  153. for k, v in pairs(t.Standby) do
  154. if isInArray(k, getPlayerStorageValue(cid, key)) then
  155. minKey = v -- Npc inactivo.
  156. break
  157. end
  158. end
  159. end
  160. return minKey
  161. end
  162.  
  163. function titleCase(first, rest) -- Pone la primera letra mayúscula de la palabra.
  164. return first:upper()..rest:lower()
  165. end
  166.  
  167. function setRecipeList(ingredients) -- Adquiere una lista de los ingredientes de las recetas dependiendo de los Id en una tabla.
  168. local str = ''
  169. if table.maxn(ingredients) > 0 then
  170. for i = 1, table.maxn(ingredients) do
  171. str = str .. (ingredients[i][2] > 1 and ingredients[i][2] .. " " .. string.gsub(getItemPluralNameById(ingredients[i][1]), "(%a)([%w_']*)", titleCase) .. "." or ingredients[i][2] .. " " .. string.gsub(getItemNameById(ingredients[i][1]), "(%a)([%w_']*)", titleCase) .. ".")
  172. if i ~= table.maxn(ingredients) then
  173. str = str .. '\n'
  174. end
  175. end
  176. end
  177. return str
  178. end
  179.  
  180.  
  181. function getItemsFromList(items) -- by Vodka // Adquiere una lista de objetos dependiendo de los Id en una tabla.
  182. local str = ''
  183. if table.maxn(items) > 0 then
  184. for i = 1, table.maxn(items) do
  185. str = str .. (items[i][2] > 1 and items[i][2] .. " " .. string.gsub(getItemPluralNameById(items[i][1]), "(%a)([%w_']*)", titleCase) or string.gsub(getItemNameById(items[i][1]), "(%a)([%w_']*)", titleCase))
  186. if i == table.maxn(items) - 1 then
  187. str = str .. " & "
  188. elseif i ~= table.maxn(items) then
  189. str = str .. ', '
  190. end
  191. end
  192. end
  193. return str
  194. end
  195.  
  196. ---------------------------------------------------------------
  197.  
  198. function getAllItemsBySlot(cid, slot, id)
  199. local containers = {}
  200. local items = {}
  201.  
  202. local sitem = getPlayerSlotItem(cid, slot)
  203. if sitem.uid > 0 then
  204. if isContainer(sitem.uid) then
  205. table.insert(containers, sitem.uid)
  206. elseif not(id) or id == sitem.itemid then
  207. table.insert(items, sitem)
  208. end
  209. end
  210.  
  211. while #containers > 0 do
  212. for k = (getContainerSize(containers[1]) - 1), 0, -1 do
  213. local tmp = getContainerItem(containers[1], k)
  214. if isContainer(tmp.uid) then
  215. table.insert(containers, tmp.uid)
  216. elseif not(id) or id == tmp.itemid then
  217. table.insert(items, tmp)
  218. end
  219. end
  220. table.remove(containers, 1)
  221. end
  222.  
  223. return items
  224. end
  225.  
  226.  
  227. function doPlayerAddMissionItem(cid, item, count, desc) -- "Otorga" objeto de misión.
  228. local Translate = {
  229. [ENG_VALUE] = "You've received " .. getItemCountName(item, count) .. " in your briefcase missions.",
  230. [ESP_VALUE] = "Has recibido " .. getItemCountName(item, count) .. " en tu maletín de misiones.",
  231. [POR_VALUE] = "Tem recebido " .. getItemCountName(item, count) .. " em seu mala do missões.",
  232. }
  233.  
  234. local function confirm()
  235. local bag, t = getPlayerSlotItem(cid, CONST_SLOT_RING), {}
  236. for slot = 0, getContainerSize(bag.uid) - 1 do
  237. local found = getContainerItem(bag.uid, slot)
  238. if isItemStackable(found.itemid) then
  239. if found.itemid == item and string.find(getItemSpecialDescription(found.uid), desc) then
  240. return found
  241. end
  242. end
  243. if found.itemid == SLOT_MISSION then
  244. return found
  245. end
  246. end
  247. return false
  248. end
  249.  
  250. if confirm() then
  251. local conf = confirm()
  252. doTransformItem(conf.uid, item, (conf.itemid == item and (isItemStackable(conf.itemid) and (conf.type + count) or (count == 1 and 0 or count)) or count))
  253. doSetItemSpecialDescription(conf.uid, "Objeto de misión. Entregar a " .. desc .. ".")
  254. local sms = Translate[getPlayerStorageValue(cid, LENGUAGE_STORAGE)]
  255. if sms then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, sms) end
  256. end
  257. return true
  258. end
  259.  
  260. function getPlayerMissionItem(cid, item, desc) -- Devuelve número con la cantidad de objeto de misión.
  261. local bag, count = getPlayerSlotItem(cid, CONST_SLOT_RING), 0
  262. for slot = 0, getContainerSize(bag.uid) - 1 do
  263. local found = getContainerItem(bag.uid, slot)
  264. if found.itemid == item and string.find(getItemSpecialDescription(found.uid), desc) then
  265. count = (isItemStackable(found.itemid) and (found.type + count) or 1)
  266. end
  267. end
  268. return count
  269. end
  270.  
  271. function takePlayerMissionItem(cid, item, count, desc) -- "Remueve" objeto de misión.
  272. local function confirm()
  273. count = (count == 1 and 0 or count)
  274. local bag = getPlayerSlotItem(cid, CONST_SLOT_RING)
  275. for slot = 0, getContainerSize(bag.uid) - 1 do
  276. local found = getContainerItem(bag.uid, slot)
  277. if found.itemid == item and found.type == count and string.find(getItemSpecialDescription(found.uid), desc) then
  278. return found -- quizás añadirle found.type == (isItemStackable(found.itemid) and count or 0)
  279. end
  280. end
  281. end
  282.  
  283. if confirm() then
  284. item = confirm()
  285. doTransformItem(item.uid, SLOT_MISSION)
  286. doSetItemSpecialDescription(item.uid, "")
  287. end
  288. return true
  289. end
  290.  
  291. ---------------------------------------------------------------
  292.  
  293. function doBartering(cid, offer, desc, reward, guide) -- "Remueve" objetos de misión y añade objetos.
  294. takePlayerMissionItem(cid, offer[1], offer[2], desc)
  295.  
  296. if guide then
  297. local addRecipe = doPlayerAddItem(cid, guide.ItemId)
  298. doItemSetAttribute(addRecipe, "aid", guide.ActionId)
  299. doItemSetAttribute(addRecipe, "name", guide.Name)
  300. end
  301.  
  302. if reward then
  303. for _, items in pairs(reward) do
  304. doPlayerAddItem(cid, items[1], items[2])
  305. end
  306. end
  307. return true
  308. end
  309.  
  310. ---------------------------------------------------------------
  311.  
  312. function doPlayerGiveItem(cid, itemid, amount, subType)
  313. local item = 0
  314. if(isItemStackable(itemid)) then
  315. item = doCreateItemEx(itemid, amount)
  316. if(doPlayerAddItemEx(cid, item, true) ~= RETURNVALUE_NOERROR) then
  317. return false
  318. end
  319. else
  320. for i = 1, amount do
  321. item = doCreateItemEx(itemid, subType)
  322. if(doPlayerAddItemEx(cid, item, true) ~= RETURNVALUE_NOERROR) then
  323. return false
  324. end
  325. end
  326. end
  327.  
  328. return true
  329. end
  330.  
  331. function doPlayerGiveItemContainer(cid, containerid, itemid, amount, subType)
  332. for i = 1, amount do
  333. local container = doCreateItemEx(containerid, 1)
  334. for x = 1, getContainerCapById(containerid) do
  335. doAddContainerItem(container, itemid, subType)
  336. end
  337.  
  338. if(doPlayerAddItemEx(cid, container, true) ~= RETURNVALUE_NOERROR) then
  339. return false
  340. end
  341. end
  342.  
  343. return true
  344. end
  345.  
  346. function doPlayerTakeItem(cid, itemid, amount)
  347. return getPlayerItemCount(cid, itemid) >= amount and doPlayerRemoveItem(cid, itemid, amount)
  348. end
  349.  
  350. function doPlayerBuyItem(cid, itemid, count, cost, charges)
  351. return doPlayerRemoveMoney(cid, cost) and doPlayerGiveItem(cid, itemid, count, charges)
  352. end
  353.  
  354. function doPlayerBuyItemContainer(cid, containerid, itemid, count, cost, charges)
  355. return doPlayerRemoveMoney(cid, cost) and doPlayerGiveItemContainer(cid, containerid, itemid, count, charges)
  356. end
  357.  
  358. function doPlayerSellItem(cid, itemid, count, cost)
  359. if(not doPlayerTakeItem(cid, itemid, count)) then
  360. return false
  361. end
  362.  
  363. if(not doPlayerAddMoney(cid, cost)) then
  364. error('[doPlayerSellItem] Could not add money to: ' .. getPlayerName(cid) .. ' (' .. cost .. 'gp).')
  365. end
  366.  
  367. return true
  368. end
  369.  
  370. function doPlayerWithdrawMoney(cid, amount)
  371. if(not getBooleanFromString(getConfigInfo('bankSystem'))) then
  372. return false
  373. end
  374.  
  375. local balance = getPlayerBalance(cid)
  376. if(amount > balance or not doPlayerAddMoney(cid, amount)) then
  377. return false
  378. end
  379.  
  380. doPlayerSetBalance(cid, balance - amount)
  381. return true
  382. end
  383.  
  384. function doPlayerDepositMoney(cid, amount)
  385. if(not getBooleanFromString(getConfigInfo('bankSystem'))) then
  386. return false
  387. end
  388.  
  389. if(not doPlayerRemoveMoney(cid, amount)) then
  390. return false
  391. end
  392.  
  393. doPlayerSetBalance(cid, getPlayerBalance(cid) + amount)
  394. return true
  395. end
  396.  
  397. function isPremium(cid)
  398. return (isPlayer(cid) and (getPlayerPremiumDays(cid) > 0 or getBooleanFromString(getConfigInfo('freePremium'))))
  399. end
  400.  
  401. function getMonthDayEnding(day)
  402. if(day == "01" or day == "21" or day == "31") then
  403. return "st"
  404. elseif(day == "02" or day == "22") then
  405. return "nd"
  406. elseif(day == "03" or day == "23") then
  407. return "rd"
  408. end
  409.  
  410. return "th"
  411. end
  412.  
  413. function getMonthString(m)
  414. return os.date("%B", os.time{year = 1970, month = m, day = 1})
  415. end
  416.  
  417. function getArticle(str)
  418. return str:find("[AaEeIiOoUuYy]") == 1 and "an" or "a"
  419. end
  420.  
  421. function isNumber(str)
  422. return tonumber(str) ~= nil
  423. end
  424.  
  425. function doPlayerAddAddons(cid, addon)
  426. for i = 0, table.maxn(maleOutfits) do
  427. doPlayerAddOutfit(cid, maleOutfits[i], addon)
  428. end
  429.  
  430. for i = 0, table.maxn(femaleOutfits) do
  431. doPlayerAddOutfit(cid, femaleOutfits[i], addon)
  432. end
  433. end
  434.  
  435. function doPlayerWithdrawAllMoney(cid)
  436. return doPlayerWithdrawMoney(cid, getPlayerBalance(cid))
  437. end
  438.  
  439. function doPlayerDepositAllMoney(cid)
  440. return doPlayerDepositMoney(cid, getPlayerMoney(cid))
  441. end
  442.  
  443. function doPlayerTransferAllMoneyTo(cid, target)
  444. return doPlayerTransferMoneyTo(cid, target, getPlayerBalance(cid))
  445. end
  446.  
  447. function playerExists(name)
  448. return getPlayerGUIDByName(name) ~= 0
  449. end
  450.  
  451. function getTibiaTime()
  452. local minutes = getWorldTime()
  453. local hours = 0
  454. while (minutes > 60) do
  455. hours = hours + 1
  456. minutes = minutes - 60
  457. end
  458.  
  459. return {hours = hours, minutes = minutes}
  460. end
  461.  
  462. function doWriteLogFile(file, text)
  463. local f = io.open(file, "a+")
  464. if(not f) then
  465. return false
  466. end
  467.  
  468. f:write("[" .. os.date("%d/%m/%Y %H:%M:%S") .. "] " .. text .. "\n")
  469. f:close()
  470. return true
  471. end
  472.  
  473. function getExperienceForLevel(lv)
  474. lv = lv - 1
  475. return ((50 * lv * lv * lv) - (150 * lv * lv) + (400 * lv)) / 3
  476. end
  477.  
  478. function doMutePlayer(cid, time)
  479. local condition = createConditionObject(CONDITION_MUTED)
  480. setConditionParam(condition, CONDITION_PARAM_TICKS, time * 1000)
  481. return doAddCondition(cid, condition)
  482. end
  483.  
  484. function getPlayerGroupName(cid)
  485. return getGroupInfo(getPlayerGroupId(cid)).name
  486. end
  487.  
  488. function getPlayerVocationName(cid)
  489. return getVocationInfo(getPlayerVocation(cid)).name
  490. end
  491.  
  492. function getPromotedVocation(vid)
  493. return getVocationInfo(vid).promotedVocation
  494. end
  495.  
  496. function doPlayerRemovePremiumDays(cid, days)
  497. return doPlayerAddPremiumDays(cid, -days)
  498. end
  499.  
  500. function getPlayerMasterPos(cid)
  501. return getTownTemplePosition(getPlayerTown(cid))
  502. end
  503.  
  504. function getHouseOwner(houseId)
  505. return getHouseInfo(houseId).owner
  506. end
  507.  
  508. function getHouseName(houseId)
  509. return getHouseInfo(houseId).name
  510. end
  511.  
  512. function getHouseEntry(houseId)
  513. return getHouseInfo(houseId).entry
  514. end
  515.  
  516. function getHouseRent(houseId)
  517. return getHouseInfo(houseId).rent
  518. end
  519.  
  520. function getHousePrice(houseId)
  521. return getHouseInfo(houseId).price
  522. end
  523.  
  524. function getHouseTown(houseId)
  525. return getHouseInfo(houseId).town
  526. end
  527.  
  528. function getHouseTilesCount(houseId)
  529. return getHouseInfo(houseId).tiles
  530. end
  531.  
  532. function getItemNameById(itemid)
  533. return getItemDescriptionsById(itemid).name
  534. end
  535.  
  536. function getItemPluralNameById(itemid)
  537. return getItemDescriptionsById(itemid).plural
  538. end
  539.  
  540. function getItemArticleById(itemid)
  541. return getItemDescriptionsById(itemid).article
  542. end
  543.  
  544. function getItemName(uid)
  545. return getItemDescriptions(uid).name
  546. end
  547.  
  548. function getItemPluralName(uid)
  549. return getItemDescriptions(uid).plural
  550. end
  551.  
  552. function getItemArticle(uid)
  553. return getItemDescriptions(uid).article
  554. end
  555.  
  556. function getItemText(uid)
  557. return getItemDescriptions(uid).text
  558. end
  559.  
  560. function getItemSpecialDescription(uid)
  561. return getItemDescriptions(uid).special
  562. end
  563.  
  564. function getItemWriter(uid)
  565. return getItemDescriptions(uid).writer
  566. end
  567.  
  568. function getItemDate(uid)
  569. return getItemDescriptions(uid).date
  570. end
  571.  
  572. function getTilePzInfo(pos)
  573. return getTileInfo(pos).protection
  574. end
  575.  
  576. function getTileZoneInfo(pos)
  577. local tmp = getTileInfo(pos)
  578. if(tmp.pvp) then
  579. return 2
  580. end
  581.  
  582. if(tmp.nopvp) then
  583. return 1
  584. end
  585.  
  586. return 0
  587. end
  588.  
  589. function doShutdown()
  590. return doSetGameState(GAMESTATE_SHUTDOWN)
  591. end
  592.  
  593. function doSummonCreature(name, pos, displayError)
  594. local displayError, cid = displayError or true, doCreateMonster(name, pos, displayError)
  595. if(not cid) then
  596. cid = doCreateNpc(name, pos, displayError)
  597. end
  598.  
  599. return cid
  600. end
  601.  
  602. function getOnlinePlayers()
  603. local tmp = getPlayersOnline()
  604. local players = {}
  605. for i, cid in ipairs(tmp) do
  606. table.insert(players, getCreatureName(cid))
  607. end
  608.  
  609. return players
  610. end
  611.  
  612. function getPlayerByName(name)
  613. local cid = getCreatureByName(name)
  614. return isPlayer(cid) and cid or nil
  615. end
  616.  
  617. function isPlayer(cid)
  618. return isCreature(cid) and cid >= AUTOID_PLAYERS and cid < AUTOID_MONSTERS
  619. end
  620.  
  621. function isPlayerGhost(cid)
  622. if(not isPlayer(cid)) then
  623. return false
  624. end
  625.  
  626. return getCreatureCondition(cid, CONDITION_GAMEMASTER, GAMEMASTER_INVISIBLE) or getPlayerFlagValue(cid, PLAYERFLAG_CANNOTBESEEN)
  627. end
  628.  
  629. function isMonster(cid)
  630. return isCreature(cid) and cid >= AUTOID_MONSTERS and cid < AUTOID_NPCS
  631. end
  632.  
  633. function isNPC(cid)
  634. return isCreature(cid) and (not isMonster(cid) and not isPlayer(cid))
  635. end
  636.  
  637. function isNpc(cid)
  638. return isCreature(cid) and cid >= AUTOID_NPCS
  639. end
  640.  
  641. function doPlayerSetExperienceRate(cid, value)
  642. return doPlayerSetRate(cid, SKILL__LEVEL, value)
  643. end
  644.  
  645. function doPlayerSetMagicRate(cid, value)
  646. return doPlayerSetRate(cid, SKILL__MAGLEVEL, value)
  647. end
  648.  
  649. function doPlayerAddLevel(cid, amount, round)
  650. local experience, level = 0, getPlayerLevel(cid)
  651. if(amount > 0) then
  652. experience = getExperienceForLevel(level + amount) - (round and getPlayerExperience(cid) or getExperienceForLevel(level))
  653. else
  654. experience = -((round and getPlayerExperience(cid) or getExperienceForLevel(level)) - getExperienceForLevel(level + amount))
  655. end
  656.  
  657. return doPlayerAddExperience(cid, experience)
  658. end
  659.  
  660. function doPlayerAddMagLevel(cid, amount)
  661. for i = 1, amount do
  662. doPlayerAddSpentMana(cid, (getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true) + 1) - getPlayerSpentMana(cid)) / getConfigInfo('rateMagic'))
  663. end
  664. return true
  665. end
  666.  
  667. function doPlayerAddSkill(cid, skill, amount, round)
  668. if(skill == SKILL__LEVEL) then
  669. return doPlayerAddLevel(cid, amount, round)
  670. elseif(skill == SKILL__MAGLEVEL) then
  671. return doPlayerAddMagLevel(cid, amount)
  672. end
  673.  
  674. return doPlayerAddSkillTry(cid, skill, (getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill) + 1) - getPlayerSkillTries(cid, skill)) / getConfigInfo('rateSkill'))
  675. end
  676.  
  677. function getPartyLeader(cid)
  678. local party = getPartyMembers(cid)
  679. if(type(party) ~= 'table') then
  680. return 0
  681. end
  682.  
  683. return party[1]
  684. end
  685.  
  686. function isInParty(cid)
  687. return type(getPartyMembers(cid)) == 'table'
  688. end
  689.  
  690. function isPrivateChannel(channelId)
  691. return channelId >= CHANNEL_PRIVATE
  692. end
  693.  
  694. function doPlayerResetIdleTime(cid)
  695. return doPlayerSetIdleTime(cid, 0)
  696. end
  697.  
  698. function doBroadcastMessage(text, class)
  699. local class = class or MESSAGE_STATUS_WARNING
  700. if(type(class) == 'string') then
  701. local className = MESSAGE_TYPES[class]
  702. if(className == nil) then
  703. return false
  704. end
  705.  
  706. class = className
  707. elseif(class < MESSAGE_FIRST or class > MESSAGE_LAST) then
  708. return false
  709. end
  710.  
  711. local players = getPlayersOnline()
  712. for _, pid in ipairs(players) do
  713. doPlayerSendTextMessage(pid, class, text)
  714. end
  715.  
  716. print("> Broadcasted message: \"" .. text .. "\".")
  717. return true
  718. end
  719.  
  720. function doPlayerBroadcastMessage(cid, text, class, checkFlag, ghost)
  721. local checkFlag, ghost, class = checkFlag or true, ghost or false, class or TALKTYPE_BROADCAST
  722. if(checkFlag and not getPlayerFlagValue(cid, PLAYERFLAG_CANBROADCAST)) then
  723. return false
  724. end
  725.  
  726. if(type(class) == 'string') then
  727. local className = TALKTYPE_TYPES[class]
  728. if(className == nil) then
  729. return false
  730. end
  731.  
  732. class = className
  733. elseif(class < TALKTYPE_FIRST or class > TALKTYPE_LAST) then
  734. return false
  735. end
  736.  
  737. local players = getPlayersOnline()
  738. for _, pid in ipairs(players) do
  739. doCreatureSay(cid, text, class, ghost, pid)
  740. end
  741.  
  742. print("> " .. getCreatureName(cid) .. " broadcasted message: \"" .. text .. "\".")
  743. return true
  744. end
  745.  
  746. function getBooleanFromString(input)
  747. local tmp = type(input)
  748. if(tmp == 'boolean') then
  749. return input
  750. end
  751.  
  752. if(tmp == 'number') then
  753. return input > 0
  754. end
  755.  
  756. local str = string.lower(tostring(input))
  757. return (str == "yes" or str == "true" or (tonumber(str) ~= nil and tonumber(str) > 0))
  758. end
  759.  
  760. function doCopyItem(item, attributes)
  761. local attributes = attributes or false
  762.  
  763. local ret = doCreateItemEx(item.itemid, item.type)
  764. if(attributes) then
  765. if(item.actionid > 0) then
  766. doItemSetAttribute(ret, "aid", item.actionid)
  767. end
  768. end
  769.  
  770. if(isContainer(item.uid)) then
  771. for i = (getContainerSize(item.uid) - 1), 0, -1 do
  772. local tmp = getContainerItem(item.uid, i)
  773. if(tmp.itemid > 0) then
  774. doAddContainerItemEx(ret, doCopyItem(tmp, true).uid)
  775. end
  776. end
  777. end
  778.  
  779. return getThing(ret)
  780. end
  781.  
  782. function doRemoveThing(uid)
  783. if(isCreature(uid)) then
  784. return doRemoveCreature(uid)
  785. end
  786.  
  787. return doRemoveItem(uid)
  788. end
  789.  
  790. function setAttackFormula(combat, type, minl, maxl, minm, maxm, min, max)
  791. local min, max = min or 0, max or 0
  792. return setCombatFormula(combat, type, -1, 0, -1, 0, minl, maxl, minm, maxm, min, max)
  793. end
  794.  
  795. function setHealingFormula(combat, type, minl, maxl, minm, maxm, min, max)
  796. local min, max = min or 0, max or 0
  797. return setCombatFormula(combat, type, 1, 0, 1, 0, minl, maxl, minm, maxm, min, max)
  798. end
  799.  
  800. function doChangeTypeItem(uid, subtype)
  801. local thing = getThing(uid)
  802. if(thing.itemid < 100) then
  803. return false
  804. end
  805.  
  806. local subtype = subtype or 1
  807. return doTransformItem(thing.uid, thing.itemid, subtype)
  808. end
  809.  
  810. function doSetItemText(uid, text, writer, date)
  811. local thing = getThing(uid)
  812. if(thing.itemid < 100) then
  813. return false
  814. end
  815.  
  816. doItemSetAttribute(uid, "text", text)
  817. if(writer ~= nil) then
  818. doItemSetAttribute(uid, "writer", tostring(writer))
  819. if(date ~= nil) then
  820. doItemSetAttribute(uid, "date", tonumber(date))
  821. end
  822. end
  823.  
  824. return true
  825. end
  826.  
  827. function getFluidSourceType(itemid)
  828. local item = getItemInfo(itemid)
  829. return item and item.fluidSource or false
  830. end
  831.  
  832. function getDepotId(uid)
  833. return getItemAttribute(uid, "depotid") or false
  834. end
  835.  
  836. function getItemDescriptions(uid)
  837. local thing = getThing(uid)
  838. if(thing.itemid < 100) then
  839. return false
  840. end
  841.  
  842. local item = getItemInfo(thing.itemid)
  843. return {
  844. name = getItemAttribute(uid, "name") or item.name,
  845. plural = getItemAttribute(uid, "pluralname") or item.plural,
  846. article = getItemAttribute(uid, "article") or item.article,
  847. special = getItemAttribute(uid, "description") or "",
  848. text = getItemAttribute(uid, "text") or "",
  849. writer = getItemAttribute(uid, "writer") or "",
  850. date = getItemAttribute(uid, "date") or 0
  851. }
  852. end
  853.  
  854. function getItemWeightById(itemid, count, precision)
  855. local item, count, precision = getItemInfo(itemid), count or 1, precision or false
  856. if(not item) then
  857. return false
  858. end
  859.  
  860. if(count > 100) then
  861. -- print a warning, as its impossible to have more than 100 stackable items without "cheating" the count
  862. print('[Warning] getItemWeightById', 'Calculating weight for more than 100 items!')
  863. end
  864.  
  865. local weight = item.weight * count
  866. --[[if(precision) then
  867. return weight
  868. end
  869.  
  870. local t = string.explode(tostring(weight), ".")
  871. if(table.maxn(t) == 2) then
  872. return tonumber(t[1] .. "." .. string.sub(t[2], 1, 2))
  873. end]]--
  874.  
  875. return weight
  876. end
  877.  
  878. function getItemWeaponType(uid)
  879. local thing = getThing(uid)
  880. if(thing.itemid < 100) then
  881. return false
  882. end
  883.  
  884. return getItemInfo(thing.itemid).weaponType
  885. end
  886.  
  887. function getItemRWInfo(uid)
  888. local thing = getThing(uid)
  889. if(thing.itemid < 100) then
  890. return false
  891. end
  892.  
  893. local item, flags = getItemInfo(thing.itemid), 0
  894. if(item.readable) then
  895. flags = 1
  896. end
  897.  
  898. if(item.writable) then
  899. flags = flags + 2
  900. end
  901.  
  902. return flags
  903. end
  904.  
  905. function getItemLevelDoor(itemid)
  906. local item = getItemInfo(itemid)
  907. return item and item.levelDoor or false
  908. end
  909.  
  910. function isItemStackable(itemid)
  911. local item = getItemInfo(itemid)
  912. return item and item.stackable or false
  913. end
  914.  
  915. function isItemRune(itemid)
  916. local item = getItemInfo(itemid)
  917. return item and item.clientCharges or false
  918. end
  919.  
  920. function isItemDoor(itemid)
  921. local item = getItemInfo(itemid)
  922. return item and item.type == 5 or false
  923. end
  924.  
  925. function isItemContainer(itemid)
  926. local item = getItemInfo(itemid)
  927. return item and item.group == 2 or false
  928. end
  929.  
  930. function isItemFluidContainer(itemid)
  931. local item = getItemInfo(itemid)
  932. return item and item.group == 12 or false
  933. end
  934.  
  935. function isItemMovable(itemid)
  936. local item = getItemInfo(itemid)
  937. return item and item.movable or false
  938. end
  939.  
  940. function isCorpse(uid)
  941. local thing = getThing(uid)
  942. if(thing.itemid < 100) then
  943. return false
  944. end
  945.  
  946. local item = getItemInfo(thing.itemid)
  947. return item and item.corpseType ~= 0 or false
  948. end
  949.  
  950. function getContainerCapById(itemid)
  951. local item = getItemInfo(itemid)
  952. if(not item or item.group ~= 2) then
  953. return false
  954. end
  955.  
  956. return item.maxItems
  957. end
  958.  
  959. function getMonsterAttackSpells(name)
  960. local monster = getMonsterInfo(name)
  961. return monster and monster.attacks or false
  962. end
  963.  
  964. function getMonsterHealingSpells(name)
  965. local monster = getMonsterInfo(name)
  966. return monster and monster.defenses or false
  967. end
  968.  
  969. function getMonsterLootList(name)
  970. local monster = getMonsterInfo(name)
  971. return monster and monster.loot or false
  972. end
  973.  
  974. function getMonsterSummonList(name)
  975. local monster = getMonsterInfo(name)
  976. return monster and monster.summons or false
  977. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement