AhmadRS Posted July 4, 2022 Share Posted July 4, 2022 Hello guys So I created this mod which saves whatever the player writes in this window. The message is supposed to be sent to all players and be saved in the database, which I was able to do successfully. But unfortunately, the mod sends and saves whatever the player writes only for those who are online. For example: I sent a message while me and my friend are online, It's saved and appears for both of us even if the mod was restarted. But if another player joins, he won't be able to see what I sent. The window: Client Side -- client side local screenW, screenH = guiGetScreenSize() wnd = guiCreateWindow((screenW - 557) / 2, (screenH - 340) / 2, 557, 340, "Test window", false)-- window guiWindowSetSizable(wnd, false) guiSetVisible(wnd,false) grd = guiCreateGridList(9, 28, 538, 170, false, wnd) colmn1 = guiGridListAddColumn(grd, "Message", 0.5)-- colmn for messages colmn2 = guiGridListAddColumn(grd, "Playername", 0.5)-- colmn for player name editb = guiCreateEdit(31, 208, 491, 42, "", false, wnd)-- editbox inbtn = guiCreateButton(143, 270, 271, 60, "Insert", false, wnd)-- insert button guiSetProperty(inbtn, "NormalTextColour", "FF00FF0C") bindKey("F6","down", function () if ( guiGetVisible(wnd) == false ) then guiSetVisible(wnd,true) showCursor(true) else guiSetVisible(wnd,false) showCursor(false) end end) addEventHandler("onClientGUIClick",inbtn, function () local TextInEditBox = guiGetText(editb) if ( guiEditGetCaretIndex( editb ) > 36 ) then outputChatBox( "#FF0000* #FF8000Testo System #FF0000: #FFFFFF It's a very long name.. what do you think", 255, 255, 255, true ) return end if ( TextInEditBox == '') then outputChatBox( "#FF0000* #FF8000Testo System #FF0000: #FFFFFF Huh?", 255, 255, 255, true ) return end if ( guiEditGetCaretIndex( editb ) < 7 ) then outputChatBox( "#FF0000* #FF8000Testo System #FF0000: #FFFFFF Are you sure that's a song name?", 255, 255, 255, true ) return end triggerServerEvent("TheTextWrittenInEditBox",localPlayer, TextInEditBox )-- send the message to server side end ) addEvent("AddToTheGridForAllPlayers",true) addEventHandler("AddToTheGridForAllPlayers",root, function ( TextInEditBox, playerName ) row = guiGridListAddRow ( grd ) guiGridListSetItemText ( grd, row, colmn1, TextInEditBox , false, false ) guiGridListSetItemText ( grd, row, colmn2, playerName , false, false ) triggerServerEvent("InsertIntoDataBase",localPlayer, TextInEditBox, playerName ) end ) addEvent("ReturnDataFromBaseToWindow",true) addEventHandler("ReturnDataFromBaseToWindow",root, function ( SavedText, SavedPlayerName ) row = guiGridListAddRow ( grd ) guiGridListSetItemText ( grd, row, colmn1, SavedText , false, false ) guiGridListSetItemText ( grd, row, colmn2, SavedPlayerName , false, false ) end ) triggerServerEvent("GetTheDataFromBase",localPlayer ) Server side -- server side local database = executeSQLQuery("CREATE TABLE IF NOT EXISTS MessageSaver3 (serial, text, playername)") addEvent("TheTextWrittenInEditBox",true) addEventHandler("TheTextWrittenInEditBox",root, function ( TextInEditBox ) local playerName = getPlayerName(source) triggerClientEvent(root,"AddToTheGridForAllPlayers",source, TextInEditBox, playerName )-- send it back with the same message and player name end ) addEvent("InsertIntoDataBase",true) addEventHandler("InsertIntoDataBase",root, function ( TextInEditBox, playerName ) if (#database == 0 ) then executeSQLQuery("INSERT INTO MessageSaver3(serial, text, playername) VALUES(?, ?, ?)", getPlayerSerial(source), TextInEditBox, playerName ) end end ) addEvent("GetTheDataFromBase",true) addEventHandler("GetTheDataFromBase",root, function ( ) local selectt = executeSQLQuery("SELECT * FROM MessageSaver3 WHERE serial=?", getPlayerSerial(source) ) if (#selectt ~= 0) then for _,v in ipairs (selectt) do local SavedText = v.text local SavedPlayerName = v.playername triggerClientEvent(source,"ReturnDataFromBaseToWindow",source, SavedText, SavedPlayerName )-- send the data to gridlist end end end ) I want it to save whatever any player writes 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