Jump to content

Help


-.Paradox.-

Recommended Posts

Posted

Hello again, guys i need help to complete my task panel, i need some functions that i could use to make this:

when i type

/task 1 [playername] [duration] it suppose to mute the player

/task 2 [playername] [reason] to kick the player

/task 3 [playername] [reason] [duration] to ban the player

Thanks for help

  • Moderators
Posted

Something like this ?

function doTask(taskId, playername, arg3, arg4) 
    if taskId then 
        local player = getPlayerFromName(playername or "") 
        if player then 
            if taskId == 1 then 
                --mute using ar3 for duration 
            elseif taskId == 2 then 
                --kick using arg3 for reason 
            elseif taskId == 3 then 
                --ban using arg3 for reason and arg4 for duration 
            else 
                -- wrong taskId 
            end 
        else 
            --player not found 
        end 
    else 
        --no taskId given 
    end 
end 

Posted

If you want to use addCommandHandler, then you must put the arguments given by addCommandHandler.

function doTask ( thePlayer, _, taskId, playername, arg3, arg4) 
    if taskId then 
        local player = getPlayerFromName(playername or "") 
        if player then 
            if taskId == 1 then 
                --mute using ar3 for duration 
            elseif taskId == 2 then 
                --kick using arg3 for reason 
            elseif taskId == 3 then 
                --ban using arg3 for reason and arg4 for duration 
            else 
                -- wrong taskId 
            end 
        else 
            --player not found 
        end 
    else 
        --no taskId given 
    end 
end 
addCommandHandler ( "task", doTask ) 

  • Moderators
Posted
Yeah thanks

Shall i use addCommandHandler?

It's already done, now you have to use the right function to kick ban and mute.

Then ingame you will do /task 1 Nikolai96 5 to mute Nikolai96 for five minutes.

You will need:

setPlayerMuted --to mute or unmute the guy 
setTimer --to call setPlayerMuted to unmute the guy 
kickPlayer --to kick the guy 
banPlayer --to ban the guy 
--and a little of maths: 
myvar*60*1000 --minutes to milliseconds for the setTimer 
myvar*60 --minutes to seconds (for the ban function) 

Posted

Like this?

function doTask(theClient, taskId, playername) 
  if ( hasObjectPermissionTo ( theClient, "function.banPlayer" ) ) then 
    if taskId then 
        local player = getPlayerFromName(playername or "") 
        if player then 
            if taskId == 1 then 
                setPlayerMuted(player, true) 
                outputChatBox("You have been muted.",player) 
            elseif taskId == 2 then 
                kickPlayer ( player, theClient, "You are kicked because of cheating." ) 
            elseif taskId == 3 then 
                banPlayer ( player, theClient, serial, "You are banned because of hacking/abusing.", 3600 ) 
            else 
                outputChatBox("Wrong Task id.",player) 
            end 
        else 
            outputChatBox("Could not find the player.",player) 
        end 
    else 
        outputChatBox("SYNTAX: /task [id] [victim] ",player) 
    end 
  else 
  outputChatBox ( "TaskID: You don't have enough permissions", theClient ) 
end 
  

And please i don't know how to call timer to unmute the victim, can you show me how and thanks.

Posted
Like this?
function doTask(thePlayer, taskId, playername) 
  if ( hasObjectPermissionTo ( thePlayer, "function.banPlayer" ) ) then 
    if taskId then 
        local player = getPlayerFromName(playername or "") 
        if player then 
            if taskId == 1 then 
                setPlayerMuted(player, true) 
                outputChatBox("You have been muted.",player) 
            elseif taskId == 2 then 
                kickPlayer ( player, thePlayer, "You are kicked because of cheating." ) 
            elseif taskId == 3 then 
                banPlayer ( player, thePlayer, serial, "You are banned because of hacking/abusing.", 3600 ) 
            else 
                outputChatBox("Wrong Task id.",thePlayer) 
            end 
        else 
            outputChatBox("Could not find the player.",thePlayer) 
        end 
    else 
        outputChatBox("SYNTAX: /task [id] [victim] ",thePlayer) 
    end 
  else 
  outputChatBox ( "TaskID: You don't have enough permissions", thePlayer ) 
end 
  

And please i don't know how to call timer to unmute the victim, can you show me how and thanks.

function doTask(thePlayer, taskId, playername, due) 
  if ( hasObjectPermissionTo ( thePlayer, "function.banPlayer" ) ) then 
    if taskId then 
      local due = tonumber ( due ) 
        local player = getPlayerFromName(playername or "") 
        if player then 
            if taskId == 1 and due then 
            due = due * 1000 -- converting duration into seconds 
                setPlayerMuted(player, true) 
 setTimer ( setPlayerMuted, due, 1, player, false ) -- unmuting him after the time is over 
                outputChatBox("You have been muted for "..due.." seconds",player) 
            elseif taskId == 2 then 
                kickPlayer ( player, thePlayer, "You are kicked because of cheating." ) 
            elseif taskId == 3 then 
                banPlayer ( player, thePlayer, serial, "You are banned because of hacking/abusing.", 3600 ) 
            else 
                outputChatBox("Wrong Task id.",thePlayer) 
            end 
        else 
            outputChatBox("Could not find the player.",thePlayer) 
        end 
    else 
        outputChatBox("SYNTAX: /task [id] [victim] ",thePlayer) 
    end 
  else 
  outputChatBox ( "TaskID: You don't have enough permissions", thePlayer ) 
end 
  

Posted

Make sure that the resource is already added to the group admin or console which has the banPlayer function .. etc if not then add this object to the group :

resource.YourResourceName

  • Moderators
Posted

I did a mistake that Solidsnake fixed but no one saw that (even me till now :D)

replace:

function doTask(thePlayer, taskId, playername, arg3, arg4) 

by this:

function doTask(thePlayer, cmd, taskId, playername, arg3, arg4) 

Final code:

function doTask(thePlayer, cmd, taskId, playername, arg3, arg4) 
    if taskId then 
        local player = getPlayerFromName(playername or "") 
        if player then 
            if taskId == 1 then 
                local duration = (tonumber(arg3) or 0) * 60 * 1000 
                setPlayerMuted(player, true) 
                outputChatBox("You have been muted for "..tostring(arg3).." mins.", player) 
                setTimer(  
                    function() 
                        setPlayerMuted(player, true) 
                        outputChatBox("You have been unmuted.", player) 
                    end, 
                    duration, 1, player 
                ) 
            elseif taskId == 2 then 
                local reason = tostring(arg3) 
                kickPlayer(player, theClient, reason) 
            elseif taskId == 3 then 
                local duration = (tonumber(arg3) or 0) * 60 
                local reason = tostring(arg4) 
                banPlayer(player, true, true, true, thePlayer, reason, duration) 
            else 
                -- wrong taskId 
            end 
        else 
            --player not found 
        end 
    else 
        --no taskId given 
    end 
end 
addCommandHandler("task", doTask) 

Posted
function doTask(thePlayer, cmd, taskId, playername, arg3, arg4) 
taskId = tonumber(taskId) 
    if taskId then 
        local player = getPlayerFromName(playername or "") 
        if player then 
            if taskId == 1 then 
                local duration = (tonumber(arg3) or 0) * 60 * 1000 
                setPlayerMuted(player, true) 
                outputChatBox("You have been muted for "..tostring(arg3).." mins.", player) 
                setTimer( 
                    function() 
                        setPlayerMuted(player, true) 
                        outputChatBox("You have been unmuted.", player) 
                    end, 
                    duration, 1, player 
                ) 
            elseif taskId == 2 then 
                local reason = tostring(arg3) 
                kickPlayer(player, theClient, reason) 
            elseif taskId == 3 then 
                local duration = (tonumber(arg3) or 0) * 60 
                local reason = tostring(arg4) 
                banPlayer(player, true, true, true, thePlayer, reason, duration) 
            else 
                -- wrong taskId 
            end 
        else 
            --player not found 
        end 
    else 
        --no taskId given 
    end 
end 
addCommandHandler("task", doTask) 

Try this

  • Moderators
Posted
Now working, but when i do /task 1 Nikolai 15 it says wrong task id

i tried /task 2 and /task 3 too but i get same error

Oh yeah my bad, I forgot the 3rd line.

function doTask(thePlayer, cmd, taskId, playername, arg3, arg4) 
    if taskId then 
        local taskId = tonumber(taskId) --forgot this line 
        local player = getPlayerFromName(playername or "") 
        if player then 
            if taskId == 1 then 
                local duration = (tonumber(arg3) or 0) * 60 * 1000 
                setPlayerMuted(player, true) 
                outputChatBox("You have been muted for "..tostring(arg3).." mins.", player) 
                setTimer(  
                    function() 
                        setPlayerMuted(player, true) 
                        outputChatBox("You have been unmuted.", player) 
                    end, 
                    duration, 1, player 
                ) 
            elseif taskId == 2 then 
                local reason = tostring(arg3) 
                kickPlayer(player, theClient, reason) 
            elseif taskId == 3 then 
                local duration = (tonumber(arg3) or 0) * 60 
                local reason = tostring(arg4) 
                banPlayer(player, true, true, true, thePlayer, reason, duration) 
            else 
                -- wrong taskId 
            end 
        else 
            --player not found 
        end 
    else 
        --no taskId given 
    end 
end 
addCommandHandler("task", doTask) 

  • Moderators
Posted

You have to save somewhere (database for exemple) that the player X is muted untill Y (Y means a datetime, for example a timestamp).

When a player join/login again, you will check if the current datetime is older or not that the datetime you saved for that player. If it's older, just don't do anything (he is already unmuted) otherwise, mute him and call a timer that will unmute him in milliseconds.

  • 4 weeks later...
Posted

You have to use db function (dbQuery or executeSQLQuery) to do such a thing. Create table, where would be serial and mute duration and when player connects to the server, check if serial is in database if so - mute him.

Posted

I think i will use serials,

here is my code;

local serialMute = { } 
  
function doTask(thePlayer, cmd, taskId, playername, arg3, arg4) 
    if taskId then 
        local taskId = tonumber(taskId) --forgot this line 
        local player = getPlayerFromName(playername or "") 
        if player then 
            if taskId == 1 then 
                local duration = (tonumber(arg3) or 0) * 60 * 1000 
                setPlayerMuted(player, true) 
                outputChatBox("You have been muted for "..tostring(arg3).." mins.[Reason]: #1.Only English in Main Chat (mute)", player, 255, 0, 0) 
                setTimer( 
                    function() 
                        setPlayerMuted(player, true) 
                        outputChatBox("You have been unmuted.", player, 0, 255, 0) 
                    end, 
                    duration, 1, player 
                ) 
                serialMute [ getPlayerSerial ( player ) ] = { duration, timer } 
            end 
        end 
    end 
end 
addCommandHandler("task", doTask) 
  
function onJoin () 
    local serial = getPlayerSerial( source ) 
    local muted = serialMute [ serial ] 
    if ( type ( muted ) == "table" ) then 
        if ( muted [ 1 ] ) then 
            setPlayerMuted ( source, true ) 
            local timer = setTimer ( unMute, muted [ 1 ], 1, source ) 
            serialMute [ serial ] [ 2 ] = timer 
  
            return 
        end 
    end 
  
    setPlayerMuted ( source, false ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), onJoin ) 
  
addEventHandler ( "onPlayerQuit", root, 
    function ( ) 
        local serial = getPlayerSerial ( source ) 
        local muted = serialMute [ serial ] 
        if ( type ( muted ) == "table" ) then 
            if isTimer ( muted [ 2 ] ) then 
                local timeLeft = getTimerDetails ( muted [ 2 ] ) 
                killTimer ( muted [ 2 ] ) 
                serialMute [ serial ] [ 1 ] = timeLeft 
            end 
        end 
    end 
) 
  
function unmute ( thePlayer ) 
    if isElement ( thePlayer ) then 
        setPlayerMuted ( thePlayer, false ) 
        serialMute [ getPlayerSerial ( thePlayer ) ] = nil 
        outputChatBox ( "You have been unmuted.", thePlayer, 0, 255, 100 ) 
    end 
end 

Oh nvm i fixed it :)

I replaced from line 9 to 20 with this

                local duration = (tonumber(arg3) or 0) * 60 * 1000 
                setPlayerMuted(player, true) 
                outputChatBox("You have been muted for "..tostring(arg3).." mins.[Reason]: #1.Only English in Main Chat (mute)", player, 255, 0, 0) 
                local timer = setTimer ( unmute, duration, 1, player ) 
                serialMute [ getPlayerSerial ( player ) ] = { duration, timer } 
 --[[               setTimer( 
                    function() 
                        setPlayerMuted(player, true) 
                        outputChatBox("You have been unmuted.", player, 0, 255, 0) 
                    end, 
                    duration, 1, player 
                )]] 

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...