local time = {22, 08}
local mintoanswer = 5 -- minutes to answer anti bot system
local delayAntiBot = 60 -- minutes of delay of delayAntiBot
local maxgroupid = 1 -- groupid higher than this don't have antiBotSystem Activated
local prisonpos = {x=494, y=538, z=9} -- if don't answer, go to this pos
local prisonminutes = 180 -- time inside the prison
local botter = 15850 -- time inside the prison
local templepos = {x=498, y=541, z=9} -- after the prisonminutes, back to this position (temple is recommended)
local storages = {first_num = 3, second_num = 4, result = 5, answer = 6, prisoned = 7, prisontime = 8, wrong_answers = 9}
prisonEvent, antiBotEvent, checkAnswerEvent = {}, {}, {}
local function checkprisoned(cid)
if getCreatureStorage(cid, storages.prisoned) == 1 then
if os.time() >= getCreatureStorage(cid, storages.prisontime) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'You had completed your time here in the prison! You may now relog to go to the city.')
else
prisonEvent[cid] = addEvent(checkprisoned, 1000, cid)
end
end
end
local function checkAnswer(cid)
local wrong = getCreatureStorage(cid, storages.wrong_answers)
if wrong > 5 or (getCreatureStorage(cid, storages.answer) ~= 1 and getCreatureStorage(cid, storages.prisoned) ~= 1 and getCreatureStorage(cid, storages.result) ~= -1) then
doCreatureSetStorage(cid, botter, 1)
db.query('UPDATE players SET botter=1 WHERE id='..getPlayerGUID(cid))
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, wrong > 5 and 'Time limit! You have been tagged as BOTTER because you answered wrong too many times.' or 'Time limit! You had been tagged as BOTTER.')
else
doCreatureSetStorage(cid, storages.prisoned)
end
doCreatureSetStorage(cid, storages.first_num)
doCreatureSetStorage(cid, storages.second_num)
doCreatureSetStorage(cid, storages.result)
doCreatureSetStorage(cid, storages.answer)
doCreatureSetStorage(cid, storages.wrong_answers)
end
local function append(l)
local s = ''
for i = 1, math.random(l) do
s = s .. string.char(math.random(2) == 1 and math.random(65, 90) or math.random(97, 122))
end
return s
end
local function antiBot(cid)
if getCreatureStorage(cid, botter) == -1 and getCreatureStorage(cid, 38417) == -1 then
local r, first, second = math.random(3), math.random(9), math.random(9)
r = r==1 and '+' or r==2 and '*' or '-'
local s = append(2) .. first .. append(4) .. r .. append(2) .. second .. append(4)
doCreatureSetStorage(cid, storages.first_num, first)
doCreatureSetStorage(cid, storages.second_num, second)
doCreatureSetStorage(cid, storages.result, math.ceil(loadstring('return '..first..r..second)()))
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Anti Bot System: You have '.. mintoanswer ..' minutes to answer how much is '.. s ..'. (Desconsider the letters) To answer say: !antibot number (In case you want to be AFK or train skills, use !afk on)')
doPlayerSendTextMessage(cid, 22, 'Anti Bot System: Example: P8VM-O2W, desconsidering the letters it is 8-2, wich is 6, then you would say !antibot 6 ... Where* multiply / divide - subtract + sum')
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Anti Bot System: Você tem '.. mintoanswer ..' minutos para responder quanto é '.. s ..'. (Desconsidere as letras) Para responder digite: !antibot número (Caso deseje treinar skill ou ficar afk utilize !afk on)')
doPlayerSendTextMessage(cid, 22, 'Anti Bot System: Exemplo: P8VM-O2W, desconsiderando as letras dá 8-2, que é igual a 6, então você deve responder !antibot 6 ... Sendo * multiplicar / dividir - subtrair + somar')
checkAnswerEvent[cid] = addEvent(checkAnswer, mintoanswer*60*1000, cid)
end
antiBotEvent[cid] = addEvent(antiBot, delayAntiBot*60*1000, cid)
end
function onAttack(cid, target)
local n = tonumber(os.date('%H'))
if (n >= time[1] or n < time[2]) and getPlayerGroupId(cid) <= maxgroupid then
if not isPlayer(target) then
if getCreatureCondition(cid, CONDITION_INFIGHT) == TRUE and getCreatureStorage(cid, 38417) == -1 then
antiBotEvent[cid] = addEvent(antiBot, 1000, cid)
end
end
end
return true
end
function onLogin(cid)
registerCreatureEvent(cid, 'Logout')
if getCreatureStorage(cid, storages.prisoned) == 1 then
if os.time() >= getCreatureStorage(cid, storages.prisontime) then
doCreatureSetStorage(cid, storages.prisontime)
doCreatureSetStorage(cid, storages.prisoned)
doTeleportThing(cid, templepos)
else
prisonEvent[cid] = addEvent(checkprisoned, 1000, cid)
doTeleportThing(cid, prisonpos)
end
end
return true
end
function onLogout(cid)
if prisonEvent[cid] then
stopEvent(prisonEvent[cid])
prisonEvent[cid] = nil
end
if antiBotEvent[cid] then
stopEvent(antiBotEvent[cid])
antiBotEvent[cid] = nil
end
if checkAnswerEvent[cid] then
stopEvent(checkAnswerEvent[cid])
checkAnswerEvent[cid] = nil
end
doCreatureSetStorage(cid, storages.first_num)
doCreatureSetStorage(cid, storages.second_num)
doCreatureSetStorage(cid, storages.result)
doCreatureSetStorage(cid, storages.answer)
doCreatureSetStorage(cid, storages.wrong_answers)
return true
end