Sign in to follow this  
slapz0r

Chat in memo

Recommended Posts

How to make a chat in memo?

--client
if ( source == Button[44] ) then
	local message = guiGetText(editAdmin)
	local name = getPlayerName(localPlayer) 
	local servertime = getRealTime ()
	local hours = (servertime.hour)
	local minutes = string.format("%02d", servertime.minute)
	local second = string.format("%02d", servertime.second)
	if message == "" then
	playSoundFrontEnd(2)
	return
	end
	guiSetText(memo_admin, guiGetText(memo_admin).."["..hours..":"..minutes..":"..second.."] "..getPlayerName ( localPlayer )..": "..message )
	guiSetText(editAdmin, "")
	end

I did something similar for just one player. How to make messages be added and visible to all users who enter the memo?

I understand that need to do something on the server side, but I don’t know how to fix it. Help

Share this post


Link to post

add \n to line 13

guiSetText(memo_admin, guiGetText(memo_admin).."["..hours..":"..minutes..":"..second.."] "..getPlayerName ( localPlayer )..": "..message.."\n" )
 

Share this post


Link to post
5 minutes ago, #x1AhMeD-09 said:

add \n to line 13

guiSetText(memo_admin, guiGetText(memo_admin).."["..hours..":"..minutes..":"..second.."] "..getPlayerName ( localPlayer )..": "..message.."\n" )
 

No, you did not understand. Everything is in order here, I just need another player to be able to see this text

Now it works only for the user who sends the message

Share this post


Link to post
1 hour ago, slapz0r said:

No, you did not understand. Everything is in order here, I just need another player to be able to see this text

Now it works only for the user who sends the message

send the message to server side by using triggerServerEvent

and then send it back to the client side

--client
    if ( source == Button[44] ) then
        local message = guiGetText ( editAdmin )
        if message == "" then
            playSoundFrontEnd(2)
            return
        end
        triggerServerEvent ( "SendMessage" , localPlayer , message )
    end
    
addEvent ( "ReciveMessage" , true )
addEventHandler ( "ReciveMessage" , root , function ( message )
        local name = getPlayerName ( localPlayer ) 
        local servertime = getRealTime ( )
        local hours , minutes , second = servertime.hour , string.format ( "%02d" , servertime.minute ) , string.format ( "%02d" , servertime.second )
        guiSetText ( memo_admin , guiGetText ( memo_admin ) .. "[" .. hours .. ":" .. minutes .. ":" .. second .. "] " .. getPlayerName ( localPlayer ) .. ": " .. message .. "\n" )
        guiSetText ( editAdmin , "" )
    end
end )
    
-- # Server side

addEvent ( "SendMessage" , true )
addEventHandler ( "SendMessage" , root , function ( Message )
    for _ , Player in pairs ( getElementsByType ( "player" ) ) do
        triggerClientEvent ( Player , "ReciveMessage" , Player , Message )
    end
end )

 

  • Like 1

Share this post


Link to post
2 hours ago, #x1AhMeD-09 said:

send the message to server side by using triggerServerEvent

and then send it back to the client side


--client
    if ( source == Button[44] ) then
        local message = guiGetText ( editAdmin )
        if message == "" then
            playSoundFrontEnd(2)
            return
        end
        triggerServerEvent ( "SendMessage" , localPlayer , message )
    end
    
addEvent ( "ReciveMessage" , true )
addEventHandler ( "ReciveMessage" , root , function ( message )
        local name = getPlayerName ( localPlayer ) 
        local servertime = getRealTime ( )
        local hours , minutes , second = servertime.hour , string.format ( "%02d" , servertime.minute ) , string.format ( "%02d" , servertime.second )
        guiSetText ( memo_admin , guiGetText ( memo_admin ) .. "[" .. hours .. ":" .. minutes .. ":" .. second .. "] " .. getPlayerName ( localPlayer ) .. ": " .. message .. "\n" )
        guiSetText ( editAdmin , "" )
    end
end )
    
-- # Server side

addEvent ( "SendMessage" , true )
addEventHandler ( "SendMessage" , root , function ( Message )
    for _ , Player in pairs ( getElementsByType ( "player" ) ) do
        triggerClientEvent ( Player , "ReciveMessage" , Player , Message )
    end
end )

 

@#x1AhMeD-09 dobxjRXMJOM.jpg

The first two lines are the local player, the one who wrote the message

Third line, this is another player wrote a message

and I see another player’s message like on the third line

How to fix it?

Share this post


Link to post
--client
    if ( source == Button[44] ) then
        local message = guiGetText ( editAdmin )
        if message == "" then
            playSoundFrontEnd(2)
            return
        end
        triggerServerEvent ( "SendMessage" , localPlayer , message )
    end
    
addEvent ( "ReciveMessage" , true )
addEventHandler ( "ReciveMessage" , root , function ( message , Name )
        local servertime = getRealTime ( )
        local hours , minutes , second = servertime.hour , string.format ( "%02d" , servertime.minute ) , string.format ( "%02d" , servertime.second )
        guiSetText ( memo_admin , guiGetText ( memo_admin ) .. "[" .. hours .. ":" .. minutes .. ":" .. second .. "] " .. Name .. ": " .. message .. "\n" )
        guiSetText ( editAdmin , "" )
    end
end )
    
-- # Server side

addEvent ( "SendMessage" , true )
addEventHandler ( "SendMessage" , root , function ( Message )
    for _ , Player in pairs ( getElementsByType ( "player" ) ) do
        triggerClientEvent ( Player , "ReciveMessage" , Player , Message , getPlayerName ( source ) )
    end
end )

 

  • Like 1

Share this post


Link to post
14 hours ago, #x1AhMeD-09 said:

--client
    if ( source == Button[44] ) then
        local message = guiGetText ( editAdmin )
        if message == "" then
            playSoundFrontEnd(2)
            return
        end
        triggerServerEvent ( "SendMessage" , localPlayer , message )
    end
    
addEvent ( "ReciveMessage" , true )
addEventHandler ( "ReciveMessage" , root , function ( message , Name )
        local servertime = getRealTime ( )
        local hours , minutes , second = servertime.hour , string.format ( "%02d" , servertime.minute ) , string.format ( "%02d" , servertime.second )
        guiSetText ( memo_admin , guiGetText ( memo_admin ) .. "[" .. hours .. ":" .. minutes .. ":" .. second .. "] " .. Name .. ": " .. message .. "\n" )
        guiSetText ( editAdmin , "" )
    end
end )
    
-- # Server side

addEvent ( "SendMessage" , true )
addEventHandler ( "SendMessage" , root , function ( Message )
    for _ , Player in pairs ( getElementsByType ( "player" ) ) do
        triggerClientEvent ( Player , "ReciveMessage" , Player , Message , getPlayerName ( source ) )
    end
end )

 

Everything works perfectly. thank

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.