Jump to content

Admin chat


Recommended Posts

Hai,

I'm trying to make a special command so that admins can speak to each other, without that chat being seen by normal players. Here's the code I've got. Help please and if you add more stuff to the code, please explain it, I'm new to lua scripting. Thanks!

function adminchat() 
  
    local account = getPlayerAccount ( thePlayer ) 
    if isObjectInACLGroup ( "user." .. getAccountName(string (account)), aclGetGroup ( "Admin" ) ) and type == 0 then    
    cancelEvent ( ) 
    local r, g, b = getPlayerNametagColor(source) 
    outputChatBox ( "#00FF00[Admin]-#ffffff" .. getPlayerName ( source ) .. ": " .. message, getRootElement(), r, g, b, true ) 
    else 
        outputChatBox("#C6FA78Fuck you.", getRootElement(), 255, 255, 255, true) 
    end 
end 
  
addCommandHandler("a", adminchat) 

Edited by Guest
Link to comment
function adminchat(p,_,...) 
    local message = table.concat({...}, " ") 
    local account = getPlayerAccount (p) 
    if isGuestAccount(account) then return end 
    if not isObjectInACLGroup ( "user." .. getAccountName(account), aclGetGroup("Admin") ) then return end 
  
    local r, g, b = getPlayerNametagColor(source) 
    outputChatBox ( "[Admin]"..getPlayerName ( source ) .. ":#ffffff " .. message, root, r, g, b, true ) 
end 
  
addEventHandler("onPlayerJoin", root, function() 
        bindKey(source, "u", "down", "chatbox", "a") 
    end 
) 
  
addCommandHandler("a", adminchat) 

Please learn from the code, because i spoon fed this.

Press U ingame to open the chat.

Link to comment

Qaisjp, it gave me this error, now and I replaced my code with yours. It gave me the same error, on my code, except it was for a different function.

[2011-10-12 10:00:37] WARNING: achat\achat.lua:21: Bad argument @ 'getPlayerNametagColor'

[2011-10-12 10:00:37] WARNING: achat\achat.lua:22: Bad argument @ 'getPlayerName' [Expected element at argument 1, got nil]

[2011-10-12 10:00:37] ERROR: achat\achat.lua:22: attempt to concatenate a boolean value

Link to comment

Aha yes, sorry. One minute.

edit:

function adminchat(_,...) 
    local p = source 
    local message = table.concat({...}, " ") 
    local account = getPlayerAccount (p) 
    if isGuestAccount(account) then return end 
    if not isObjectInACLGroup ( "user." .. getAccountName(account), aclGetGroup("Admin") ) then return end 
  
    local r, g, b = getPlayerNametagColor(source) 
    outputChatBox ( "[Admin]"..getPlayerName ( source ) .. ":#ffffff " .. message, root, r, g, b, true ) 
end 
  
addEventHandler("onPlayerJoin", root, function() 
        bindKey(source, "u", "down", "chatbox", "a") 
    end 
) 
  
addCommandHandler("a", adminchat) 

Link to comment

Yet, another error in the script:

[2011-10-12 17:27:48] LOGIN: (Admin, Everyone) Charlie successfully logged in as 'Charlie' (IP: 127.0.0.1 Serial: FA3C6E5FBF3B66FC15FCB1F2AAD204F4)

[2011-10-12 17:27:51] WARNING: achat\achat.lua:19: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got nil]

[2011-10-12 17:27:51] WARNING: achat\achat.lua:20: Bad argument @ 'isGuestAccount' [Expected account at argument 1, got boolean]

[2011-10-12 17:27:52] WARNING: achat\achat.lua:21: Bad argument @ 'getAccountName' [Expected account at argument 1, got boolean]

[2011-10-12 17:27:52] ERROR: achat\achat.lua:21: attempt to concatenate a boolean value

Link to comment

Hai, made some changes to my own script and now I get this error:

[2011-10-12 19:44:26] ERROR: achat\achat.lua:4: bad argument #1 to 'concat' (table expected, got string)

Script is here:

function adminchat(thePlayer, ...) 
  
    local word = ( ... ) 
    local message = table.concat(word, " ") 
     
    local account = getPlayerAccount ( thePlayer ) 
     
    if isObjectInACLGroup ( "user." .. account, aclGetGroup ( "Admin" ) )   then 
        outputChatBox ( "#C6FA78[Admin]" .. getPlayerName ( thePlayer ) .. ": " .. message, getRootElement(), 255, 255, 255, true ) 
    else 
        outputChatBox("#C6FA78No.", getRootElement(), 255, 255, 255, true) 
    end 
end 
  
addCommandHandler("a", adminchat) 

Link to comment
function adminchat(thePlayer, ...) 
  
    local word = {...} 
    local message = table.concat(word, " ") 
     
    local account = getPlayerAccount ( thePlayer ) 
     
    if isObjectInACLGroup ( "user." .. getAccountName(account), aclGetGroup ( "Admin" ) )   then 
        outputChatBox ( "#C6FA78[Admin]" .. getPlayerName ( thePlayer ) .. ": " .. message, getRootElement(), 255, 255, 255, true ) 
    else 
        outputChatBox("#C6FA78No.", getRootElement(), 255, 255, 255, true) 
    end 
end 
  
addCommandHandler("a", adminchat) 

Link to comment
function adminchat(thePlayer, ...) 
  
    local word = {...} 
    local message = table.concat(word, " ") 
     
    local account = getPlayerAccount ( thePlayer ) 
     
    if isObjectInACLGroup ( "user." .. getAccountName(account), aclGetGroup ( "Admin" ) )   then 
        outputChatBox ( "#C6FA78[Admin]" .. getPlayerName ( thePlayer ) .. ": " .. message, getRootElement(), 255, 255, 255, true ) 
    else 
        outputChatBox("#C6FA78No.", getRootElement(), 255, 255, 255, true) 
    end 
end 
  
addCommandHandler("a", adminchat) 

Worked, thanks! But it displays as: (color here)[Admin]Charlie: a test. And I didn't put that a there. Help!

Link to comment

Also another problem with another script.

function veh(thePlayer, modelid) 
  
    local X = 5 
    local Y = 0 
    local Z = 0 
     
    model = modelid 
    player = getPlayerName( thePlayer ) 
    if isObjectInACLGroup ("user." .. player, aclGetGroup("Admin") )    then 
        createVehicle (modelid, X, Y, Z) 
    elseif not isObjectInACLGroup ("user." .. player, getACLGroup("Admin") )    then 
        outputChatBox ( "Admin cmd only!" ) 
    end 
end 
  
addCommandHandler("veh", veh) 

It works, I get no error/debug error but the car doesn't spawn.

Link to comment
function veh(thePlayer, cmd, modelid) 
    local X = 5 
    local Y = 0 
    local Z = 0 
    local model = tonumber(modelid) 
  
    if isObjectInACLGroup ("user." .. getAccountName(getPlayerAccount(player)), aclGetGroup("Admin") )    then 
        createVehicle (model, X, Y, Z) 
    else 
        outputChatBox ( "Admin cmd only!" ) 
    end 
end  
addCommandHandler("veh", veh) 

Link to comment
function veh(thePlayer, cmd, modelid) 
    local x,y,z = getElementPosition(thePlayer) 
    local model = tonumber(modelid) 
  
    if isObjectInACLGroup ("user." .. getAccountName(getPlayerAccount(player)), aclGetGroup("Admin") )    then 
        createVehicle (model, x+5,y,z) 
    else 
        outputChatBox ( "Admin cmd only!" ) 
    end 
end  
addCommandHandler("veh", veh) 

i think that is waht u want

Link to comment
function adminchat(thePlayer, _,...) 
  
    local word = {...} 
    local message = table.concat(word, " ") 
     
    local account = getPlayerAccount ( thePlayer ) 
     
    if isObjectInACLGroup ( "user." .. getAccountName(account), aclGetGroup ( "Admin" ) )   then 
        outputChatBox ( "#C6FA78[Admin]" .. getPlayerName ( thePlayer ) .. ": " .. message, getRootElement(), 255, 255, 255, true ) 
    else 
        outputChatBox("#C6FA78No.", getRootElement(), 255, 255, 255, true) 
    end 
end 
  
addCommandHandler("a", adminchat) 

I am very nice, aren't I ;)

Link to comment
  
function outputForAdmins(player, msg) 
  for i,v in pairs(getElementsByType("player")) do 
     local account = getPlayerAccount ( v ) 
     
     if isObjectInACLGroup ( "user." .. getAccountName(account), aclGetGroup ( "Admin" ) )   then 
        outputChatBox ( "#C6FA78[Admin]" .. getPlayerName ( player ) .. ": " .. message, v, 255, 255, 255, true ) 
     end 
  end 
end 
function adminchat(thePlayer, _,...) 
  
    local word = {...} 
    local message = table.concat(word, " ") 
     
    local account = getPlayerAccount ( thePlayer ) 
     
    if isObjectInACLGroup ( "user." .. getAccountName(account), aclGetGroup ( "Admin" ) )   then 
        outputForAdmins(thePlayer, message) 
    else 
        outputChatBox("#C6FA78No.", thePlayer, 255, 255, 255, true) 
    end 
end 
  
addCommandHandler("a", adminchat) 

This one is only to show what you say for admins, above castillos post is announce

Link to comment
function adminchat(thePlayer, ...) 
  
    local word = {...} 
    local message = table.concat(word, " ") 
     
    local account = getPlayerAccount ( thePlayer ) 
     
    if isObjectInACLGroup ( "user." .. getAccountName(account), aclGetGroup ( "Admin" ) )   then 
        outputChatBox ( "#C6FA78[Admin]" .. getPlayerName ( thePlayer ) .. ": " .. message, getRootElement(), 255, 255, 255, true ) 
    else 
        outputChatBox("#C6FA78No.", getRootElement(), 255, 255, 255, true) 
    end 
end 
  
addCommandHandler("a", adminchat) 

Worked, thanks! But it displays as: (color here)[Admin]Charlie: a test. And I didn't put that a there. Help!

lol look at line 15 :P

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