Jump to content

PM system pls


Dice

Recommended Posts

Posted

Hi, i am working on a PM system GUI and all, I got it down, I am confused on the playerlist, i have them on there, i have it so it updates when a player changed their name or quits or joins etc.

I got it so when I double click a name a PM window pops up and the title at the top says "PMing : thePlayersName" anyways I have that part down no problem, but how can I make it so the window only pops up when one of the items (players) are clicked. For example if I click the bottom of the gridlist where there are no objects filled, the PM window pops up "PMing: " <-- i dont want it to do that, i only want it to pop up when the items are clicked.

  
addEventHandler( "onClientGUIDoubleClick", playerlist, msgwino, false ) 
function msgwino () 
    local playerName = guiGridListGetItemText ( playerlist, guiGridListGetSelectedItem ( playerlist ), 1 ) 
    msgwin = guiCreateWindow(889, 491, 342, 298, "PM with: " ..playerName, false) 
    guiWindowSetSizable(msgwin, false) 
    chatmemo = guiCreateMemo(14, 45, 312, 206, "", false, msgwin) 
    guiMemoSetReadOnly(chatmemo, true) 
    sendpm = guiCreateEdit(14, 261, 227, 26, "", false, msgwin) 
    guiSetProperty(sendpm, "NormalTextColour", "FF7F7F7F") 
    sendbut = guiCreateButton(248, 260, 78, 27, "Send", false, msgwin) 
    close = guiCreateButton(314, 23, 18, 18, "X", false, msgwin) 
end 
  

That is what I have so far, i know the 'playerlist' is basically saying that if I click anywere on the gridlist it pops up, but i want it only when i double click the items.

also this makes me wonder, what if there are multiple players in that server and i double click all there names and all the PM window pops up, are all these varables going to be overwritten? how can i make it so i can close the windows, as you can see

close%20=%20guiCreateButton(314,%2023,%2018,%2018,%20"X",%20false,%20msgwin)

I have a feeling if multiple players are in that server i close one window and more windows are opened it won't work anymore because when i close it i was planning to destroy all teh GUI's for that window, but since all will have the same, "variables" once i close one, and try to close the other, that"close" technically won't exist no more.

Posted
function msgwino () 
    local row, col = guiGridListGetSelectedItem ( playerlist ) 
    if ( row and col and row ~= -1 and col ~= -1 ) then 
        local playerName = guiGridListGetItemText ( playerlist, row, 1 ) 
        msgwin = guiCreateWindow(889, 491, 342, 298, "PM with: " ..playerName, false) 
        guiWindowSetSizable(msgwin, false) 
        chatmemo = guiCreateMemo(14, 45, 312, 206, "", false, msgwin) 
        guiMemoSetReadOnly(chatmemo, true) 
        sendpm = guiCreateEdit(14, 261, 227, 26, "", false, msgwin) 
        guiSetProperty(sendpm, "NormalTextColour", "FF7F7F7F") 
        sendbut = guiCreateButton(248, 260, 78, 27, "Send", false, msgwin) 
        close = guiCreateButton(314, 23, 18, 18, "X", false, msgwin) 
    end 
end 

You can make a table to store all GUI elements of each chat.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Thanks this worked! all I need help with is that

The issue we were talking about with tables, I have always tried to avoid tables because I hated them with a passion. how can I do that here?

function msgwino () 
    local row, col = guiGridListGetSelectedItem ( playerlist ) 
    if ( row and col and row ~= -1 and col ~= -1 ) then 
        local playerName = guiGridListGetItemText ( playerlist, row, 1 ) 
        msgwin = guiCreateWindow(889, 491, 342, 298, "PM with: " ..playerName, false) 
        guiWindowSetSizable(msgwin, false) 
        chatmemo = guiCreateMemo(14, 45, 312, 206, "", false, msgwin) 
        guiMemoSetReadOnly(chatmemo, true) 
        sendpm = guiCreateEdit(14, 261, 227, 26, "", false, msgwin) 
        guiSetProperty(sendpm, "NormalTextColour", "FF7F7F7F") 
        sendbut = guiCreateButton(248, 260, 78, 27, "Send", false, msgwin) 
        close = guiCreateButton(314, 23, 18, 18, "X", false, msgwin) 
        addEventHandler ( "onClientGUIClick", close, msgwinclose ) 
    end 
end 
  
function msgwinclose() 
    _destroyElement ( msgwin ) 
end 

I know this is wrong and you told me with tables, can you show me how? because like this as I have it if i have multiple windows open the

addEventHandler ( "onClientGUIClick", close, msgwinclose ) 

will only wwork once.

Posted
chats = { } 
  
function msgwino () 
    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 ) then 
            chats [ player ] = { } 
            chats [ player ].window = guiCreateWindow(889, 491, 342, 298, "PM with: " ..playerName, 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) 
            guiSetProperty(chats [ player ].edit, "NormalTextColour", "FF7F7F7F") 
            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 ].close, 
                function ( ) 
                    _destroyElement ( chats [ player ].window ) 
                end 
                ,false 
            ) 
        end 
    end 
end 

I haven't tested it, I leave that to you.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

thank you works really good now pls!

but why when i try to let's say set the visibility of the to false it gives me an error 'attempt to index fields ? a nil value'

sorry my experience with tables are really shitty.

function openpm () 
    if (guiGetVisible(pmmain) == false) then 
        guiSetVisible ( pmmain, true ) 
        guiSetVisible ( chats [ player ].window, true ) --ISSUE HEREpls 
        showCursor( guiGetVisible( pmmain ) ) 
        guiSetInputEnabled(true) 
        toggleAllControls( false ) 
    else 
        guiSetVisible ( pmmain, false ) 
        guiSetVisible ( chats [ player ].window, false ) --nhere pls 
        showCursor( guiGetVisible( pmmain ) ) 
        guiSetInputEnabled( false ) 
        toggleAllControls( true ) 
    end 
end 

Posted

'player' is not defined anywhere.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

This is what I have so far.

chats = { } 
  
function msgwino () 
    local row, col = guiGridListGetSelectedItem ( playerlist ) 
    if ( row and col and row ~= -1 and col ~= -1 ) then 
        local playerName = guiGridListGetItemText ( playerlist, row, 1 ) 
        local player = getPlayerName ( getPlayerFromName ( playerName ) ) 
        if ( player ) then 
            chats [ player ] = { } 
            chats [ player ].window = guiCreateWindow(889, 491, 342, 298, "PM with: " ..playerName, 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) 
            guiSetProperty(chats [ player ].edit, "NormalTextColour", "FF7F7F7F") 
            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 ].close, 
                function ( ) 
                    _destroyElement ( chats [ player ].window ) 
                end 
                ,false 
            ) 
        end 
    end 
end 
  
  
function openpm () 
    if (guiGetVisible(pmmain) == false) then 
        guiSetVisible ( pmmain, true ) 
        guiSetVisible ( chats [ player ].window, true ) 
        showCursor( guiGetVisible( pmmain ) ) 
        guiSetInputEnabled(true) 
        toggleAllControls( false ) 
    else 
        guiSetVisible ( pmmain, false ) 
        guiSetVisible ( chats [ player ].window, false ) 
        showCursor( guiGetVisible( pmmain ) ) 
        guiSetInputEnabled( false ) 
        toggleAllControls( true ) 
    end 
end 
  

I know they are local, but this is where i had it before trying a whole bunch of shit, i tried making them global, even passing the variables onto openpm() , this is driving me nuts, last time i tries to get involved with tables i nearly fucked my screen -.-. i am so lost with this part

Posted

What are you trying to do?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

sorry i didn't post 100 percent of the client script but, anways there is a bind to close and open the PM main window that has a list of all the players, on top of that i want to make it so if i press the bind (which i already have 'f3' ) the little PM window's closes also, all the ones that are open which is the

chats [ player ].window 

<---those are the little pm windows.

anyways when i press the bind is where i get that error.

'attempt to index fields ? a nil value'

Posted

Use this:

for _, element in pairs ( chats ) do 
    if ( isElement ( element ) ) then 
        if ( getElementType ( element ) == "gui-window" ) then 
            guiSetVisible ( element, false ) 
        end 
    end 
end 

That should hide all the windows.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

It still doesn't work, my main window disappears just fine, but those little pm windows won't , i tried some stuff of my own too but nothing.

only positive thing is that the error is gone

Posted

Post your entire script.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        pmmain = guiCreateWindow(1020, 410, 253, 398, "", false) 
        guiWindowSetSizable(pmmain, false) 
        playerlist = guiCreateGridList(10, 68, 234, 277, false, pmmain) 
        pcolumn = guiGridListAddColumn(playerlist, "Player List", 0.9) 
        pmbut = guiCreateButton(20, 357, 80, 27, "Msg", false, pmmain) 
        notifychk = guiCreateCheckBox(130, 360, 93, 21, "sound", true, false, pmmain) 
        ftalabel = guiCreateLabel(42, 40, 170, 18, "pm system", false, pmmain) 
        guiSetFont(ftalabel, "clear-normal") 
        playerName = guiGridListGetItemText ( playerlist, guiGridListGetSelectedItem ( playerlist ), 1 ) 
        for id, player in ipairs ( getElementsByType ( "player" ) ) do 
        guiGridListSetItemText ( playerlist, guiGridListAddRow ( playerlist ), pcolumn, getPlayerName ( player ), false, false ) 
        end 
        -- 
        addEventHandler( "onClientGUIDoubleClick", playerlist, msgwino, false ) 
        -- 
        guiSetVisible ( pmmain, false )  
    end 
) 
  
  
  
chats = { } 
  
function msgwino () 
    local row, col = guiGridListGetSelectedItem ( playerlist ) 
    if ( row and col and row ~= -1 and col ~= -1 ) then 
        local playerName = guiGridListGetItemText ( playerlist, row, 1 ) 
        local player = getPlayerName ( getPlayerFromName ( playerName ) ) 
        if ( player ) then 
            chats [ player ] = { } 
            chats [ player ].window = guiCreateWindow(889, 491, 342, 298, "PM with: " ..playerName, 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) 
            guiSetProperty(chats [ player ].edit, "NormalTextColour", "FF7F7F7F") 
            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 ].close, 
                function ( ) 
                    _destroyElement ( chats [ player ].window ) 
                end 
                ,false 
            ) 
        end 
    end 
end 
  
bindKey ( "F3", "down",  
    function () 
        if (guiGetVisible(pmmain) == false) then 
            guiSetVisible ( pmmain, true ) 
            showCursor( guiGetVisible( pmmain ) ) 
            guiSetInputEnabled(true) 
            toggleAllControls( false ) 
        else 
            guiSetVisible ( pmmain, false ) 
            showCursor( guiGetVisible( pmmain ) ) 
            guiSetInputEnabled( false ) 
            toggleAllControls( true ) 
        end 
    end 
) 
  
  

btw the one u just gave me i removed it, when i messed up trying different stuff

Posted
addEventHandler ( "onClientResourceStart", resourceRoot, 
    function ( ) 
        chats = { } 
  
        pmmain = guiCreateWindow(1020, 410, 253, 398, "", false) 
        guiWindowSetSizable(pmmain, false) 
        playerlist = guiCreateGridList(10, 68, 234, 277, false, pmmain) 
        pcolumn = guiGridListAddColumn(playerlist, "Player List", 0.9) 
        pmbut = guiCreateButton(20, 357, 80, 27, "Msg", false, pmmain) 
        notifychk = guiCreateCheckBox(130, 360, 93, 21, "sound", true, false, pmmain) 
        ftalabel = guiCreateLabel(42, 40, 170, 18, "pm system", false, pmmain) 
        guiSetFont(ftalabel, "clear-normal") 
        playerName = guiGridListGetItemText ( playerlist, guiGridListGetSelectedItem ( playerlist ), 1 ) 
        for id, player in ipairs ( getElementsByType ( "player" ) ) do 
            guiGridListSetItemText ( playerlist, guiGridListAddRow ( playerlist ), pcolumn, getPlayerName ( player ), false, false ) 
        end 
        -- 
        addEventHandler( "onClientGUIDoubleClick", playerlist, msgwino, false ) 
        -- 
        guiSetVisible ( pmmain, false )  
    end 
) 
  
function msgwino () 
    local row, col = guiGridListGetSelectedItem ( playerlist ) 
    if ( row and col and row ~= -1 and col ~= -1 ) then 
        local playerName = guiGridListGetItemText ( playerlist, row, 1 ) 
        local player = getPlayerName ( getPlayerFromName ( playerName ) ) 
        if ( player ) then 
            chats [ player ] = { } 
            chats [ player ].window = guiCreateWindow(889, 491, 342, 298, "PM with: " ..playerName, 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) 
            guiSetProperty(chats [ player ].edit, "NormalTextColour", "FF7F7F7F") 
            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 ].close, 
                function ( ) 
                    destroyElement ( chats [ player ].window ) 
                end 
                ,false 
            ) 
        end 
    end 
end 
  
bindKey ( "F3", "down", 
    function ( ) 
        if ( guiGetVisible ( pmmain ) == false ) then 
            guiSetVisible ( pmmain, true ) 
            showCursor ( guiGetVisible ( pmmain ) ) 
            guiSetInputEnabled ( true ) 
            toggleAllControls ( false ) 
        else 
            guiSetVisible ( pmmain, false ) 
            showCursor ( guiGetVisible ( pmmain ) ) 
            guiSetInputEnabled ( false ) 
            toggleAllControls ( true ) 
            for _, elements in pairs ( chats ) do 
                for _, element in pairs ( elements ) do 
                    if ( isElement ( element ) ) then 
                        if ( getElementType ( element ) == "gui-window" ) then 
                            guiSetVisible ( element, false ) 
                        end 
                    end 
                end 
            end 
        end 
    end 
) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

ffs finally lol thanks a bunch!!!

2 Random questions, what is the hash tag for? when i see it on things like for example #players or #elements

and

difference between ipairs and pairs?

thanks a lot!

Posted

I haven't used it on that script. Is used to count the items of an indexed table, or a variable to count the characters.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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