Killerbee_x. Posted July 6, 2011 Share Posted July 6, 2011 Hey guys, since a few weeks I'm trying to script with some help from scripters. I've tried to make a command which mutes a randomplayer for 1 minute. but it seems to fail. Maybe you guys can help me local randomPlayer = getRandomPlayer ( ) function mute(randomPlayer) outputChatBox(getPlayerName(randomPlayer).." is now muted", getRootElement(), 255, 0, 0, true) mutePlayer(randomPlayer) setTimer(60000,1, unmuterandomPlayer) end addCommandHandler("idiot", mute) Regards Killerbee_x. Link to comment
JR10 Posted July 6, 2011 Share Posted July 6, 2011 function mute(player) local randomPlayer = getRandomPlayer ( ) outputChatBox(getPlayerName(randomPlayer).." is now muted", getRootElement(), 255, 0, 0, true) mutePlayer(randomPlayer) setTimer(60000,1, unmuterandomPlayer) end addCommandHandler("idiot", mute) Link to comment
Deltanic Posted July 6, 2011 Share Posted July 6, 2011 Addition to JR10, which is actually the problem of all this: the setTimer syntax is incorrect. You used the function to call at the end, it has to be at the first argument. setTimer ( unmuterandomPlayer, 60000, 1, randomPlayer ) The last argument is needed to determine who was the random player. See the wiki for a full documentation about setTimer. Link to comment
JR10 Posted July 6, 2011 Share Posted July 6, 2011 Sorry, didn't notice that, but there is 2 problems like getting one random player on resource start, muting the player who typed the command. Link to comment
Deltanic Posted July 6, 2011 Share Posted July 6, 2011 repeat randomPlayer = getRandomPlayer ( ) until randomPlayer ~= player Where the 'player' variable is the player who entered the command. Link to comment
Killerbee_x. Posted July 6, 2011 Author Share Posted July 6, 2011 May I ask you guys, to make the complete function forme, because I'm a noob in scripting Link to comment
JR10 Posted July 6, 2011 Share Posted July 6, 2011 function mute(player) repeat randomPlayer = getRandomPlayer ( ) until randomPlayer ~= player outputChatBox(getPlayerName(randomPlayer).." is now muted", getRootElement(), 255, 0, 0, true) mutePlayer(randomPlayer) setTimer ( unmuterandomPlayer, 60000, 1, randomPlayer ) end addCommandHandler("idiot", mute) Link to comment
Deltanic Posted July 6, 2011 Share Posted July 6, 2011 If it won't work, post your unmuterandomPlayer function here as it might need to be modified now. Link to comment
Killerbee_x. Posted July 6, 2011 Author Share Posted July 6, 2011 ERROR: Infinite/too long execution (Die) ERROR: Aborting; infinite running script ps: dont look the resource name^^ Link to comment
Killerbee_x. Posted July 6, 2011 Author Share Posted July 6, 2011 If it won't work, post your unmuterandomPlayer function here as it might need to be modified now. I just sent you my whole script, I dont have more T__T Link to comment
Deltanic Posted July 6, 2011 Share Posted July 6, 2011 Oh lol, then you're trying to call an unexisting function Replace the setTimer line with this: setTimer ( unmutePlayer, 60000, 1, randomPlayer ) Link to comment
DakiLLa Posted July 6, 2011 Share Posted July 6, 2011 There is no such function 'mutePlayer'. Use setPlayerMuted instead. Next code should work (not tested though). By the way, make sure your resource has rights to mute players (it should be noted in ACL.xml). local timers = {} local muteDuration = 60 --seconds addCommandHandler( "idiot", function( player, cmd ) local rndPlayer = getRandomPlayer() --if random player is not muted if not timers[ rndPlayer ] then setPlayerMuted( rndPlayer, true ) timers[ rndPlayer ] = setTimer( setPlayerMuted, muteDuration*1000, 1, rndPlayer, false ) outputChatBox( getPlayerName( rndPlayer ).." is now muted", root, 255, 0, 0, true ) end end ) --if a player leaves the server and he has been muted, then remove the timer addEventHandler( "onPlayerQuit", root, function() if timers[ source ] then killTimer( timers[ source ] ) timers[ source ] = nil end end ) Link to comment
Killerbee_x. Posted July 6, 2011 Author Share Posted July 6, 2011 Haha, Ty it works. Also where do I have to put the message to the player when he gots unmuteD? Link to comment
DakiLLa Posted July 6, 2011 Share Posted July 6, 2011 Hmm, replace the 10th line: timers[ rndPlayer ] = setTimer( function( rplayer ) setPlayerMuted( rplayer, false ) outputChatBox( getPlayerName( rplayer ).." is now unmuted", root, 255, 255, 0, true ) end, muteDuration*1000, 1, rndPlayer ) 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