Jump to content

Local Chat MTASA


Recommended Posts

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

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
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 by Guest
Link to comment

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

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

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

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

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

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 by Guest
Link to comment

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

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

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