Jump to content

PM again


Dice

Recommended Posts

function buildChatWnd () 
local row, col = guiGridListGetSelectedItem ( playerlist ) 
    if ( row and col and row ~= -1 and col ~= -1 ) then 
        local playerName = guiGridListGetItemText ( playerlist, row, 1 ) 
        local player = getPlayerFromName ( playerName ) 
        if ( player ) and ( player ~= getPlayerName ( getLocalPlayer() ) ) then --Check recheck 
            if not chats [ player ] then 
                chats [ player ] = { }   
                chats [ player ].window = guiCreateWindow(889, 491, 342, 298, getPlayerName ( localPlayer ), false) 
                guiWindowSetSizable(chats [ player ].window, false) 
                chats [ player ].memo = guiCreateMemo(14, 45, 312, 206, "", false, chats [ player ].window) 
                guiMemoSetReadOnly(chats [ player ].memo, true) 
                chats [ player ].edit = guiCreateEdit(14, 261, 227, 26, "", false, chats [ player ].window) 
                chats [ player ].send = guiCreateButton(248, 260, 78, 27, "Send", false, chats [ player ].window) 
                chats [ player ].close = guiCreateButton(314, 23, 18, 18, "X", false, chats [ player ].window) 
                addEventHandler ( "onClientGUIClick", chats [ player ].send, msgwino ) 
                addEventHandler ( "onClientGUIClick", chats [ player ].close, 
                        function ( ) 
                            _destroyElement ( chats [ player ].window ) 
                            chats [ player ] = nil 
                        end 
                            ,false 
                        ) 
            end 
        end  
    end  
end 
  
function msgwino () 
    if not chats [ player ] then 
        buildChatWnd ( player ) 
    end 
    newText = guiGetText( chats [ player ].edit ) 
    if newText and string.len(newText) > 0 then 
        local oldText = guiGetText(chats [ player ].memo) 
        if not oldText then oldText = "" end 
        oldText = oldText .. getPlayerName(localPlayer) .. ": " .. newText .. "\n" 
        guiSetText(chats [ player ].memo, oldText) 
        guiSetText(chats [ player ].edit, "") 
        guiMemoSetCaretIndex(chats [ player ].memo, string.len(oldText)) 
        triggerServerEvent("sMsg", localPlayer, player,newText)  
    end 
end 
  
function receivedMsg ( player, chat ) 
    if not chats [ player ] then 
        buildChatWnd ( player ) 
    end 
    local oldText = guiGetText(chats [ player ].memo) 
    if not oldText then oldText = "" end 
    oldText = oldText .. getPlayerName( player ) .. ": " .. chat .. "\n" 
    guiSetText(chats [ player ].memo, oldText) 
    guiMemoSetCaretIndex(chats [ player ].memo, string.len(oldText)) 
end 
addEvent ( "rMsg", true ) 
addEventHandler ( "rMsg", root, receivedMsg )  

Line 33 ^ keeps giving me that Attempt to Index Field a nil value -.- pls he;p

Link to comment

ok here is what I have so far, I fixed that issue only problem is the person receiving the message is not getting the GUI.. idk y, nothing happens.

---Client

function buildChatWnd () 
local row, col = guiGridListGetSelectedItem ( playerlist ) 
    if ( row and col and row ~= -1 and col ~= -1 ) then 
        playerName = guiGridListGetItemText ( playerlist, row, 1 ) 
        player = getPlayerFromName ( playerName ) 
        if ( player ) and ( player ~= getPlayerName ( getLocalPlayer() ) ) then --Check recheck 
            if not chats [ player ] then 
                chats [ player ] = { }   
                chats [ player ].window = guiCreateWindow(889, 491, 342, 298, getPlayerName ( player ), false) 
                guiWindowSetSizable(chats [ player ].window, false) 
                chats [ player ].memo = guiCreateMemo(14, 45, 312, 206, "", false, chats [ player ].window) 
                guiMemoSetReadOnly(chats [ player ].memo, true) 
                chats [ player ].edit = guiCreateEdit(14, 261, 227, 26, "", false, chats [ player ].window) 
                chats [ player ].send = guiCreateButton(248, 260, 78, 27, "Send", false, chats [ player ].window) 
                chats [ player ].close = guiCreateButton(314, 23, 18, 18, "X", false, chats [ player ].window) 
                addEventHandler( "onClientGUIAccepted", chats [ player ].edit, msgwino ) 
                addEventHandler ( "onClientGUIClick", chats [ player ].send, msgwino ) 
                addEventHandler ( "onClientGUIClick", chats [ player ].close, 
                        function ( ) 
                            _destroyElement ( chats [ player ].window ) 
                            chats [ player ] = nil 
                        end 
                            ,false 
                        ) 
            end 
        end  
    end  
end 
  
function msgwino () ---Send the message pls 
    if not chats [ player ] then 
        buildChatWnd ( player ) 
    end 
    newText = guiGetText( chats [ player ].edit ) 
    if newText and string.len(newText) > 0 then 
        local oldText = guiGetText(chats [ player ].memo) 
        if not oldText then oldText = "" end 
        oldText = oldText .. getPlayerName(localPlayer) .. ": " .. newText .. "\n" 
        guiSetText(chats [ player ].memo, oldText) 
        guiSetText(chats [ player ].edit, "") 
        guiMemoSetCaretIndex(chats [ player ].memo, string.len(oldText)) 
        triggerServerEvent("sMsg", localPlayer, player, newText)  
    end 
end 
  

--Server

function servmsg ( player, chat ) 
    outputChatBox ( getPlayerName ( player ) ) 
    triggerClientEvent ( player, "rMsg", source, source, chat ) 
end  
addEvent ( "sMsg", true ) 
addEventHandler ( "sMsg", root, servmsg ) 

--Client

---get the message who ever you sent it to.

function receivedMsg ( player, chat ) 
    if not chats [ player ] then 
        buildChatWnd () 
    end 
    local oldText = guiGetText(chats [ player ].memo) 
    if not oldText then oldText = "" end 
    oldText = oldText .. getPlayerName( player ) .. ": " .. chat .. "\n" 
    guiSetText(chats [ player ].memo, oldText) 
    guiMemoSetCaretIndex(chats [ player ].memo, string.len(oldText)) 
end 
addEvent ( "rMsg", true ) 
addEventHandler ( "rMsg", root, receivedMsg )  

Link to comment

Nope, only thing is the other person only gets the message if the window with you is already open, if he doesn't have a little chat window open, and I send the person a message, it will not open the chat window on the targetplayers side, like I said unless his chat window is already open.

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