Jump to content

global chat


Wes

Recommended Posts

Hey! Can someone send me a download link to a global chat script?

I mean for example the player presses the B button, then what he wrote is going to be seen by everyone on the chat, like [GLOBAL] PlayerName: Message.

Thank you.

Link to comment

Im boring :S

Server:

function globalMessage(thePlayer, cmd, ...) 
    local message = table.concat ( { ... }, " " ) 
    local name = getPlayerName(thePlayer) 
    outputChatBox("#FF0000[GLOBAL]#00FF00"..name..": #FFFFFF"..message, getRootElement(), 255, 255, 255, true) 
    end 
addCommandHandler("global", globalMessage) 

Client:

bindKey("b", "down", "chatbox", "global") 

Link to comment
bindKey(source, "b", "down", "chatbox", "global") 

This is an example for server side.

Lol sorry. I didnt see that xD. Thanks for correcting me.

EDIT: so...

function globalMessage(thePlayer, cmd, ...) 
    local message = table.concat ( { ... }, " " ) 
    local name = getPlayerName(thePlayer) 
    outputChatBox("#FF0000[GLOBAL]#00FF00"..name..": #FFFFFF"..message, getRootElement(), 255, 255, 255, true) 
    end 
addCommandHandler("global", globalMessage) 
bindKey(getRootElement(), "b", "down", "chatbox", "global") 

Is it correctly?

Link to comment
bindKey(source, "b", "down", "chatbox", "global") 

This is an example for server side.

Lol sorry. I didnt see that xD. Thanks for correcting me.

EDIT: so...

function globalMessage(thePlayer, cmd, ...) 
    local message = table.concat ( { ... }, " " ) 
    local name = getPlayerName(thePlayer) 
    outputChatBox("#FF0000[GLOBAL]#00FF00"..name..": #FFFFFF"..message, getRootElement(), 255, 255, 255, true) 
    end 
addCommandHandler("global", globalMessage) 
bindKey(getRootElement(), "b", "down", "chatbox", "global") 

Is it correctly?

No that's wrong won't work -_-

Link to comment

Create a client side

Im boring :S

Server:

function globalMessage(thePlayer, cmd, ...) 
    local message = table.concat ( { ... }, " " ) 
    local name = getPlayerName(thePlayer) 
    outputChatBox("#FF0000[GLOBAL]#00FF00"..name..": #FFFFFF"..message, getRootElement(), 255, 255, 255, true) 
    end 
addCommandHandler("global", globalMessage) 

Client:

bindKey("b", "down", "chatbox", "global") 

Because I dont know how to do all in server side :S

Link to comment

Try this server side :

function globalMessage(thePlayer, cmd, ...) 
    local message = table.concat ( { ... }, " " ); 
    local name = getPlayerName(thePlayer); 
for _,v in ipairs(getElementsByType("player")) do 
    outputChatBox("#FF0000[GLOBAL]#00FF00"..name..": #FFFFFF"..message,v, 255, 255, 255, true) 
    end 
end 
addCommandHandler("global",  globalMessage); 
  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() 
  for index,player in pairs(getElementsByType("player")) do 
        bindKey(player,"b", "down", "chatbox", "global"); 
  end 
end 
) 
  
  
addEventHandler("onPlayerJoin", getRootElement(),  
function() 
  bindKey(source, "b", "down", "chatbox", "global"); 
end 
) 

:wink:

Link to comment

Thanks to me? :C

function globalMessage(thePlayer, cmd, ...) 
    local message = table.concat ( { ... }, " " ); 
    local name = getPlayerName(thePlayer); 
if message then 
for _,v in ipairs(getElementsByType("player")) do 
    outputChatBox("#FF0000[GLOBAL]#00FF00"..name..": #FFFFFF"..message,v, 255, 255, 255, true) 
    end 
end 
end 
addCommandHandler("global",  globalMessage); 
  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() 
  for index,player in pairs(getElementsByType("player")) do 
        bindKey(player,"b", "down", "chatbox", "global"); 
  end 
end 
) 
  
  
addEventHandler("onPlayerJoin", getRootElement(), 
function() 
  bindKey(source, "b", "down", "chatbox", "global"); 
end 
) 

Link to comment
How can I fix that the players cant send an empty message? So he presses a space and he can send that empty.
Thanks to me? :C
function globalMessage(thePlayer, cmd, ...) 
    local message = table.concat ( { ... }, " " ); 
    local name = getPlayerName(thePlayer); 
if message then 
for _,v in ipairs(getElementsByType("player")) do 
    outputChatBox("#FF0000[GLOBAL]#00FF00"..name..": #FFFFFF"..message,v, 255, 255, 255, true) 
    end 
end 
end 
addCommandHandler("global",  globalMessage); 
  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() 
  for index,player in pairs(getElementsByType("player")) do 
        bindKey(player,"b", "down", "chatbox", "global"); 
  end 
end 
) 
  
  
addEventHandler("onPlayerJoin", getRootElement(), 
function() 
  bindKey(source, "b", "down", "chatbox", "global"); 
end 
) 

I really don't think this will do it ..

Link to comment
How can I fix that the players cant send an empty message? So he presses a space and he can send that empty.
Thanks to me? :C
function globalMessage(thePlayer, cmd, ...) 
    local message = table.concat ( { ... }, " " ); 
    local name = getPlayerName(thePlayer); 
if message then 
for _,v in ipairs(getElementsByType("player")) do 
    outputChatBox("#FF0000[GLOBAL]#00FF00"..name..": #FFFFFF"..message,v, 255, 255, 255, true) 
    end 
end 
end 
addCommandHandler("global",  globalMessage); 
  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() 
  for index,player in pairs(getElementsByType("player")) do 
        bindKey(player,"b", "down", "chatbox", "global"); 
  end 
end 
) 
  
  
addEventHandler("onPlayerJoin", getRootElement(), 
function() 
  bindKey(source, "b", "down", "chatbox", "global"); 
end 
) 

I really don't think this will do it ..

¬¬ I did the introduction.

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