Jump to content

Chatting on multiple servers


Recommended Posts

Hey, I saw this in a few servers, they've made a script so that, for example if they have 2 servers, players can talk to eachother from the 2 servers. Like -

e.g. -

[DM]: Player1: Hey!

And the player on the other server -

[SH]: Player2: Hey!

----

I've seen it in a few servers? How can I do this?

Link to comment
-- Remote function set with callRemote 'functionName' argument
-- Called from/on remote servers
function outputChatBoxRemote ( playerName, message, type, serverport )
    outputChatBox ( "From " .. playerName .. " on " .. serverport .. ": " .. message )
    return "hello sailor"
end

-- Callback set with callRemote 'callbackFunction' argument
-- Called on the local server when callRemote has completed successfully or with errors
function finishedCallback( responseData, errno )
    responseData = tostring(responseData)
    if responseData == "ERROR" then
        outputDebugString( "callRemote: ERROR #" .. errno )
    elseif responseData ~= "hello sailor" then
        outputDebugString( "callRemote: Unexpected reply: " .. responseData  )
    else
        -- callRemote completed successfully
    end
end

function playerChat ( message, type )
    callRemote ( "play.mtabeta.com:33004", getResourceName(getThisResource()), "outputChatBoxRemote", finishedCallback, getPlayerName(source), message, type, getServerPort() )
    callRemote ( "play.mtabeta.com:33005", getResourceName(getThisResource()), "outputChatBoxRemote", finishedCallback, getPlayerName(source), message, type, getServerPort() )
    callRemote ( "play.mtabeta.com:33006", getResourceName(getThisResource()), "outputChatBoxRemote", finishedCallback, getPlayerName(source), message, type, getServerPort() )
end
addEventHandler ( "onPlayerChat", getRootElement(), playerChat )

Okay I get that all, how would I make it so for example, if I have a seperate chat binded on say for example "G". How would I use that chat? Instead of the default chat.

Link to comment
function globalMessage(thePlayer, cmd, ...)
    local message = table.concat ( { ... }, " " )
    local name = getPlayerName(thePlayer)
    outputChatBox("#B24D4D[Global]#FFFFFF "..name..": #ffffff"..message, players, 255, 255, 255, true)
end
addCommandHandler("global", globalMessage)

function outputChatBoxRemote ( playerName, message, type, serverport )
    outputChatBox ( "From " .. playerName .. " on " .. serverport .. ": " .. message )
    outputDebugString ( "From " .. playerName .. " on " .. serverport .. ": " .. message )
    return "hello sailor"
end

function finishedCallback( responseData, errno )
    responseData = tostring(responseData)
    if responseData == "ERROR" then
        outputDebugString( "callRemote: ERROR #" .. errno )
    elseif responseData ~= "hello sailor" then
        outputDebugString( "callRemote: Unexpected reply: " .. responseData  )
    else
    end
end

function playerChat ( message, type )
    callRemote ( "46.4.173.215:22004", getResourceName(getThisResource()), "outputChatBoxRemote", finishedCallback, getPlayerName(source), message, type, getServerPort() )
    callRemote ( "46.4.173.215:22005", getResourceName(getThisResource()), "outputChatBoxRemote", finishedCallback, getPlayerName(source), message, type, getServerPort() )
end
addEventHandler ( "onPlayerChat", getRootElement(), playerChat )

 

[15:34:56] WARNING: chat/server.lua:25: Bad argument @ 'callRemote' [Expected st
ring at argument 4, got function]
[15:35:02] WARNING: chat/server.lua:26: Bad argument @ 'callRemote' [Expected st
ring at argument 4, got function]

Also how would I only set it so the global chat only appears?
 

Edited by raysmta
Link to comment
function globalMessage(thePlayer, cmd, ...)
    local message = table.concat ( { ... }, " " )
    local name = getPlayerName(thePlayer)
    outputChatBox("#B24D4D[Global]#FFFFFF "..name..": #ffffff"..message, players, 255, 255, 255, true)
end
addCommandHandler("global", globalMessage)

function outputChatBoxRemote ( playerName, message, type, serverport )
    outputChatBox ( "From " .. playerName .. " on " .. serverport .. ": " .. message )
    outputDebugString ( "From " .. playerName .. " on " .. serverport .. ": " .. message )
    return "hello sailor"
end

function finishedCallback( responseData, errno )
    responseData = tostring(responseData)
    if responseData == "ERROR" then
        outputDebugString( "callRemote: ERROR #" .. errno )
    elseif responseData ~= "hello sailor" then
        outputDebugString( "callRemote: Unexpected reply: " .. responseData  )
    else
    end
end

function playerChat ( message, type )
    callRemote ( "46.4.173.215:22004", getResourceName(getThisResource()), "outputChatBoxRemote", "46.4.173.215:22004", finishedCallback, getPlayerName(source), message, type, getServerPort() )
    callRemote ( "46.4.173.215:22005", getResourceName(getThisResource()), "outputChatBoxRemote","46.4.173.215:22005", finishedCallback, getPlayerName(source), message, type, getServerPort() )
end
addEventHandler ( "onPlayerChat", getRootElement(), playerChat )

And 

Link to comment
function globalMessage(thePlayer, cmd, ...)
    local message = table.concat ( { ... }, " " )
    local name = getPlayerName(thePlayer)
    outputChatBox("#B24D4D[Global]#FFFFFF "..name..": #ffffff"..message, players, 255, 255, 255, true)
end
addCommandHandler("global", globalMessage)

function outputChatBoxRemote ( playerName, message, type, serverport )
    outputChatBox ( "From " .. playerName .. " on " .. serverport .. ": " .. message )
    outputDebugString ( "From " .. playerName .. " on " .. serverport .. ": " .. message )
    return "hello sailor"
end

function finishedCallback( responseData, errno )
    responseData = tostring(responseData)
    if responseData == "ERROR" then
        outputDebugString( "callRemote: ERROR #" .. errno )
    elseif responseData ~= "hello sailor" then
        outputDebugString( "callRemote: Unexpected reply: " .. responseData  )
    else
    end
end

function playerChat ( message, type )
    callRemote ( "46.4.173.215:22004", getResourceName(getThisResource()), "outputChatBoxRemote", "46.4.173.215:22004", finishedCallback, getPlayerName(source), message, type, getServerPort() )
    callRemote ( "46.4.173.215:22005", getResourceName(getThisResource()), "outputChatBoxRemote","46.4.173.215:22005", finishedCallback, getPlayerName(source), message, type, getServerPort() )
end
addEventHandler ( "onPlayerChat", getRootElement(), playerChat )
callRemote: ERROR #404

----------

Also I added this into both ACL's of the servers -

 

    <group name="OutRPCGroup">
       <acl name="OutRPC" />
       <object name="resource.chat" />
    </group>
    <acl name="OutRPC">
      <right name="function.callRemote" access="true" />
    </acl>
    
	<group name="InRPCGroup">
    <acl name="InRPC" />
      <object name="user.http_guest" />
    </group>
    <acl name="InRPC">
      <right name="resource.chat.http" access="true" />
	</acl>

"chat" being the name of the resource.

Edited by raysmta
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...