local config = { healthMultiplier = 1.0, manaMultiplier = 1.0 } last_use = {} uses_in_this_second = {} uses_in_interval = {} uses_in_interval_same_IP = {} list_of_users = {} intervalCheck = 600 lastCheck = os.time() + intervalCheck maxPotionsPerInterval = 1 maxPotionsPerSecond = 2 local POTIONS = { [8704] = {empty = 7636, splash = 2, health = {50, 100}}, -- small health potion [7618] = {empty = 7636, splash = 2, health = {100, 200}}, -- health potion [7588] = {empty = 7634, splash = 2, health = {350, 500}, vocations = {3, 4, 7, 8}, vocStr = "knights and paladins"}, -- strong health potion [7591] = {empty = 7635, splash = 2, health = {450, 700}, level = 80, vocations = {4, 8}, vocStr = "knights"}, -- great health potion [8473] = {empty = 7635, splash = 2, health = {650, 950}, level = 130, vocations = {4, 8}, vocStr = "knights"}, -- ultimate health potion [7620] = {empty = 7636, splash = 7, mana = {90, 150}}, -- mana potion [7589] = {empty = 7634, splash = 7, mana = {170, 210}, vocations = {1, 2, 3, 5, 6, 7}, vocStr = "sorcerers, druids and paladins"}, -- strong mana potion [7590] = {empty = 7635, splash = 7, mana = {200, 320}, level = 80, vocations = {1, 2, 5, 6}, vocStr = "sorcerers and druids"}, -- great mana potion [8472] = {empty = 7635, splash = 3, health = {260, 400}, mana = {120, 180}, level = 80, vocations = {3, 7}, vocStr = "paladins"} -- great spirit potion } local exhaust = createConditionObject(CONDITION_EXHAUST) setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100)) function onUse(cid, item, fromPosition, itemEx, toPosition) if lastCheck < os.time() then lastCheck = os.time() + intervalCheck local cheaters = {} for guid, users in pairs(list_of_users) do if uses_in_interval[guid] >= maxPotionsPerInterval then usersIDs = '' for i = 1, #users do usersIDs = usersIDs .. ',' .. users[i] end db.executeQuery("INSERT INTO `z_manabots` (`player_id`, `player_name`, `time`, `time_string`, `potion_uses`, `friends` , `same_ip`) VALUES (" .. guid .. ", " .. db.escapeString(getPlayerNameByGUID(guid)) .. ", " .. os.time() .. ", " .. db.escapeString(os.date("%Y/%m/%d %H:%M:%S")) .. ", " .. uses_in_interval[guid] .. ", " .. db.escapeString(IDs) .. ", " .. uses_in_interval_same_IP[guid] .. ");") end end last_use = {} uses_in_this_second = {} uses_in_interval = {} uses_in_interval_same_IP = {} list_of_users = {} end local potion = POTIONS[item.itemid] if(not potion) then return false end if(not isPlayer(itemEx.uid)) then return false end --can not use in protection zone if getTilePzInfo(getCreaturePosition(cid)) == TRUE and potion.mana then doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can not drink mana potions in protection zone.") return true end -- can not use on other players in train room if itemEx.uid ~= cid and getPlayerStorageValue(itemEx.uid, 1337) == 1 and potion.mana then doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can not use mana potions on other players in train room.") return true end if(((potion.level and getPlayerLevel(cid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, getPlayerVocation(cid)))) and not getPlayerCustomFlagValue(cid, PlayerCustomFlag_GamemasterPrivileges)) then doCreatureSay(itemEx.uid, "Only " .. potion.vocStr .. (potion.level and (" of level " .. potion.level) or "") .. " or above may drink this fluid.", TALKTYPE_ORANGE_1) return true end -- count uses if potion.mana then local targetGUID = getPlayerGUID(itemEx.uid) local userGUID = getPlayerGUID(cid) if last_use[targetGUID] == nil then last_use[targetGUID] = os.time() uses_in_this_second[targetGUID] = 1 uses_in_interval[targetGUID] = 1 uses_in_interval_same_IP[targetGUID] = 0 list_of_users[targetGUID] = {userGUID} elseif last_use[targetGUID] == os.time() then uses_in_this_second[targetGUID] = uses_in_this_second[targetGUID] + 1 uses_in_interval[targetGUID] = uses_in_interval[targetGUID] + 1 else last_use[targetGUID] = os.time() uses_in_this_second[targetGUID] = 1 uses_in_interval[targetGUID] = uses_in_interval[targetGUID] + 1 end addList = true for i = 1, #list_of_users[targetGUID] do if list_of_users[targetGUID][i] == userGUID then addList = false break end end if addList == true then if getPlayerIp(cid) == getPlayerIp(itemEx.uid) then uses_in_interval_same_IP[targetGUID] = uses_in_interval_same_IP[targetGUID] + 1 end table.insert(list_of_users[targetGUID], userGUID) end -- check number of mana potions used on target in this second (block) if itemEx.uid ~= cid and uses_in_this_second[targetGUID] > maxPotionsPerSecond then doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE) doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1) return false end end local health = potion.health if(health and not doCreatureAddHealth(itemEx.uid, math.ceil(math.random(health[1], health[2]) * config.healthMultiplier))) then return false end local mana = potion.mana local addMana = math.ceil(math.random(mana[1], mana[2]) * config.manaMultiplier) if(mana and not doPlayerAddMana(itemEx.uid, addMana)) then return false end doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE) doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1) doAddCondition(cid, exhaust) return true end