Advertisement
Guest User

Untitled

a guest
May 8th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.77 KB | None | 0 0
  1. --Circles
  2. AREA_CIRCLE2X2 =
  3. {
  4.     {0, 1, 1, 1, 0},
  5.     {1, 1, 1, 1, 1},
  6.     {1, 1, 3, 1, 1},
  7.     {1, 1, 1, 1, 1},
  8.     {0, 1, 1, 1, 0}
  9. }
  10.  
  11. AREA_CIRCLE3X3 =
  12. {
  13.     {0, 0, 1, 1, 1, 0, 0},
  14.     {0, 1, 1, 1, 1, 1, 0},
  15.     {1, 1, 1, 1, 1, 1, 1},
  16.     {1, 1, 1, 3, 1, 1, 1},
  17.     {1, 1, 1, 1, 1, 1, 1},
  18.     {0, 1, 1, 1, 1, 1, 0},
  19.     {0, 0, 1, 1, 1, 0, 0}
  20. }
  21.  
  22. -- Crosses
  23. AREA_CROSS1X1 =
  24. {
  25.     {0, 1, 0},
  26.     {1, 3, 1},
  27.     {0, 1, 0}
  28. }
  29.  
  30. AREA_CROSS5X5 =
  31. {
  32.     {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
  33.     {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
  34.     {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
  35.     {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  36.     {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  37.     {1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1},
  38.     {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  39.     {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  40.     {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
  41.     {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
  42.     {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}
  43. }
  44.  
  45. AREA_CROSS6X6 =
  46. {
  47.     {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
  48.     {0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
  49.     {0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
  50.     {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
  51.     {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
  52.     {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  53.     {1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1},
  54.     {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  55.     {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
  56.     {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
  57.     {0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
  58.     {0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
  59.     {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}
  60. }
  61.  
  62. --Squares
  63. AREA_SQUARE1X1 =
  64. {
  65.     {1, 1, 1},
  66.     {1, 3, 1},
  67.     {1, 1, 1}
  68. }
  69.  
  70. -- Walls
  71. AREA_WALLFIELD = {
  72.     {1, 1, 3, 1, 1}
  73. }
  74.  
  75. AREADIAGONAL_WALLFIELD =
  76. {
  77.     {0, 0, 0, 0, 1},
  78.     {0, 0, 0, 1, 1},
  79.     {0, 1, 3, 1, 0},
  80.     {1, 1, 0, 0, 0},
  81.     {1, 0, 0, 0, 0},
  82. }
  83.  
  84. emoteAttack = true
  85. petEmoteAttack = true
  86. refillStatsAtLevel = true
  87.  
  88. TYPE_NEAR = 1
  89. TYPE_DISTANCE = 2
  90.  
  91. petExhaust = 3 --in seconds
  92. petSayExhaust = 3 --in seconds
  93.  
  94. petGainTicks =
  95. {
  96.     health = {func = doCreatureAddHealth, time = 3000, count = 1},
  97.     mana = {func = doCreatureAddMana, time = 3000, count = 2}
  98. }
  99.  
  100. petGainHealth = 30
  101. petGainMana = 30
  102. petExpRate = 1.3
  103.  
  104. carryItems = 10
  105.  
  106. petItemsBase = 1250
  107. petItems = {}
  108. blockedItems = {6132, 2195}
  109.  
  110. for i = 1, carryItems do
  111.     table.insert(petItems, petItemsBase + i)
  112. end
  113.  
  114. petBase = 6120
  115. petStorages =
  116. {
  117.     pet = petBase + 1000,
  118.     level = petBase + 2000,
  119.     exp = petBase + 3000,
  120.     items = petBase + 4000,
  121.     isPet = petBase + 5000,
  122.     isDead = petBase + 6000,
  123.     exhaust = petBase + 7000,
  124.     sayExhaust = petBase + 8000,
  125.     moveExhaust = petBase + 9000,
  126.     health = petBase + 10000,
  127.     mana = petBase + 11000,
  128.     buyed = petBase + 12000
  129. }
  130.  
  131. tables =
  132. {
  133.     pet = {},
  134.     level = {},
  135.     exp = {},
  136.     items = {},
  137.     isDead = {},
  138.     exhaust = {},
  139.     health = {},
  140.     mana = {},
  141.     buyed = {}
  142. }
  143.  
  144. reviveCost = 1000
  145.  
  146. pets =
  147. {
  148.     [1] =
  149.     {
  150.         monster = "orc spearman",
  151.         vocations = {1, 2, 3, 4},
  152.         level = 30,
  153.         attacks =
  154.         {
  155.             [1] = {name = "", level = 30, petLevel = 30, mana = 50, type = TYPE_DISTANCE, range = 10, combat = COMBAT_PHYSICALDAMAGE, effect = CONST_ME_NONE, distEffect = CONST_ANI_SPEAR, damageMin = 0.7, damageMax = 1.0}
  156.         }
  157.     },
  158.     [2] =
  159.     {
  160.         monster = "fire devil",
  161.         vocations = {1, 2},
  162.         level = 60,
  163.         attacks =
  164.         {
  165.             [1] = {name = "Fire Strike", level = 60, petLevel = 60, mana = 100, type = TYPE_DISTANCE, combat = COMBAT_FIREDAMAGE, effect = CONST_ME_FIREDAMAGE, distEffect = CONST_ANI_FIRE, damageMin = 1.5, damageMax = 2.0}
  166.         }
  167.     },
  168.     [3] =
  169.     {
  170.         monster = "minotaur guard",
  171.         vocations = {3, 4},
  172.         level = 60,
  173.         cost = 50,
  174.         attacks =
  175.         {
  176.             [1] = {name = "Punch", level = 60, petLevel = 60, mana = 55, type = TYPE_NEAR, combat = COMBAT_PHYSICALDAMAGE, effect = CONST_ME_BLOOD, distEffect = CONST_ANI_NONE, damageMin = 1.5, damageMax = 2.0}
  177.         }
  178.     },
  179.     [4] =
  180.     {
  181.         monster = "water elemental",
  182.         vocations = {2},
  183.         level = 95,
  184.         cost = 15000,
  185.         attacks =
  186.         {
  187.             [1] = {name = "Ice Bomb", level = 100, petLevel = 100, mana = 250, type = TYPE_DISTANCE, range = 3, combat = COMBAT_ICEDAMAGE, effect = CONST_ME_ICEAREA, distEffect = CONST_ANI_ICE, damageMin = 1.5, damageMax = 2.0, area = AREA_CROSS1X1},
  188.             [2] = {name = "Poison Strike", level = 95, petLevel = 95, mana = 80, type = TYPE_DISTANCE, range = 8, combat = COMBAT_POISONDAMAGE, effect = CONST_ME_GREENRINGS, distEffect = CONST_ANI_POISON, damageMin = 1.2, damageMax = 1.8} 
  189.         }
  190.     },
  191.     [5] =
  192.     {
  193.         monster = "fire elemental",
  194.         vocations = {1},
  195.         level = 95,
  196.         attacks =
  197.         {
  198.             [1] = {name = "Fire Bomb", level = 100, petLevel = 100, mana = 250, type = TYPE_DISTANCE, range = 3, combat = COMBAT_FIREDAMAGE, effect = CONST_ME_FIRE, distEffect = CONST_ANI_FIRE, damageMin = 1.5, damageMax = 2.0, area = AREA_CROSS1X1},
  199.             [2] = {name = "Fire Strike", level = 95, petLevel = 95, mana = 80, type = TYPE_DISTANCE, range = 3, combat = COMBAT_FIREDAMAGE, effect = CONST_ME_FIREDAMAGE, distEffect = CONST_ANI_FIRE, damageMin = 1.2, damageMax = 1.8}   
  200.         }
  201.     },
  202.     [6] =
  203.     {
  204.         monster = "orc warlord",
  205.         vocations = {4},
  206.         level = 95,
  207.         attacks =
  208.         {
  209.             [1] = {name = "Throw Knife", level = 95, petLevel = 95, mana = 80, type = TYPE_DISTANCE, combat = COMBAT_PHYSICALDAMAGE, effect = CONST_ME_BLOOD, distEffect = CONST_ANI_THROWINGKNIFE, damageMin = 1.5, damageMax = 2.0}
  210.         }
  211.     },
  212.     [7] =
  213.     {
  214.         monster = "golem",
  215.         vocations = {3},
  216.         level = 95,
  217.         attacks =
  218.         {
  219.             [1] = {name = "Throw Stone", level = 95, petLevel = 95, mana = 80, type = TYPE_DISTANCE, combat = COMBAT_PHYSICALDAMAGE, effect = CONST_ME_BLOOD, distEffect = CONST_ANI_LARGEROCK, damageMin = 1.5, damageMax = 2.0}
  220.         }
  221.     },
  222.     [8] =
  223.     {
  224.         monster = "wyrm",
  225.         vocations = {1, 2, 3, 4},
  226.         level = 135
  227.     },
  228.     [9] =
  229.     {
  230.         monster = "dragon lord",
  231.         vocations = {1, 2, 3, 4},
  232.         level = 200,
  233.         attacks =
  234.         {
  235.             [1] = {name = "Fire Bomb", level = 200, petLevel = 200, mana = 300, type = TYPE_DISTANCE, range = 3, combat = COMBAT_FIREDAMAGE, effect = CONST_ME_FIREAREA, distEffect = CONST_ANI_FIRE, damageMin = 1.5, damageMax = 2.0, area = AREA_CROSS1X1},
  236.             [2] = {name = "Fire Storm", level = 205, petLevel = 220, mana = 700, type = TYPE_NEAR, range = 8, combat = COMBAT_FIREDAMAGE, effect = CONST_ME_FIREAREA, distEffect = CONST_ANI_FIRE, damageMin = 1.8, damageMax = 2.5, area = AREA_CROSS5X5},
  237.             [3] = {name = "Fire Explosion", level = 203, petLevel = 210, mana = 450, type = TYPE_DISTANCE, range = 6, combat = COMBAT_FIREDAMAGE, effect = CONST_ME_EXPLOSIONHIT, distEffect = CONST_ANI_FIRE, damageMin = 1.5, damageMax = 2.1, area = AREA_CIRCLE2X2},
  238.             [4] = {name = "Scratch", level = 201, petLevel = 205, mana = 150, type = TYPE_NEAR, range = 1, combat = COMBAT_PHYSICALDAMAGE, effect = CONST_ME_HITAREA, distEffect = CONST_ANI_FIRE, damageMin = 1.3, damageMax = 1.8},
  239.             [5] = {name = "Fire Strike", level = 203, petLevel = 210, mana = 100, type = TYPE_DISTANCE, range = 3, combat = COMBAT_FIREDAMAGE, effect = CONST_ME_EXPLOSIONAREA, distEffect = CONST_ANI_FIRE, damageMin = 1.8, damageMax = 1.9} 
  240.         }
  241.     }
  242. }
  243.  
  244. for i = 1, #pets do
  245.     table.insert(tables.pet, petStorages.pet + i)
  246.     table.insert(tables.level, petStorages.level + i)
  247.     table.insert(tables.exp, petStorages.exp + i)
  248.     table.insert(tables.items, petStorages.items + i)
  249.     table.insert(tables.isDead, petStorages.isDead + i)
  250.     table.insert(tables.exhaust, petStorages.exhaust + i)
  251.     table.insert(tables.health, petStorages.health + i)
  252.     table.insert(tables.mana, petStorages.mana + i)
  253.     table.insert(tables.buyed, petStorages.buyed + i)
  254. end
  255.  
  256. function gainStat(pid, stat)
  257.  
  258.     if pid and pid > 0 and isMonster(pid) then
  259.         stat.func(pid, stat.count)
  260.     end
  261.     addEvent(gainStat, stat.time, pid, stat)
  262. end
  263.  
  264. function getLevelByExp(exp)
  265.     return math.floor((math.sqrt(3) * math.sqrt(243*(exp+1)^2-48600*(exp+1)+3680000)+27 * (exp+1)-2700)^(1/3)/30^(2/3)-(5*10^(2/3))/(3^(1/3)*(math.sqrt(3)*math.sqrt(243*(exp+1)^2-48600*(exp+1)+3680000)+27*(exp+1)-2700)^(1/3))+2)
  266. end
  267.  
  268. function getPetInfo(pet)
  269.     if isNumber(pet) then
  270.         return pets[pet] or false
  271.     else
  272.         for _, v in pairs(pets) do
  273.             if pet:lower() == v.monster then
  274.                 return v
  275.             end
  276.         end
  277.     end
  278.     return false
  279. end
  280.  
  281. function getPetByLevel(cid)
  282.     local level = getPlayerLevel(cid)
  283.     local pet
  284.     for i = 1, #pets do
  285.         v = pets[i]
  286.         if level >= v.level and isInArray(v.vocations, getPlayerVocation(cid)) then
  287.             pet = v
  288.         end
  289.     end
  290.     return (pet ~= nil and pet or false)
  291. end
  292.  
  293. function getAttackFormula(pid, attack)
  294.     return {
  295.             min = ((getPetLevel(pid) * 2) * (1 + attack.damageMin) + getPetLevel(pid)) / 2.5,
  296.             max = ((getPetLevel(pid) * 3) * (1 + attack.damageMax) + getPetLevel(pid)) / 2.5
  297.            }
  298. end
  299.  
  300. function doAttack(pid, target, param)
  301.  
  302.     local pet = getPetInfo(getCreatureName(pid))
  303.     if pet then
  304.         if pet.attacks and pet.attacks[param] then
  305.             local attack = pet.attacks[param]
  306.             if target > 0 and pid ~= getCreatureTarget(getCreatureMaster(pid)) then
  307.                 if attack.type and attack.type == TYPE_DISTANCE and getDistanceBetween(getCreaturePosition(pid), getCreaturePosition(target)) > (attack.range or 3) or attack.type == TYPE_NEAR and getDistanceBetween(getCreaturePosition(pid), getCreaturePosition(target)) > (attack.range or 1) then
  308.                     return doPlayerSendCancel(getCreatureMaster(pid), "Target is too far.") and doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
  309.                 end
  310.                 if not isSightClear(getCreaturePosition(pid), getCreaturePosition(target), true) then
  311.                     return doPlayerSendCancel(getCreatureMaster(pid), "There is not enough room.") and doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
  312.                 end
  313.             else
  314.                 return doPlayerSendCancel(getCreatureMaster(pid), "Please select a target first.") and doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
  315.             end
  316.             if getPlayerLevel(getCreatureMaster(pid)) < attack.level then
  317.                 return doPlayerSendCancel(getCreatureMaster(pid), "You need level " .. attack.level .. " or higher to use this attack.") and doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
  318.             end
  319.             if getPetLevel(pid) < attack.petLevel then
  320.                 return doPlayerSendCancel(getCreatureMaster(pid), "Your pet needs level " .. attack.petLevel .. " or higher to use this attack.") and doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
  321.             end
  322.             if attack.mana and getCreatureMana(pid) < attack.mana then
  323.                 return doPlayerSendCancel(getCreatureMaster(pid), "Your pet does not have enough mana.") and doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
  324.             end
  325.             if attack.area then
  326.                 doCastAreaAttack(pid, target, attack.area, attack)
  327.             else
  328.                 doTargetCombatHealth(pid, target, attack.combat, -getAttackFormula(pid, attack).min, -getAttackFormula(pid, attack).max, attack.effect)
  329.             end
  330.             doCreatureAddMana(pid, -attack.mana)
  331.             if attack.name ~= "" then
  332.                 if emoteAttack then
  333.                     doCreatureSay(getCreatureMaster(pid), getCreatureName(pid) .. ", use " .. attack.name .. "!", TALKTYPE_SAY)
  334.                 end
  335.                 if petEmoteAttack then
  336.                     doCreatureSay(pid, attack.name, TALKTYPE_MONSTER)
  337.                 end
  338.             end
  339.             return doSendDistanceShoot(getCreaturePosition(pid), (attack.type == TYPE_DISTANCE and getCreaturePosition(target) or getCreaturePosition(pid)), attack.distEffect)
  340.         else
  341.             return doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
  342.         end
  343.     else
  344.         return doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF) and doPlayerSendCancel(getCreatureMaster(pid), "There is a tecnical problem, please contact a gamemaster.")
  345.     end
  346. end
  347.  
  348. function callPet(cid, petId)
  349.  
  350.     for i = 1, #tables do
  351.         for y = 1, #tables[i] do
  352.             if getCreatureStorage(cid, tables[i][y]) < 0 then
  353.                 doCreatureSetStorage(cid, tables[i][y], 0)
  354.             end
  355.         end
  356.     end
  357.  
  358.     local pet = getPetInfoById(petId)
  359.     if not pet then
  360.         return doPlayerSendCancel(cid, "Something is wrong.")
  361.     end
  362.  
  363.     if getPlayerLevel(cid) < pet.level then
  364.         return doPlayerSendCancel(cid, "You need level " .. pet.level .. " or higher to call this pet.")
  365.     end
  366.     if pet.cost and pet.cost > 0 then
  367.         if getCreatureStorage(cid, tables.buyed[petId]) < 1 then
  368.             return doPlayerSendCancel(cid, "You need to buy this pet first.") and doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
  369.         end
  370.     end
  371.  
  372.     local ret = doCreateMonster(pet.monster, getCreaturePosition(cid))
  373.  
  374.     if getCreatureStorage(cid, tables.level[petId]) < 1 then
  375.         doCreatureSetStorage(cid, tables.level[petId], pet.level)
  376.     end
  377.  
  378.     if getCreatureStorage(cid, tables.exp[petId]) < 1 then
  379.         doCreatureSetStorage(cid, tables.exp[petId], getExperienceForLevel(pet.level))
  380.     end
  381.  
  382.     if getCreatureStorage(cid, tables.level[petId]) < pet.level then
  383.         doCreatureSetStorage(cid, tables.level[petId], pet.level)
  384.     elseif getPlayerLevel(cid) * 3 < getCreatureStorage(cid, tables.level[petId]) then
  385.         doCreatureSetStorage(cid, tables.level[petId], pet.level)
  386.         doCreatureSetStorage(cid, tables.exp[petId], getExperienceForLevel(pet.level))
  387.     end
  388.  
  389.     if getLevelByExp(getCreatureStorage(cid, tables.exp[petId])) < getCreatureStorage(cid, tables.level[petId]) then
  390.         doCreatureSetStorage(cid, tables.exp[petId], getExperienceForLevel(getCreatureStorage(cid, tables.level[petId])))
  391.     end
  392.  
  393.     if getCreatureStorage(cid, tables.health[petId]) < 1 then
  394.         doCreatureSetStorage(cid, tables.health[petId], getCreatureStorage(cid, tables.level[petId]) * petGainHealth)
  395.     end
  396.  
  397.     if getCreatureStorage(cid, tables.mana[petId]) < 1 then
  398.         doCreatureSetStorage(cid, tables.mana[petId], getCreatureStorage(cid, tables.level[petId]) * petGainMana)
  399.     end
  400.  
  401.     doCreatureSetStorage(ret, tables.level[petId], getCreatureStorage(cid, tables.level[petId]))
  402.     doCreatureSetStorage(ret, tables.exp[petId], getCreatureStorage(cid, tables.exp[petId]))
  403.  
  404.     doConvinceCreature(cid, ret)
  405.     doCreatureSetStorage(ret, petStorages.isPet, 1)
  406.     doSendMagicEffect(getCreaturePosition(ret), CONST_ME_TELEPORT)
  407.     setCreatureMaxHealth(ret, getPetLevel(ret) * petGainHealth)
  408.     doCreatureAddHealth(ret, -getCreatureHealth(ret) + getCreatureStorage(cid, tables.health[petId]))
  409.     setCreatureMaxMana(ret, getPetLevel(ret) * petGainMana)
  410.     doCreatureAddMana(ret, -getCreatureMana(ret) + getCreatureStorage(cid, tables.mana[petId]))
  411.     for _, v in pairs(petGainTicks) do
  412.         gainStat(ret, v)
  413.     end
  414.     return doCreatureSay(cid, "Go pet!", TALKTYPE_SAY)
  415. end
  416.  
  417. function doCastAreaAttack(pid, target, area, attack)
  418.     local center = {}
  419.     local areaxx = {}
  420.     center.y = math.floor(#area/2)+1
  421.     for y = 1, #area do
  422.         for x = 1, #area[y] do
  423.             local number = area[y][x]
  424.             if number > 0 then
  425.                 center.x = math.floor(table.getn(area[y])/2)+1
  426.                 if attack.type == TYPE_DISTANCE then
  427.                     table.insert(areaxx, {x = getCreaturePosition(target).x + x - center.x, y = getCreaturePosition(target).y + y - center.y, z = getCreaturePosition(target).z})
  428.                 else
  429.                     table.insert(areaxx, {x = getCreaturePosition(pid).x + x - center.x, y = getCreaturePosition(pid).y + y - center.y, z = getCreaturePosition(pid).z})
  430.                 end            
  431.             end
  432.         end
  433.     end
  434.     for i = 1, #areaxx do
  435.         doAreaCombatHealth(pid, attack.combat, areaxx[i], 0, -getAttackFormula(pid, attack).min, -getAttackFormula(pid, attack).max, attack.effect)
  436.     end
  437. end
  438.  
  439. function isPet(pid)
  440.     local id = getPetIdByName(getCreatureName(pid))
  441.     return getCreatureStorage(pid, petStorages.isPet) > 0 and true or false
  442. end
  443.  
  444. function doPetAddExperience(pid, exp)
  445.  
  446.     local id = getPetIdByName(getCreatureName(pid))
  447.     exp = math.ceil(exp)
  448.     doCreatureSetStorage(getCreatureMaster(pid), tables.exp[id], getPetExperience(pid) + exp)
  449.     doSendAnimatedText(getCreaturePosition(pid), exp, getConfigValue("gainExperienceColor"))
  450.     return true
  451. end
  452.  
  453. function getPetExperience(pid)
  454.     local id = getPetIdByName(getCreatureName(pid))
  455.     return getCreatureStorage(getCreatureMaster(pid), tables.exp[id])
  456. end
  457.  
  458. function getPetLevel(pid)
  459.     local id = getPetIdByName(getCreatureName(pid))
  460.     return getCreatureStorage(getCreatureMaster(pid), tables.level[id])
  461. end
  462.  
  463. function doPetSetLevel(pid, level)
  464.  
  465.     local id = getPetIdByName(getCreatureName(pid))
  466.     doCreatureSetStorage(getCreatureMaster(pid), tables.level[id], level)
  467.     setCreatureMaxHealth(pid, getPetLevel(pid) * petGainHealth)
  468.     setCreatureMaxMana(pid, getPetLevel(pid) * petGainMana)
  469.     return true
  470. end
  471.  
  472. function getPlayerPet(cid)
  473.     local pet
  474.     if #getCreatureSummons(cid) < 1 then
  475.         pet = false
  476.     end
  477.  
  478.     for _, it in ipairs(getCreatureSummons(cid)) do
  479.         if isPet(it) then
  480.             pet = it
  481.             break
  482.         end
  483.     end
  484.     return pet
  485. end
  486.  
  487. function getPetIdByName(name)
  488.  
  489.     local id = 0
  490.     for k, it in pairs(pets) do
  491.         if it.monster:lower() == name:lower() then
  492.             id = k
  493.             break
  494.         end
  495.     end
  496.     return (id > 0 and id or false)
  497. end
  498.  
  499. function getTopItem(p)
  500.     p.stackpos = 0
  501.     local v = getThingFromPos(p)
  502.     repeat
  503.         p.stackpos = p.stackpos + 1
  504.         v = getThingFromPos(p)
  505.     until v.itemid == 0
  506.     p.stackpos = p.stackpos - 1
  507.     return getThingFromPos(p)
  508. end
  509.  
  510. function getPetInfoById(pet)
  511.     for k, v in pairs(pets) do
  512.         if k == pet then
  513.             return v
  514.         end
  515.     end
  516.     return false
  517. end
  518.  
  519. if not getCreatureStorage then
  520.     getCreatureStorage = getPlayerStorageValue
  521.     doCreatureSetStorage = doPlayerSetStorageValue
  522. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement