FlyingSpoon Posted May 14, 2017 Share Posted May 14, 2017 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
GTX Posted May 14, 2017 Share Posted May 14, 2017 (edited) https://wiki.multitheftauto.com/wiki/CallRemote There's an example (Example #2). Edited May 14, 2017 by GTX Link to comment
FlyingSpoon Posted May 14, 2017 Author Share Posted May 14, 2017 -- 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
GTX Posted May 15, 2017 Share Posted May 15, 2017 You can bind it like so: bindKey("G", "down", "chatbox", "Global") addCommandHandler("Global", function() -- stuff end ) Link to comment
FlyingSpoon Posted May 15, 2017 Author Share Posted May 15, 2017 (edited) 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 May 15, 2017 by raysmta Link to comment
Anubhav Posted May 16, 2017 Share Posted May 16, 2017 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
FlyingSpoon Posted May 16, 2017 Author Share Posted May 16, 2017 (edited) 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 May 16, 2017 by raysmta Link to comment
Dealman Posted May 19, 2017 Share Posted May 19, 2017 The 404 means the host was not found - make sure you've filled the necessary arguments properly. Did you export the function? If no, you may have to do that. On my phone atm so can't really review the code Link to comment
FlyingSpoon Posted May 20, 2017 Author Share Posted May 20, 2017 My servers are all on the same machine, and the exports are in both servers too. Link to comment
koragg Posted May 20, 2017 Share Posted May 20, 2017 You can take a look at how it's done here: https://github.com/JarnoVgr/Mr.Green-MTA-Resources/tree/master/resources/[web]/interchat Link to comment
Anubhav Posted May 20, 2017 Share Posted May 20, 2017 The IP/Port is wrong. You might wanna change it to localhost, as you told it is on the same machine. Link to comment
FlyingSpoon Posted May 21, 2017 Author Share Posted May 21, 2017 I tried localhost too. Link to comment
GTX Posted May 21, 2017 Share Posted May 21, 2017 You must use HTTP port (so according to default MTA configuration, it's 22005. Use the one that you put in mtaserver.conf under httpport attribute) 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