Jump to content

Problem with command and outputChatbox


Overkillz

Recommended Posts

Hi, I made a easy script with commands and outputchatbox but, I will like to block it if the player is muted, so If the player is muted, he cant use it.

What is wrong here ?

function hi (player) 
    outputChatBox("#FFFFFF<"..getPlayerName(player).."#ffffff>:Hey #00ffffGuys !",root,255,255,255,true) 
    if isPlayerMuted(source) then  
    cancelEvent() 
    outputChatBox("You are muted.",source, 255, 255, 0,true) 
    return 
end 
addCommandHandler ( "hi", hi ) 

Regards.

Link to comment

EDIT: ohh i should have noticed that

  
function hi (player) 
    if not isPlayerMuted(player) then 
    outputChatBox("#FFFFFF<"..getPlayerName(player).."#ffffff>:Hey #00ffffGuys !",root,255,255,255,true) 
    else 
    cancelEvent() 
    outputChatBox("You are muted.",player, 255, 255, 0,true) 
    end 
end 
addCommandHandler ( "hi", hi ) 
  

Edited by Guest
Link to comment
function hi (player) 
    if not isPlayerMuted(player) then 
        outputChatBox("#FFFFFF<"..getPlayerName(player).."#ffffff>:Hey #00ffffGuys !",root,255,255,255,true) 
    else 
        outputChatBox("You are muted.",player, 255, 255, 0,true) 
    end 
end 
addCommandHandler ( "hi", hi ) 

Link to comment

Make the check before you output the message. Also you should use player instead of source for the player source.

function exampleCommand_Handler(thePlayer, theCMD) 
    if(isPlayerMuted(thePlayer) ~= true) then 
        outputChatBox("<"..getPlayerName(thePlayer).."#FFFFFF>: #00FFFFHello World!", root, 255, 255, 255, true) 
    else 
        outputChatBox("You're muted and can not use this command.") 
        cancelEvent() 
    end 
end 
addCommandHandler("hi", exampleCommand_Handler, false) 
-- False tells the command handler that it is NOT case-sensitive. 

Edit:

DNL beat me to it :lol:

Link to comment

Thanks you guys, and with the PM System ?

function privateMessage(player, command, toplayername, ...) 
local words = { ... } 
local message = table.concat(words," ") 
    if toplayername then 
        if (findPlayerByName (toplayername)) then 
        toplayer = (findPlayerByName (toplayername)) 
            if not (toplayer == player) then 
                if message then 
                    outputChatBox("#FF0000[PM]#00aaff Message to #FFFFFF" .. getPlayerName(toplayer) .. "#FFFFFF: " .. message, player, 255, 255, 255, true) 
                    outputChatBox("#FF0000[PM]#00aaff Message from #FFFFFF" .. getPlayerName(player) .. "#FFFFFF: " .. message, toplayer, 255, 255, 255, true) 
                else 
                    outputChatBox("#FF0000[PM]#00aaff Invalid syntax! Usage:#FFFFFF /pm [partical player name] [message]", player, 255, 255, 255, true) 
                    return false 
                end 
            else 
                outputChatBox("#FF0000[PM]#00aaff You cannot PM yourself#FFFFFF!", player, 255, 255, 255, true) 
                return false 
            end 
        else 
            outputChatBox("#FF0000[PM]#00aaff Player not found! #FFFFFF("..toplayername..").", player, 255, 255, 255, true) 
            return false 
        end 
    else 
        outputChatBox("#FF0000[PM]#00aaff Invalid syntax! Usage:#FFFFFF /pm [partical player name] [message]", player, 255, 255, 255, true) 
        return false 
    end 
end 
addCommandHandler("pm", privateMessage) 

Link to comment

You can try this;

function privateMessage(player, command, toplayername, ...) 
local words = { ... } 
local message = table.concat(words," ") 
    if(isPlayerMuted(player) ~= true) then 
        if toplayername then 
            if (findPlayerByName (toplayername)) then 
            toplayer = (findPlayerByName (toplayername)) 
                if not (toplayer == player) then 
                    if message then 
                        outputChatBox("#FF0000[PM]#00aaff Message to #FFFFFF" .. getPlayerName(toplayer) .. "#FFFFFF: " .. message, player, 255, 255, 255, true) 
                        outputChatBox("#FF0000[PM]#00aaff Message from #FFFFFF" .. getPlayerName(player) .. "#FFFFFF: " .. message, toplayer, 255, 255, 255, true) 
                    else 
                        outputChatBox("#FF0000[PM]#00aaff Invalid syntax! Usage:#FFFFFF /pm [partical player name] [message]", player, 255, 255, 255, true) 
                        return false 
                    end 
                else 
                    outputChatBox("#FF0000[PM]#00aaff You cannot PM yourself#FFFFFF!", player, 255, 255, 255, true) 
                    return false 
                end 
            else 
                outputChatBox("#FF0000[PM]#00aaff Player not found! #FFFFFF("..toplayername..").", player, 255, 255, 255, true) 
                return false 
            end 
        else 
            outputChatBox("#FF0000[PM]#00aaff Invalid syntax! Usage:#FFFFFF /pm [partical player name] [message]", player, 255, 255, 255, true) 
            return false 
        end 
    else 
        outputChatBox("#FF0000[PM]:#00AAFF Failed to send PM - you're muted!", player, 255, 255, 255, true) 
    end 
end 
addCommandHandler("pm", privateMessage) 

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