Jump to content

مساعدة


Recommended Posts

  • Scripting Moderators

وعليكم السلام
rulesTable
وين معرف؟
handlePunishment و وين يشتغل
لأن انت تاخذ منه القيمة

kickPlayer أيضًا لا تسمي وظائفك بنفس اسم وظائف موجودة بالفعل لأن راح يسبب لك مشاكل في إستعمالها مثل

Edited by xLive
  • Like 1
Link to comment
16 hours ago, xLive said:

وعليكم السلام
rulesTable
وين معرف؟
handlePunishment و وين يشتغل
لأن انت تاخذ منه القيمة

kickPlayer أيضًا لا تسمي وظائفك بنفس اسم وظائف موجودة بالفعل لأن راح يسبب لك مشاكل في إستعمالها مثل

rules table?معرف ال

local rulesTable = {
    ['8.6'] = 'hacking/ddosing',
    ['8.7'] = 'scamming',
    ['9.3'] = 'leeching from the server',
    ['9.4'] = 'advertising',
    ['9.7'] = 'harming the server',

}
    local ruleDescription = rulesTable[ruleNumber]









هذا الكود كامل 
 

executeSQLQuery("CREATE TABLE IF NOT EXISTS punishments (serial TEXT, punishername TEXT, reason TEXT, duration NUMERIC, timestamp NUMERIC, muted INTEGER)")

local rulesTable = {
    ['1.1'] = 'speaking non-english in global chat',
    ['2.1'] = 'annoying',
    ['3.1'] = 'offending',
    ['3.2'] = 'offending the server/staff',
	['4.1'] = 'many short messages',
	['4.2'] = 'crowding global chat with junk',
	['4.3'] = 'congregating the chatbox',
	['4.4'] = 'using console to spam commands',
	['4.5'] = 'using binds to spam commands',
	['5.1'] = 'disturbing no-dm players',
    ['5.2'] = 'disturbing other players while using nodm',
    ['5.3'] = 'disturbing busy staff',
    ['5.4'] = 'disturbing events',
	['6.1'] = 'wearing offensive tag',
	['6.2'] = 'wearing clan tag without permission',
	['6.3'] = 'wearing staff related tags',
	['6.4'] = 'impersonating',
	['6.5'] = 'impersonating server staff',
	['6.6'] = 'advertising via nick',
	['7.1'] = 'account sharing',
	['8.1'] = 'abusing IllusionRoam features',
	['8.2'] = 'abusing GTA/MTA/IllusionRoam bugs',
	['8.3'] = 'changing ip',
	['8.4'] = 'xp farming',
	['8.5'] = 'killing clanmates without tag',
	['8.6'] = 'hacking/ddosing',
	['8.7'] = 'scamming',
	['9.3'] = 'leeching from the server',
	['9.4'] = 'advertising',
	['9.5'] = 'canceling donations',
	['9.6'] = 'harming the server',
	['9.7'] = 'harming the server',

}
function loadMuteDataFromDB()
    local query = executeSQLQuery("SELECT * FROM punishments WHERE muted = 1")
    
    for _, row in ipairs(query) do
        local playerSerial = row.serial
        local timestamp = tonumber(row.timestamp)
        local ruleNumber = row.reason
        local ruleDescription = rulesTable[ruleNumber]

        local currentTime = getRealTime().timestamp
        local remainingDuration = row.duration - (currentTime - timestamp)

        if remainingDuration > 0 then
            local player = findPlayerBySerial(playerSerial)
            if player then
                setPlayerMuted(player, true)
                mutedPlayers[playerSerial] = { duration = remainingDuration, startTime = timestamp }

                mutedPlayers[playerSerial].unmuteTimer = setTimer(unmutePlayer, remainingDuration * 1000, 1, playerSerial, "Console", ruleNumber, ruleDescription)

                outputChatBox("#FFFFFF".. getPlayerName(player) .. " #006600has been muted by #FFFFFFConsole. #006600[#FFFFFFReason: RULE #" .. ruleNumber .. ": " .. ruleDescription .. ". Duration: " .. formatTime(remainingDuration), getRootElement(), 255, 255, 255, true)
            end
        else
            executeSQLQuery("UPDATE punishments SET muted = 0, timestamp = 0 WHERE serial = ? AND reason = ?", playerSerial, ruleNumber)
        end
    end
end

loadMuteDataFromDB()


loadMuteDataFromDB()
local mutedPlayers = {}


addEventHandler("onPlayerJoin", root, function()
    local player = source
    local playerName = getPlayerName(player)
    local playerSerial = getPlayerSerial(player)
    local query = executeSQLQuery("SELECT * FROM punishments WHERE serial = ? ORDER BY duration DESC LIMIT 1", playerSerial)

    if query and #query > 0 then
        local row = query[1]
        local totalDuration = tonumber(row.duration)
        local ruleNumber = row.reason
        local ruleDescription = rulesTable[ruleNumber]

        local currentTime = getRealTime().timestamp
        local timestamp = tonumber(row.timestamp)

        local remainingDuration = totalDuration - (currentTime - timestamp)

        if remainingDuration <= 0 then
            executeSQLQuery("DELETE FROM punishments WHERE serial = ? AND punishername = ? AND reason = ?", playerSerial, row.punishername, row.reason)
        else
		setElementData(player,"muted", true)
            setPlayerMuted(player, true)

            mutedPlayers[playerSerial] = { duration = remainingDuration, startTime = timestamp }

            mutedPlayers[playerSerial].unmuteTimer = setTimer(unmutePlayer, remainingDuration * 1000, 1, playerSerial, "Console", ruleNumber, ruleDescription)

        end
    end
end)

function findPlayerByPartialName(partialName)
    local matchedPlayer = nil
    for _, player in ipairs(getElementsByType("player")) do
        local playerName = getPlayerName(player)
        if string.find(playerName:lower(), partialName:lower()) then
            if matchedPlayer then
                return nil
            else
                matchedPlayer = player
            end
        end
    end
    return matchedPlayer
end
function handlePunishment(punisherName, partialName, ruleNumber)
    local targetPlayer = findPlayerByPartialName(partialName)

    if not isElement(targetPlayer) or getElementType(targetPlayer) ~= "player" then
        outputChatBox("• Player not found", source, 255, 0, 0, true)
        return
    end
    
    local ruleDescription = rulesTable[ruleNumber]

    if not ruleDescription then
        outputConsole("No description found for rule number: " .. ruleNumber)
        ruleDescription = "Unknown Rule"
    end

    local reputation = getElementData(targetPlayer, "Reputation") or 0

    outputConsole("Rule Number: " .. ruleNumber)
    outputConsole("Rule Description: " .. tostring(ruleDescription))

    if ruleNumber == '1.1' or ruleNumber == '2.1' or ruleNumber == '3.1' or ruleNumber == '3.2' then
        local duration = calculateMuteDuration(reputation, ruleNumber)
        mutePlayer(targetPlayer, punisherName, ruleNumber, ruleDescription, duration)
        setTimer(unmutePlayer, duration * 1000, 1, getPlayerSerial(targetPlayer), punisherName, ruleNumber, ruleDescription)
    elseif ruleNumber == '5.1' or ruleNumber == '5.2' or ruleNumber == '5.3' or ruleNumber == '5.4' or ruleNumber == '6.2' or ruleNumber == '6.4' or ruleNumber == '8.1' or ruleNumber == '8.2' then
        kickPlayer(targetPlayer, punisherName, ruleDescription)
        
        local playerName = getPlayerName(targetPlayer)
        if playerName then
            outputChatBox("#00FF00" .. playerName .. " has been kicked by #FFFFFF" .. punisherName .. " #006600[#FFFFFFReason: " .. ruleDescription .. "#006600]", getRootElement(), 255, 255, 255, true)
        else
            outputChatBox("• Failed to get player name for kick message.", source, 255, 0, 0, true)
        end
    else
        outputChatBox("• Invalid rule number", source, 255, 0, 0, true)
        return
    end
end

function kickPlayer(player, punisherName, ruleDescription)
    local playerName = getPlayerName(player)

    if not isElement(player) or getElementType(player) ~= "player" then
        outputConsole("Invalid player element in kickPlayer function.")
        return
    end

    outputChatBox("#00FF00" .. playerName .. " has been kicked by #FFFFFF" .. punisherName .. " #006600[#FFFFFFReason: " .. ruleDescription .. "#006600]", getRootElement(), 255, 255, 255, true)
    kickPlayer(player, "Kicked: " .. ruleDescription)  -- Kick the player with a reason
end
function calculateMuteDuration(reputation, ruleNumber)

if ruleNumber == '1.1' then
        if reputation <= -150.00 then  
            return 3600 -- 1 hour
        elseif reputation <= -100.00 then
            return 2400 -- 2 hours
        elseif reputation <= -50.00 then
            return 1200 -- 1 hour
        elseif reputation <= -15.00 then
            return 600 -- 10 minutes
        elseif reputation >= 75.00 then
            return 300 -- 5 minutes
        else
            return 300 -- 
        end

    elseif ruleNumber == '2.1' then
        if reputation <= -150.00 then -- 
            return 7200 -- 2 hours
        elseif reputation <= -100.00 then
            return 3600 -- 1 hour
        elseif reputation <= -50.00 then
            return 1800 -- 30 minutes
        elseif reputation <= -15.00 then
            return 600 -- 10 minutes
        elseif reputation >= 75.00 then
            return 300 -- 5 minutes
        else
            return 600 
        end

    elseif ruleNumber == '3.1' then
        if reputation <= -200.00 then
            return 14400 -- 2 hours
        elseif reputation <= -100.00 then
            return 7200 -- 1 hour
        elseif reputation <= -50.00 then
            return 3600 -- 30 minutes
        elseif reputation <= -15.00 then
            return 3600 -- 10 minutes
        elseif reputation >= 75.00 then
            return 1200 -- 5 minutes
        else
            return 600 
        end

    elseif ruleNumber == '3.2' then
        if reputation <= -150.00 then 
		
            return 28800 -- 2 hours
        elseif reputation <= -100.00 then
            return 14400 -- 1 hour
        elseif reputation <= -15.00 then
            return 7200 -- 30 minutes
		        elseif reputation >= 0.00 then
            return 1800 -- 5 minutes
        elseif reputation >= 75.00 then
            return 1800 -- 5 minutes
        else
            return 600  
        end

        else
         
		    return 300 
        end
	end
	
function mutePlayer(player, punisherName, ruleNumber, ruleDescription, duration)
    local playerSerial = getPlayerSerial(player)
    local playerName = getPlayerName(player)
    local timestamp = getRealTime().timestamp
       local reputation2 = getElementData(player, "Reputation") or 0

    if mutedPlayers[playerSerial] then
    outputChatBox("#ff0000• Player #ff0000is already muted. ", getRootElement(), 255, 255, 255, true)
        return

    end

    setPlayerMuted(player, true)
	setElementData(player, "muted", true)
    mutedPlayers[playerSerial] = { duration = duration, startTime = timestamp }

    outputChatBox("#006600• #FFFFFF".. playerName .. " #006600has been muted by #FFFFFF" .. punisherName .. " #006600[#FFFFFFReason: RULE #" .. ruleNumber .. ": " .. ruleDescription .. ". Duration: " .. formatTime(duration) .. " #006600]", getRootElement(), 255, 255, 255, true)

    executeSQLQuery("INSERT INTO punishments (serial, punishername, reason, duration, timestamp) VALUES (?, ?, ?, ?, ?)", playerSerial, punisherName, ruleNumber, duration, timestamp)
        			setElementData(player, "Reputation", reputation2 - 15.00)

    mutedPlayers[playerSerial].unmuteTimer = setTimer(function()
        unmutePlayer(playerSerial, punisherName, ruleNumber, ruleDescription, true)
    end, duration * 1000, 1)
end


function findPlayerBySerial(serial)
    for _, player in ipairs(getElementsByType("player")) do
        if getPlayerSerial(player) == serial then
            return player
        end
    end
    return nil
end
function unmutePlayer(serial, punisherName, ruleNumber, ruleDescription, isAutomatic)
    local player = findPlayerBySerial(serial)

    if player then
        local playerSerial = getPlayerSerial(player)

        if mutedPlayers[playerSerial] then
            if mutedPlayers[playerSerial].unmuteTimer then
                killTimer(mutedPlayers[playerSerial].unmuteTimer)
            end

            local playerName = getPlayerName(player)

            setPlayerMuted(player, false)
            mutedPlayers[playerSerial] = nil

            executeSQLQuery("DELETE FROM punishments WHERE serial = ? AND reason = ?", playerSerial, ruleNumber)

            if not isAutomatic then
                outputChatBox("#006600• #FFFFFF" .. playerName .. " #006600has been unmuted by #FFFFFFConsole", player, 255, 255, 255, true)
				setElementData(player,"muted", false)
            end

            if isElement(player) and getElementType(player) == "player" and isAutomatic then
                outputChatBox("#006600• #FFFFFF" .. playerName .. " #006600has been unmuted by #FFFFFFConsole.", player, 255, 255, 255, true)
								setElementData(player,"muted", false)

            end
        else
            local playerName = getPlayerName(player)
            if not isAutomatic then
                outputConsole(playerName .. " is not currently muted.")
            end
        end
    else
        outputConsole("Player not found.")
    end
end

function formatTime(duration)
    local hours = math.floor(duration / 3600)
    local minutes = math.floor((duration % 3600) / 60)
    local seconds = duration % 60

    local formattedTime = ""

    if hours > 0 then
        formattedTime = formattedTime .. hours .. " hour(s) "
    end

    if minutes > 0 then
        formattedTime = formattedTime .. minutes .. " minute(s) "
    end

    if seconds > 0 then
        formattedTime = formattedTime .. seconds .. " second(s)"
    end

    return formattedTime
end

function handleAUnmute(punisherName, playerName)
    local targetPlayer = findPlayerByPartialName(playerName)
    
    if not targetPlayer then
        outputChatBox("Player not found or multiple players match the partial name.")
        return
    end

    local playerNameTarget = getPlayerName(targetPlayer)
    local playerSerial = getPlayerSerial(targetPlayer)

    if mutedPlayers[playerSerial] then
        if mutedPlayers[playerSerial].unmuteTimer then
            killTimer(mutedPlayers[playerSerial].unmuteTimer)
        end

        setPlayerMuted(targetPlayer, false)
        
        mutedPlayers[playerSerial] = nil

        executeSQLQuery("DELETE FROM punishments WHERE serial = ?", playerSerial)
        
        outputChatBox("• #FFFFFF" .. playerNameTarget .. " #006600has been unmuted by #FFFFFF" .. punisherName .. "#006600", getRootElement(), 255, 255, 255, true)
		setElementData(targetPlayer, "muted", false)
    else
        outputChatBox(playerNameTarget .. " is not currently muted.", getRootElement(), 255, 255, 255, true)
    end
end

addCommandHandler("aunmute", function(player, _, playerName)
    local punisherName = getPlayerName(player)
    handleAUnmute(punisherName, playerName)
end)

addCommandHandler("action", function(player, _, playerName, ruleNumber)
    local punisherName = getPlayerName(player)
    handlePunishment(punisherName, playerName, ruleNumber)
end)

function checkRemainingMute(player, command, targetPlayerName)
    if not targetPlayerName then
        outputChatBox("Usage: /checkmute [playername]", player, 255, 255, 255, true)
        return
    end

    local targetPlayer = findPlayerByPartialName(targetPlayerName)

    if not targetPlayer then
        outputChatBox("Player not found or multiple players match the partial name.", player, 255, 255, 255, true)
        return
    end

    local playerSerial = getPlayerSerial(targetPlayer)

    if mutedPlayers[playerSerial] then
        local remainingDuration = mutedPlayers[playerSerial].duration - (getRealTime().timestamp - mutedPlayers[playerSerial].startTime)

        if remainingDuration <= 0 then
            outputChatBox(getPlayerName(targetPlayer) .. " is not currently muted.", player, 255, 255, 255, true)
        else
            outputChatBox(getPlayerName(targetPlayer) .. " is muted for another " .. formatTime(remainingDuration), player, 255, 255, 255, true)
        end
    else
        outputChatBox(getPlayerName(targetPlayer) .. " is not currently muted.", player, 255, 255, 255, true)
    end
end

addCommandHandler("checkmute", checkRemainingMute)
function checkExpiredMutes()
    local currentTime = getRealTime().timestamp

    for playerSerial, data in pairs(mutedPlayers) do
        local remainingDuration = data.duration - (currentTime - data.startTime)

        if remainingDuration <= 0 then
            unmutePlayer(playerSerial, "Console", "", "", true)
        end
    end
end

addEventHandler("onResourceStart", resourceRoot, checkExpiredMutes)

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...