• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

RevScripts [TALKACTION] - Check cavebot players.

OTcreator

Active Member
Joined
Feb 14, 2022
Messages
438
Solutions
1
Reaction score
47
Welcome.
TFS [1.4.2]

Is anyone able to write talkactions, at least the basis that works on the principle:

1.) Player types !checkbot NICK.
2.) He can check only those who have storage XXXX.
3.) It can check if it is within 5 bars of the player.
4.) Can only check a player who has not been checked in the last hour.
5.)Anyone can only be checked 5 times a day.

Suppose the conditions are met.
After typing !checkbot NICK - the player gets a question (random, hour, day, etc.).
If he types !noafk RESPONSE - the correct one is something there.
If he does not answer within 5 minutes - something there.

Thank you for all your efforts.
 
It will save you a lot of time if you just pay 20.00 a month with chat gpt and code with it. Just saying.
Post automatically merged:

Welcome.
TFS [1.4.2]

Is anyone able to write talkactions, at least the basis that works on the principle:

1.) Player types !checkbot NICK.
2.) He can check only those who have storage XXXX.
3.) It can check if it is within 5 bars of the player.
4.) Can only check a player who has not been checked in the last hour.
5.)Anyone can only be checked 5 times a day.

Suppose the conditions are met.
After typing !checkbot NICK - the player gets a question (random, hour, day, etc.).
If he types !noafk RESPONSE - the correct one is something there.
If he does not answer within 5 minutes - something there.

Thank you for all your efforts.


Here this is example Chat Gpt did for me I do not know if it works at all. As I am using my phone.

Lua:
local botCheck = TalkAction("!checkbot")

function botCheck.onSay(player, words, param)
    local target = Player(param)
    if not target then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "A player with this name is not online.")
        return false
    end

    if player:getStorageValue(XXXX) <= 0 then -- Replace XXXX with your storage key
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot use this command.")
        return false
    end

    if target:getPosition():getDistance(player:getPosition()) > 5 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are too far away from the player.")
        return false
    end

    local checkTime = player:getStorageValue(target:getGuid() + 10000)
    if os.time() - checkTime < 3600 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You can only check a player once every hour.")
        return false
    end

    local dailyChecks = player:getStorageValue(target:getGuid() + 20000)
    if dailyChecks >= 5 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You have reached your check limit for today.")
        return false
    end

    local questions = {
        { question = "What day is it today?", answer = "Monday" },
        { question = "What is 2+2?", answer = "4" }
    }

    local randomQuestion = math.random(#questions)
    player:setStorageValue(target:getGuid() + 30000, randomQuestion) -- storing question index
    player:setStorageValue(target:getGuid() + 10000, os.time()) -- update last check time
    player:setStorageValue(target:getGuid() + 20000, dailyChecks + 1) -- update daily check count
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Question: " .. questions[randomQuestion].question)

    addEvent(function()
        if player:getStorageValue(target:getGuid() + 30000) ~= 0 then
            player:setStorageValue(target:getGuid() + 30000, 0)
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "Time's up for the question!")
        end
    end, 300 * 1000) -- 5 minutes timer

    return true
end

botCheck:separator(" ")
botCheck:register()
 
Last edited:
It will save you a lot of time if you just pay 20.00 a month with chat gpt and code with it. Just saying.
Post automatically merged:




Here this is example Chat Gpt did for me I do not know if it works at all. As I am using my phone.

Lua:
local botCheck = TalkAction("!checkbot")

function botCheck.onSay(player, words, param)
    local target = Player(param)
    if not target then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "A player with this name is not online.")
        return false
    end

    if player:getStorageValue(XXXX) <= 0 then -- Replace XXXX with your storage key
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot use this command.")
        return false
    end

    if target:getPosition():getDistance(player:getPosition()) > 5 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are too far away from the player.")
        return false
    end

    local checkTime = player:getStorageValue(target:getGuid() + 10000)
    if os.time() - checkTime < 3600 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You can only check a player once every hour.")
        return false
    end

    local dailyChecks = player:getStorageValue(target:getGuid() + 20000)
    if dailyChecks >= 5 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You have reached your check limit for today.")
        return false
    end

    local questions = {
        { question = "What day is it today?", answer = "Monday" },
        { question = "What is 2+2?", answer = "4" }
    }

    local randomQuestion = math.random(#questions)
    player:setStorageValue(target:getGuid() + 30000, randomQuestion) -- storing question index
    player:setStorageValue(target:getGuid() + 10000, os.time()) -- update last check time
    player:setStorageValue(target:getGuid() + 20000, dailyChecks + 1) -- update daily check count
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Question: " .. questions[randomQuestion].question)

    addEvent(function()
        if player:getStorageValue(target:getGuid() + 30000) ~= 0 then
            player:setStorageValue(target:getGuid() + 30000, 0)
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "Time's up for the question!")
        end
    end, 300 * 1000) -- 5 minutes timer

    return true
end

botCheck:separator(" ")
botCheck:register()
Just a few things....
1) You're sending the question to the player who typed !checkbot, not the player he wants to check.... (if im not mistaken)
2) The addEvent is the same, and also dangerous as there is no guarantee the "target"(which it should be) is still in memory. They could have died/logged out etc. You need to pass the id of the player as a parameter of addEvent into the function, and try to recreate the Player class first and check it exists.
 
They can create thousands of systems for this, the best thing is for the GM to go to the player and check it himself. After all, that's the GM's job. human work 100x better than these things.
 
They can create thousands of systems for this, the best thing is for the GM to go to the player and check it himself. After all, that's the GM's job. human work 100x better than these things.
True but when it comes to scripting for myself. Time matters plus whenever I use AI I teach it. I only showed example here is your job to let AI know what you actually using so... I can create script I need in 1 minute. It works with no issues mostly with 1st creation.
 
Welcome.
TFS [1.4.2]

Is anyone able to write talkactions, at least the basis that works on the principle:

1.) Player types !checkbot NICK.
2.) He can check only those who have storage XXXX.
3.) It can check if it is within 5 bars of the player.
4.) Can only check a player who has not been checked in the last hour.
5.)Anyone can only be checked 5 times a day.

Suppose the conditions are met.
After typing !checkbot NICK - the player gets a question (random, hour, day, etc.).
If he types !noafk RESPONSE - the correct one is something there.
If he does not answer within 5 minutes - something there.

Thank you for all your efforts.
Very good idea!
 
Just a few things....
3) Setting offset to 10000 between storage ranges (10000, 20000 and 30000) will make this script fail, if there are more than 10k players in database:
Lua:
    player:setStorageValue(target:getGuid() + 30000, randomQuestion) -- storing question index
    player:setStorageValue(target:getGuid() + 10000, os.time()) -- update last check time
    player:setStorageValue(target:getGuid() + 20000, dailyChecks + 1) -- update daily check count
Obvious solution is to use guid * number_of_storages and offset with +0, +1, +2 etc. ex.:
Lua:
    player:setStorageValue(target:getGuid() * 3 + 10000 + 0, randomQuestion) -- storing question index
    player:setStorageValue(target:getGuid() * 3 + 10000 + 1, os.time()) -- update last check time
    player:setStorageValue(target:getGuid() * 3 + 10000 + 2, dailyChecks + 1) -- update daily check count
4) Setting offset to low value like 10000 will make it randomly block chest quest system which uses UIDs 0-65535 to store, if quest was made by player ( forgottenserver/data/actions/scripts/quests/quests.lua at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/data/actions/scripts/quests/quests.lua#L32) )

20$ and 5 seconds later we got script that will:
🤣
You would not find any of these bugs by testing this script in game with 2 players on local PC.
 
Lua:
local checkbotStorage = XXXX
local lastCheckStorage = 444220
local dailyCheckCountStorage = 444221
local correctResponseStorage = 444222
local noResponseStorage = 444223
local maxDailyChecks = 5
local checkCooldown = 3600 -- 1 hour in seconds
local questionTimeout = 300 -- 5 minutes in seconds

local questions = {
    ["What is 2+2?"] = "4",
    ["What is the color of the sky?"] = "blue",
    ["What is 5*3?"] = "15"
}

local function askQuestion(targetPlayer, player, question)
    targetPlayer:setStorageValue(correctResponseStorage, os.time() + questionTimeout)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been asked a question: " .. question)
end

local function onNoResponse(playerId)
    local targetPlayer = Player(playerId)
    if targetPlayer and os.time() > targetPlayer:getStorageValue(correctResponseStorage) then
        targetPlayer:setStorageValue(noResponseStorage, (targetPlayer:getStorageValue(noResponseStorage) or 0) + 1)
        targetPlayer:sendTextMessage(MESSAGE_INFO_DESCR, "You did not answer the question in time.")
    end
end

local function handleCheck(player, targetPlayer)
    if player:getStorageValue(checkbotStorage) == -1 then
        player:setStorageValue(checkbotStorage, 0)
    end

    if player:getStorageValue(dailyCheckCountStorage) == -1 then
        player:setStorageValue(dailyCheckCountStorage, 0)
    end

    local lastCheck = player:getStorageValue(lastCheckStorage) or 0
    if os.time() - lastCheck < checkCooldown then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You can only check a player once every hour.")
        return false
    end

    local dailyChecks = player:getStorageValue(dailyCheckCountStorage) or 0
    if dailyChecks >= maxDailyChecks then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You have reached the maximum number of checks for today.")
        return false
    end

    if not targetPlayer:getPosition():isInRange(player:getPosition(), 5) then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "The player is not within range.")
        return false
    end

    if targetPlayer:getStorageValue(checkbotStorage) == -1 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "The player is not eligible to be checked.")
        return false
    end

    local question, response = next(questions)
    askQuestion(targetPlayer, player, question)

    player:setStorageValue(lastCheckStorage, os.time())
    player:setStorageValue(dailyCheckCountStorage, dailyChecks + 1)

    addEvent(onNoResponse, questionTimeout * 1000, targetPlayer:getId())

    return true
end

local function onSayCheckbot(player, words, param)
    if not param or param == "" then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to specify a player name.")
        return false
    end

    local targetPlayer = Player(param)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Player not found.")
        return false
    end

    return handleCheck(player, targetPlayer)
end

local function onAnswer(player, words, param)
    local expectedResponse = questions[player:getStorageValue(correctResponseStorage)]
    if param == expectedResponse then
        player:setStorageValue(correctResponseStorage, (player:getStorageValue(correctResponseStorage) or 0) + 1)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Correct answer! You have been awarded.")
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Incorrect answer or no question asked.")
    end
end

function onSay(player, words, param)
    if words == "!checkbot" then
        return onSayCheckbot(player, words, param)
    elseif words == "!noafk" then
        return onAnswer(player, words, param)
    end
    return false
end

Just to clarify I am using Canary so TFS 1.4 is a bit of black magic to me. XD will not attempt anymore as I know there is much more to creatr such talkaction.
 
Last edited:
Instead of talkaction store every fishing conjure kill actions use and point player and when he amassed 10k points do a check would be automated and based on how active but really just look at online session time and u get 99 convictions
 
I think I managed without events.
I still need to refine it.
The person who does not respond , will receive one warning.
Another non-response is already death on the spot, without stopping the backpack, even if it has aol or full bless.

GM is not always in the game, and bots block resps.
So if someone is on the resp, that is, those minimum 10 bars from the player, he can check him, if he does not answer he flies out of the resp.
 
I think I managed without events.
I still need to refine it.
The person who does not respond , will receive one warning.
Another non-response is already death on the spot, without stopping the backpack, even if it has aol or full bless.

GM is not always in the game, and bots block resps.
So if someone is on the resp, that is, those minimum 10 bars from the player, he can check him, if he does not answer he flies out of the resp.
teleporting them out and giving them storage coudl work too i guess.
You could use multiworld and banned players would be moved to Bot world. where they are "banished" but still in game if they choose to hmm
 
Code:
local checkbotStorage = XXXX
local lastCheckStorage = 444220
local dailyCheckCountStorage = 444221
local correctResponseStorage = 444222
local noResponseStorage = 444223
local maxDailyChecks = 5
local checkCooldown = 3600 -- 1 hour in seconds
local questionTimeout = 300 -- 5 minutes in seconds

local questions = {
    ["What is 2+2?"] = "4",
    ["What is the color of the sky?"] = "blue",
    ["What is 5*3?"] = "15"
}

local function askQuestion(targetPlayer, player, question)
    targetPlayer:setStorageValue(correctResponseStorage, os.time() + questionTimeout)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been asked a question: " .. question)
end

local function onNoResponse(targetPlayer)
    if os.time() > targetPlayer:getStorageValue(correctResponseStorage) then
        targetPlayer:setStorageValue(noResponseStorage, (targetPlayer:getStorageValue(noResponseStorage) or 0) + 1)
        targetPlayer:sendTextMessage(MESSAGE_INFO_DESCR, "You did not answer the question in time.")
    end
end

local function onSay(player, words, param)
    if not param or param == "" then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to specify a player name.")
        return false
    end

    local targetPlayer = Player(param)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Player not found.")
        return false
    end

    if player:getStorageValue(checkbotStorage) == -1 then
        player:setStorageValue(checkbotStorage, 0)
    end

    if player:getStorageValue(dailyCheckCountStorage) == -1 then
        player:setStorageValue(dailyCheckCountStorage, 0)
    end

    local lastCheck = player:getStorageValue(lastCheckStorage) or 0
    if os.time() - lastCheck < checkCooldown then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You can only check a player once every hour.")
        return false
    end

    local dailyChecks = player:getStorageValue(dailyCheckCountStorage) or 0
    if dailyChecks >= maxDailyChecks then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You have reached the maximum number of checks for today.")
        return false
    end

    if not targetPlayer:getPosition():isInRange(player:getPosition(), 5) then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "The player is not within range.")
        return false
    end

    if targetPlayer:getStorageValue(checkbotStorage) == -1 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "The player is not eligible to be checked.")
        return false
    end

    local question, response = next(questions)
    askQuestion(targetPlayer, player, question)

    player:setStorageValue(lastCheckStorage, os.time())
    player:setStorageValue(dailyCheckCountStorage, dailyChecks + 1)

    addEvent(onNoResponse, questionTimeout * 1000, targetPlayer)

    return true
end

local function onAnswer(player, words, param)
    local expectedResponse = questions[player:getStorageValue(correctResponseStorage)]
    if param == expectedResponse then
        player:setStorageValue(correctResponseStorage, (player:getStorageValue(correctResponseStorage) or 0) + 1)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Correct answer! You have been awarded.")
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Incorrect answer or no question asked.")
    end
end

function onSay(player, words, param)
    if words == "!checkbot" then
        return onSay(player, words, param)
    elseif words == "!noafk" then
        return onAnswer(player, words, param)
    end
    return false
end

Just to clarify I am using Canary so TFS 1.4 is a bit of black magic to me. XD will not attempt anymore as I know there is much more to creatr such talkaction.
Well, unfortunately you haven't gone through the thread ([TFS 1.x+] How to NOT write LUA scripts or how to crash server by LUA script (https://otland.net/threads/tfs-1-x-how-to-not-write-lua-scripts-or-how-to-crash-server-by-lua-script.271018/)) that Gesior has posted earlier - you're passing a player object as an argument to an addEvent function, which means it will crash as soon as the player relogs.
Post automatically merged:

I wrote the script for you, however I haven't tested it so there might be some issues. The penalty function is not defined because you haven't really specified any conditions but I guess you can take it from here. Good luck!

Lua:
local config = {
  allowCheckFromDistance = 5, -- allow the use of talkaction in range of x sqm's
  allowedDailyCheckInvocations = 5, -- allow the talkaction to be invoked x times daily by a player
  allowedDailyCheckInpections = 5, -- amount of times a player can be checked
  allowToPerfomCheckOnStorageValue = 1, -- allow to perfom the talkaction on players with storages.isCheckable set to x value
  executePenaltyAfter = 3, -- trigger the penalty after 3 unsuccessful checks

  warningInterval = 1 * 60, -- send warning message every minute
  answerDuration = 5 * 60, -- 5 minutes
  checkDelay = 60 * 60, -- 60 minutes

  storages = {
    isCheckable = 80500,
    dailyCheckInvocation = 80501, -- amount of times the player has invoked the talkaction
    dailyCheckInspection = 80502, -- amount of times a player has been checked
    failedCheckCount = 80503, -- amount of unsuccessful checks
    lastCheck = 80504, -- time when the players was last checked
  },

  questions = {
    -- "question" = "answer",
    ["What is 2+2?"] = 4,
    ["What is 5 x 3?"] = 15,
  },

  messages = {
    onWarningMessage = "You have %s minutes left to answer the question.",
    onCorrectAnswer = "Congratulations! You\'ve successfullly answered the question.",
    onWrongAnswer = "You\'ve provided a wrong answer to the question. You have received a warning.",
    onTooManyChecks = "This player has been checked too many times today and cannot be checked again until tomorrow.",
    onAnswerTimeOut = "You\'ve not answered the question within allowed time limit. You have received a warning.",
    onDailyLimitReached = "You have reached your daily limit of checks and cannot check any more players today.",
    onCheckCount = "You currently have %s/%s warnings.",
    onHelpCheckBot = "Type !checkbot NICK to check if a player is a bot. They must answer a question within 5 minutes.",
    onHelpNoAfk = "Type !noafk RESPONSE to prove that you\'re not a botter.",
    onCheckInitiated = "You have initiated a check on %s. They must respond within %s minutes.",
    onPlayerRecentlyChecked = "This player was checked recently and cannot be checked again yet.",
    onPlayerPendingCheck = "This player is currently undergoing a check. Please try again later.",
    onPlayerNotCheckable = "This player is not checkable.",
    onPlayerNotFound = "Player %s is either offline or doesn\'t exist.",
    onPlayerTooFar = "This player is too far away from you. You need to be within %s sqm\'s to invoke this command.",
    onPlayerInspection = "%s has performed a check on you. Answer the following question: %s within %s minutes. Respond with !noafk RESPONSE.",
    onFailToProvideAnswer = "%s has either exceeded the time limit or responded wrongly to the question. He has been penalized.",
    onSuccessToProvideAnswer = "%s has successfully answered the question.",
    onPenalty = "You have failed at the BotCheck. You will now receive a penalty.",
    onNotUndergoingCheck = "You\'re not being checked."
  },
}

local BotCheck = {}
BotCheck.questions = {}
BotCheck.pendingChecks = {}

BotCheck.formatTime = function(sec)
  local minutes = math.floor(sec / 60)
  local seconds = sec % 60
  return string.format("%02d:%02d", minutes, seconds)
end

BotCheck.drawRandomQuestion = function()
  if #BotCheck.questions == 0 then
    for question in pairs(config.questions) do
      table.insert(BotCheck.questions, question)
    end
  end

  local randomIndex = math.random(#BotCheck.questions)
  local question = BotCheck.questions[randomIndex]
  local answer = config.questions[question]
  return question, answer
end

BotCheck.perfomCheck = function(playerGuid, targetPlayerGuid)
  local player = Player(playerGuid)
  local targetPlayer = Player(targetPlayerGuid)
  if not player or not targetPlayer then return end

  -- Get random question
  local question, answer = BotCheck.drawRandomQuestion()

  -- Get answer duration
  local answerDuration = BotCheck.formatTime(config.answerDuration)

  -- Send message to the target player
  local targetPlayerMessage = string.format(config.messages.onPlayerInspection, player:getName(), question, answerDuration)
  targetPlayer:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, targetPlayerMessage)

  -- Send message to the player
  local playerMessage = string.format(config.messages.onCheckInitiated, targetPlayer:getName(), answerDuration)
  player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, playerMessage)

  -- Add a record to pending checks
  BotCheck.pendingChecks[targetPlayerGuid] = {
    inspectorGuid = playerGuid,
    answer = answer,
    events = {}
  }

  -- Schedule initial warning message
  BotCheck.sendWarningMessage(playerGuid, targetPlayerGuid, config.answerDuration / config.warningInterval)

  -- Update checked player storages
  targetPlayer:setStorageValue(config.storages.dailyCheckInspection, targetPlayer:getStorageValue(config.storages.dailyCheckInspection) + 1)
  targetPlayer:setStorageValue(config.storages.lastCheck, os.time() + config.checkDelay)

  -- Update storages of player who performs the check
  player:setStorageValue(config.storages.dailyCheckInvocation, player:getStorageValue(config.storages.dailyCheckInvocation) + 1)
end

BotCheck.sendWarningMessage = function(playerGuid, targetPlayerGuid, minutesLeft)
  local targetPlayer = Player(targetPlayerGuid)
  if not targetPlayer then return end

  if minutesLeft > 0 then
      local message = string.format(config.messages.onWarningMessage, BotCheck.formatTime(minutesLeft * 60))
      targetPlayer:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, message)

      -- Schedule next warning
      local nextWarningTime = config.warningInterval * 1000
      minutesLeft = minutesLeft - (config.warningInterval / 60)
      BotCheck.pendingChecks[targetPlayerGuid].events["warningEvent"] = addEvent(BotCheck.sendWarningMessage, nextWarningTime, playerGuid, targetPlayerGuid, minutesLeft)
  else
      targetPlayer:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, config.messages.onAnswerTimeOut)
      targetPlayer:setStorageValue(config.storages.failedCheckCount, targetPlayer:getStorageValue(config.storages.failedCheckCount) + 1)
      local failedChecks = targetPlayer:getStorageValue(config.storages.failedCheckCount)
      local maxFailedChecks = config.executePenaltyAfter

      if failedChecks == maxFailedChecks then
        targetPlayer:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, config.messages.onPenalty)

        BotCheck.stopEventsAndRemovePendingRecord(targetPlayerGuid)
        BotCheck.applyPenalty(targetPlayerGuid)

        local player = Player(playerGuid)
        if not player then return end
        local playerMessage = string.format(config.messages.onFailToProvideAnswer, targetPlayer:getName())
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, playerMessage)
      else
        local message = string.format(config.messages.onCheckCount, failedChecks, maxFailedChecks)
        targetPlayer:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, message)

        local player = Player(playerGuid)
        if not player then return end
        local playerMessage = string.format(config.messages.onFailToProvideAnswer, targetPlayer:getName())
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, playerMessage)

        BotCheck.stopEventsAndRemovePendingRecord(targetPlayerGuid)
      end
  end
end

BotCheck.stopEventsAndRemovePendingRecord = function(playerGuid)
  if BotCheck.pendingChecks[playerGuid] then
    for _, eventId in pairs(BotCheck.pendingChecks[playerGuid].events) do
      stopEvent(eventId)
    end
    BotCheck.pendingChecks[playerGuid] = nil
  end
end

BotCheck.applyPenalty = function(targetPlayerGuid)
  print("applying penalty to playerGuid: " .. targetPlayerGuid)
end

BotCheck.onCheckAnswer = function(targetPlayerGuid, playerAnswer)
  local targetPlayer = Player(targetPlayerGuid)
  if not targetPlayer then return end

  if not BotCheck.pendingChecks[targetPlayerGuid] then
    targetPlayer:sendCancelMessage(config.messages.onNotUndergoingCheck)
    return false
  else
    local data = BotCheck.pendingChecks[targetPlayerGuid]
    local expectedAnswer = data.answer
    local player = Player(data.inspectorGuid)

    if tostring(expectedAnswer):trim():lower() == tostring(playerAnswer):trim():lower() then
      targetPlayer:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, config.messages.onCorrectAnswer)
      if player then
        local message = string.format(config.messages.onSuccessToProvideAnswer, targetPlayer:getName())
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, message)
      end
      BotCheck.stopEventsAndRemovePendingRecord(targetPlayerGuid)
    else
      targetPlayer:setStorageValue(config.storages.failedCheckCount, targetPlayer:getStorageValue(config.storages.failedCheckCount) + 1)
      local failedChecks = targetPlayer:getStorageValue(config.storages.failedCheckCount)
      local maxFailedChecks = config.executePenaltyAfter

      if failedChecks == maxFailedChecks then
        targetPlayer:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, config.messages.onPenalty)
        BotCheck.applyPenalty(targetPlayerGuid)
      else
        targetPlayer:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, config.messages.onWrongAnswer)
        local message = string.format(config.messages.onCheckCount, failedChecks, maxFailedChecks)
        targetPlayer:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, message)
      end

      if player then
        local message = string.format(config.messages.onFailToProvideAnswer, targetPlayer:getName())
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, message)
      end

      BotCheck.stopEventsAndRemovePendingRecord(targetPlayerGuid)
    end

  end
end

local weirdBotCheck = TalkAction("!checkbot")
function weirdBotCheck.onSay(player, words, param, type)
  if not param or param == "" then
    player:sendCancelMessage(config.messages.onHelpCheckBot)
    return false
  end

  -- Check whether the player who invokes the talkaction has any invocations left
  local dailyCheckInvocations = player:getStorageValue(config.storages.dailyCheckInvocation)
  if dailyCheckInvocations >= config.allowedDailyCheckInvocations then
    player:sendCancelMessage(config.messages.onDailyLimitReached)
    return false
  end

  -- Check if the target player exists
  local targetPlayer = Player(param)
  if not targetPlayer then
    local message = string.format(config.messages.onPlayerNotFound, param)
    player:sendCancelMessage(message)
    return false
  end

  -- Check whether the player is checkable
  local isTargetPlayerCheckable = targetPlayer:getStorageValue(config.storages.isCheckable) == config.allowToPerfomCheckOnStorageValue
  if isTargetPlayerCheckable then
    local targetPlayerGuid = targetPlayer:getGuid()
    local playerGuid = player:getGuid()
    -- Check whether the player is within allowed range
    if targetPlayer:getPosition():getDistance(player:getPosition()) <= config.allowCheckFromDistance then
      local lastCheckTime = targetPlayer:getStorageValue(config.storages.lastCheck)
      -- Check whether the target player hasn't been check in the previous hour
      if lastCheckTime > os.time() then
        player:sendCancelMessage(config.messages.onPlayerRecentlyChecked)
        return false
      -- Check whether the player doesn't have a pending check
      elseif BotCheck.pendingChecks[targetPlayerGuid] then
        player:sendCancelMessage(config.messages.onPlayerPendingCheck)
        return false
      -- Check whether the player hasn't reached the limit of daily checks
      elseif targetPlayer:getStorageValue(config.storages.dailyCheckInspection) >= config.allowedDailyCheckInpections then
        player:sendCancelMessage(config.messages.onTooManyChecks)
        return false
      -- All conditions are satisfied, allow the player to perform a check on target player
      else
        BotCheck.perfomCheck(playerGuid, targetPlayerGuid)
      end
    -- Player is not within the allowed range
    else
      local message = string.format(config.messages.onPlayerTooFar, config.allowCheckFromDistance)
      player:sendCancelMessage(message)
      return false
    end
  else
    player:sendCancelMessage(config.messages.onPlayerNotCheckable)
    return false
  end

  return false
end
weirdBotCheck:separator(" ")
weirdBotCheck:register()

local talkAction = TalkAction("!noafk")
function talkAction.onSay(player, words, param, type)
  if not param or param == "" then
    player:sendCancelMessage(config.messages.onHelpNoAfk)
    return false
  end
  local playerGuid = player:getGuid()
  BotCheck.onCheckAnswer(playerGuid, param)
  return false
end
talkAction:separator(" ")
talkAction:register()

local globalEvent = GlobalEvent("BotCheckStartup")
function globalEvent.onStartup()
  local storagesToReset = {config.storages.dailyCheckInspection, config.storages.dailyCheckInvocation, config.storages.failedCheckCount}
  for _, storage in ipairs(storagesToReset) do
    local sql = "UPDATE player_storage SET `value` = 0 WHERE `key` = " .. storage
    db.query(sql)
  end
  return true
end
globalEvent:register()
 
Last edited:
It will save you a lot of time if you just pay 20.00 a month with chat gpt and code with it. Just saying.
Post automatically merged:




Here this is example Chat Gpt did for me I do not know if it works at all. As I am using my phone.

Lua:
local botCheck = TalkAction("!checkbot")

function botCheck.onSay(player, words, param)
    local target = Player(param)
    if not target then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "A player with this name is not online.")
        return false
    end

    if player:getStorageValue(XXXX) <= 0 then -- Replace XXXX with your storage key
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot use this command.")
        return false
    end

    if target:getPosition():getDistance(player:getPosition()) > 5 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are too far away from the player.")
        return false
    end

    local checkTime = player:getStorageValue(target:getGuid() + 10000)
    if os.time() - checkTime < 3600 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You can only check a player once every hour.")
        return false
    end

    local dailyChecks = player:getStorageValue(target:getGuid() + 20000)
    if dailyChecks >= 5 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You have reached your check limit for today.")
        return false
    end

    local questions = {
        { question = "What day is it today?", answer = "Monday" },
        { question = "What is 2+2?", answer = "4" }
    }

    local randomQuestion = math.random(#questions)
    player:setStorageValue(target:getGuid() + 30000, randomQuestion) -- storing question index
    player:setStorageValue(target:getGuid() + 10000, os.time()) -- update last check time
    player:setStorageValue(target:getGuid() + 20000, dailyChecks + 1) -- update daily check count
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Question: " .. questions[randomQuestion].question)

    addEvent(function()
        if player:getStorageValue(target:getGuid() + 30000) ~= 0 then
            player:setStorageValue(target:getGuid() + 30000, 0)
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "Time's up for the question!")
        end
    end, 300 * 1000) -- 5 minutes timer

    return true
end

botCheck:separator(" ")
botCheck:register()
Why to pay? I can do the same thing with free chstgpt
 
Back
Top