-.Paradox.- Posted February 20, 2014 Share Posted February 20, 2014 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 Link to comment
Moderators Citizen Posted February 20, 2014 Moderators Share Posted February 20, 2014 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 Link to comment
-.Paradox.- Posted February 20, 2014 Author Share Posted February 20, 2014 Yeah thanks Shall i use addCommandHandler? Link to comment
Castillo Posted February 20, 2014 Share Posted February 20, 2014 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 ) Link to comment
Moderators Citizen Posted February 21, 2014 Moderators Share Posted February 21, 2014 Yeah thanksShall 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) Link to comment
-.Paradox.- Posted February 21, 2014 Author Share Posted February 21, 2014 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. Link to comment
Saml1er Posted February 21, 2014 Share Posted February 21, 2014 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 Link to comment
-.Paradox.- Posted February 21, 2014 Author Share Posted February 21, 2014 Not working, when i do /task 1 nikolai nothing happens Link to comment
Wei Posted February 21, 2014 Share Posted February 21, 2014 Not working, when i do /task 1 nikolai nothing happens Have you set the duration did you do like /task 1 15 Link to comment
-.Paradox.- Posted February 21, 2014 Author Share Posted February 21, 2014 Yes and all of them are not working Link to comment
iPrestege Posted February 21, 2014 Share Posted February 21, 2014 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 Link to comment
-.Paradox.- Posted February 22, 2014 Author Share Posted February 22, 2014 Not working, i can't get any errors in debug or output Link to comment
Moderators Citizen Posted February 22, 2014 Moderators Share Posted February 22, 2014 I did a mistake that Solidsnake fixed but no one saw that (even me till now ) 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) Link to comment
-.Paradox.- Posted February 22, 2014 Author Share Posted February 22, 2014 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 Link to comment
Wei Posted February 22, 2014 Share Posted February 22, 2014 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 Link to comment
Moderators Citizen Posted February 22, 2014 Moderators Share Posted February 22, 2014 Now working, but when i do /task 1 Nikolai 15 it says wrong task idi 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) Link to comment
-.Paradox.- Posted February 23, 2014 Author Share Posted February 23, 2014 Thanks a lot it's working, one more thing, when player reconnect he is not muted anymore. Link to comment
Moderators Citizen Posted February 23, 2014 Moderators Share Posted February 23, 2014 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. Link to comment
-.Paradox.- Posted February 23, 2014 Author Share Posted February 23, 2014 I fixed it myself, thanks dude a lot Link to comment
Moderators Citizen Posted February 24, 2014 Moderators Share Posted February 24, 2014 You'r welcome Link to comment
-.Paradox.- Posted March 23, 2014 Author Share Posted March 23, 2014 Excuse me, i want to save it into players serials, so when the player reconnect he will be muted, any ideas? I will send you my code in pm Link to comment
WhoAmI Posted March 23, 2014 Share Posted March 23, 2014 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. Link to comment
-.Paradox.- Posted March 23, 2014 Author Share Posted March 23, 2014 I have no knowledge on MySql and SQlite Link to comment
WhoAmI Posted March 23, 2014 Share Posted March 23, 2014 In this forum there are few tutorials about usage. Link to comment
-.Paradox.- Posted March 23, 2014 Author Share Posted March 23, 2014 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 )]] Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now