FlyingSpoon Posted June 20, 2016 Share Posted June 20, 2016 function checkDimension() if ( getElementDimension ( source ) == 0 ) then setElementData(source, "Arena") end end addEventHandler("onResourceStart", root, checkDimension) addEventHandler("onPlayerJoin", root, checkDimension) function arenaChat(m) outputChatBox("(Local) "..getPlayerName(source)..": #ffffff"..m, getElementByID(getElementData(source, "Arena")), 255, 255, 255, true) outputServerLog("CHAT: "..getPlayerName(source)..": "..m," ") end addEventHandler( "onPlayerChat", root, arenaChat ) SERVER SIDED Bad argument @'getElementByID' [Expected string at argument 1, got boolean] Bad argument @'outputChatBox' [Expected element at argument 2, got boolean] Link to comment
FlyingSpoon Posted June 20, 2016 Author Share Posted June 20, 2016 Ok I tweaked my code a little, still I got an error - function onJoin() if source then setElementData(source, "Local", source) outputChatBox("True", root) else outputChatBox("False", root) end end addEventHandler("onResourceStart", root, onJoin) addCommandHandler("test", onJoin) local function playerChat(message, messageType, player) if messageType == 0 then cancelEvent() outputChatBox("(Local)".. getPlayerName(source)..": #ffffff", getElementByID(getElementData(source, "Local")), 255, 255, 255) outputServerLog("CHAT: "..getPlayerName(source)..": "..message)- end end addEventHandler("onPlayerChat", root, playerChat) Link to comment
FlyingSpoon Posted June 20, 2016 Author Share Posted June 20, 2016 Basically what I want to do is, I want to set that the main chat is only for a certain number of players, so if players in the lobby they can only see the chat, as I am making a global chat and seperating it from this. Link to comment
Bean666 Posted June 20, 2016 Share Posted June 20, 2016 (edited) setElementData(source, "Local", source) setElementData(source, "Arena") should be setElementData(source, "Local", true) setElementData(source, "Arena", true) but i think this won't work because you are not defining source into player, make sure to define source to player first. and why not use local data = getElementData(player, "Local") if data == true then try this it works ingame making show Local, no errors i got. ( im not sure if this is what you;re looking for ) function playerChat(message, messageType, player) if messageType == 0 then cancelEvent() for i,player in ipairs(getElementsByType("player")) do local data = getElementData(player, "Local") if data == true then outputChatBox("(Local)"..getPlayerName(player)..": #ffffff", player, 255, 255, 255) outputServerLog("CHAT: "..getPlayerName(player)..": "..message) end end end end addEventHandler("onPlayerChat", root, playerChat) instead of putting getElementID stuff. and don't use source atm in the function onPlayerChat because there is "player" in the parentheses. Edited June 20, 2016 by Guest Link to comment
Bean666 Posted June 20, 2016 Share Posted June 20, 2016 sorry for double post see up ^ i updated. if u want to test the element data's difference quickly use this by using /set function swag(player) local data = getElementData(player, "Local") if data == false then setElementData(player, "Local", true) outputChatBox("Element data set!") end if data == true then setElementData(player, "Local", false) outputChatBox("Element data false!") end end addCommandHandler("set", swag) here is the onJoin and checkDimension Fix: function onJoin() for i, player in ipairs(getElementsByType("player")) do local data = getElementData(player, "Local") if data == false then setElementData(player, "Local", true) outputChatBox("True") end if data == true then setElementData(player, "Local", false) outputChatBox("False") end end end addEventHandler("onResourceStart", root, onJoin) function checkDimension() for i,player in ipairs(getElementsByType("player")) do if ( getElementDimension ( player ) == 0 ) then setElementData(player, "Arena", true) outputChatBox("arena set") end end end addEventHandler("onResourceStart", root, checkDimension) addEventHandler("onPlayerJoin", root, checkDimension) Link to comment
FlyingSpoon Posted June 20, 2016 Author Share Posted June 20, 2016 Testing it now, will report back to you of the status. Link to comment
FlyingSpoon Posted June 20, 2016 Author Share Posted June 20, 2016 Thank you works great! Link to comment
FlyingSpoon Posted June 20, 2016 Author Share Posted June 20, 2016 One last thing, when I restart the resource once it says false, so it don't work then I restart it again it works, any ideas how to fix this? Link to comment
Bean666 Posted June 20, 2016 Share Posted June 20, 2016 here, it's because i thought you wanted to test the datas every resource start. it might have missing / more ends so if there is an eof problem u just fix it. function onJoin() for i, player in ipairs(getElementsByType("player")) do setElementData(player, "Local", true) outputChatBox("True") end end addEventHandler("onResourceStart", root, onJoin) Link to comment
FlyingSpoon Posted June 20, 2016 Author Share Posted June 20, 2016 function checkDimension() for i,player in ipairs(getElementsByType("player")) do if ( getElementDimension ( source ) == 0 ) then setElementData(player, "Arena", true) outputDebugString("[CHAT-SYSTEM] Settings for local chat have been updated for "..getPlayerCount().." players.") else setElementData(player, "Arena", false) end end end addEventHandler("onResourceStart", root, checkDimension) addEventHandler("onPlayerJoin", root, checkDimension) function playerChat(message, messageType, player) if messageType == 0 then cancelEvent() for i,player in ipairs(getElementsByType("player")) do local data = getElementData(player, "Arena") if data == true then outputChatBox("#FF6E6E(Local) #ffffff"..getPlayerName(player)..": #FF6E6E"..message, getElementByID(getElementData(source, "Arena")), 255, 255, 255, true) outputServerLog("LOCAL: "..getPlayerName(player)..": "..message) end end end end addEventHandler("onPlayerChat", root, playerChat) Will this only work for people in that dimension? Link to comment
FlyingSpoon Posted June 20, 2016 Author Share Posted June 20, 2016 I want to get the people who are only set to that element data to see the outputted text, no one else Link to comment
Bean666 Posted June 20, 2016 Share Posted June 20, 2016 getElementByID(getElementData(source, "Arena")) remove that and change to player i think it will already work because you're already doing a check who has the data by using if data == true i already tested this ingame with a player before and it seems working. players will not see the outputchatbox if they dont have the data to true, that's why data == true. and why are u using getElementByID it makes no sense. Link to comment
FlyingSpoon Posted June 20, 2016 Author Share Posted June 20, 2016 function checkDimension() for i,player in ipairs(getElementsByType("player")) do if ( getElementDimension ( player ) == 0 ) then setElementData(player, "Arena", true) elseif ( getElementDimension ( player ) == 1 ) then setElementData(player, "Arena2", true) end end end setTimer( checkDimension, 2000, 0) function playerChat(message, messageType, player) if messageType == 0 then cancelEvent() for i,player in ipairs(getElementsByType("player")) do local data = getElementData(player, "Arena") local data2 = getElementData(player, "Arena2") if data == true then outputChatBox("#FF6E6E(Local) #ffffff"..getPlayerName(source)..": #FF6E6E"..message, player, 255, 255, 255, true) outputServerLog("LOCAL: "..getPlayerName(source)..": "..message) elseif data2 == true and data == true then setElementData(player, "Arena", false) outputChatBox("#FF6E6E(Local) #ffffff"..getPlayerName(source)..": #FF6E6E"..message, player, 255, 255, 255, true) outputServerLog("LOCAL: "..getPlayerName(source)..": "..message) end end end end addEventHandler("onPlayerChat", root, playerChat) I want to make the chat only visible to certain dimensions, I tried something but it dont work. Link to comment
Bean666 Posted June 20, 2016 Share Posted June 20, 2016 try . EDIT: Tested and works ig. try it. : function checkDimension() for i,player in ipairs(getElementsByType("player")) do if ( getElementDimension ( player ) == 0 ) then setElementData(player, "Arena", true) end if ( getElementDimension ( player ) == 1 ) then setElementData(player, "Arena2", true) end end end setTimer( checkDimension, 2000, 0) Link to comment
FlyingSpoon Posted June 20, 2016 Author Share Posted June 20, 2016 It works, but it shows the chat for both arena's I just want it to show the chat for arena 1 in dimension 0 and show chat for players in arena 2 for dimension 1, I dont want players to be able to see chat in different dimensions Link to comment
Bean666 Posted June 20, 2016 Share Posted June 20, 2016 try not tested. function playerChat(message, messageType, player) if messageType == 0 then cancelEvent() for i,player in ipairs(getElementsByType("player")) do local data = getElementData(player, "Arena") local data2 = getElementData(player, "Arena2") if data == true then outputChatBox("#FF6E6E(Local) #ffffff"..getPlayerName(source)..": #FF6E6E"..message, player, 255, 255, 255, true) outputServerLog("LOCAL: "..getPlayerName(source)..": "..message) end if data2 == true then setElementData(player, "Arena", false) outputChatBox("#FF6E6E(Local) #ffffff"..getPlayerName(source)..": #FF6E6E"..message, player, 255, 255, 255, true) outputServerLog("LOCAL: "..getPlayerName(source)..": "..message) end end end end addEventHandler("onPlayerChat", root, playerChat) Link to comment
FlyingSpoon Posted June 20, 2016 Author Share Posted June 20, 2016 Still the other play can see chat from other dimension Link to comment
Bean666 Posted June 20, 2016 Share Posted June 20, 2016 (edited) any errors? try this: function playerChat(message, messageType, player) if messageType == 0 then cancelEvent() for i,player in ipairs(getElementsByType("player")) do local data = getElementData(player, "Arena") local data2 = getElementData(player, "Arena2") if data == true then setElementData(player, "Arena2", false) outputChatBox("#FF6E6E(Local) #ffffff"..getPlayerName(source)..": #FF6E6E"..message, player, 255, 255, 255, true) outputServerLog("LOCAL: "..getPlayerName(source)..": "..message) end if data2 == true then setElementData(player, "Arena", false) outputChatBox("#FF6E6E(Local) #ffffff"..getPlayerName(source)..": #FF6E6E"..message, player, 255, 255, 255, true) outputServerLog("LOCAL: "..getPlayerName(source)..": "..message) end end end end addEventHandler("onPlayerChat", root, playerChat) Edited June 20, 2016 by Guest Link to comment
FlyingSpoon Posted June 20, 2016 Author Share Posted June 20, 2016 No errors, just that both dimensions can see chat. Link to comment
FlyingSpoon Posted June 20, 2016 Author Share Posted June 20, 2016 I think somehow we have to use getElementsByID I saw it in Bonsai's Gamemode, but I don't know how he did it. Link to comment
FlyingSpoon Posted June 20, 2016 Author Share Posted June 20, 2016 This is Bonsai's look - function arenaChat(m, messageType) if messageType == 2 then return elseif messageType == 0 then cancelEvent() outputChatBox(getPlayerName(source)..": #ffffff"..m, getElementByID(getElementData(source, "Arena")), 255, 255, 255, true) outputServerLog("CHAT: "..getCleanPlayerName(source)..": "..m," ") end end addEventHandler( "onPlayerChat", root, arenaChat ) Link to comment
Bean666 Posted June 20, 2016 Share Posted June 20, 2016 try local data = getElementData(player, "Arena") outputChatBox(getPlayerName(player)..": #ffffff"..m, data, 255, 255, 255, true) Link to comment
FlyingSpoon Posted June 20, 2016 Author Share Posted June 20, 2016 m is the message, still same thing I think we have to do it getElementByID, but I don't know how to use it. Link to comment
Bean666 Posted June 20, 2016 Share Posted June 20, 2016 can u try this btw do u have a server to test on? function playerChat(message, messageType, player) if messageType == 0 then cancelEvent() for i,player in ipairs(getElementsByType("player")) do local data = getElementData(player, "Arena") local data2 = getElementData(player, "Arena2") if data == true then setElementData(player, "Arena2", false) outputChatBox("#FF6E6E(Local) #ffffff"..getPlayerName(player)..": #FF6E6E"..message, player, 255, 255, 255, true) outputServerLog("LOCAL: "..getPlayerName(player)..": "..message) end if data2 == true then setElementData(player, "Arena", false) outputChatBox("#FF6E6E(Local) #ffffff"..getPlayerName(player)..": #FF6E6E"..message, player, 255, 255, 255, true) outputServerLog("LOCAL: "..getPlayerName(player)..": "..message) end end end end addEventHandler("onPlayerChat", root, playerChat) 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