AhmadRS Posted July 4, 2022 Share Posted July 4, 2022 السلام عليكم ورحمة الله وبركاته .. شباب انا كنت ابغى اسوي مود يرسل رسائل لكل اللاعبين .. والرسالة المفروض تظهر لكل اللاعبين وتنحفظ بقاعدة بيانات بحيث لو رسترت السيرفر او المود الرسايل تفضل موجودة. الحمدلله عرفت اسوي الفكرة هذه بس واجهتني مشكلة وهي ان لو انا وخويي بنفس السيرفر , وارسلت رسالة باللوحة الرسالة بتظهر لي وله وبتنحفظ بقاعدة البيانات ومابتختفي نهائياً . بس لو انا كنت لحالي بالسيرفر وارسلت رسالة , بتنحفظ عندي تمام بس مابتظهر لأي لاعب بيدخل السيرفر بعدين. وهذه صورة للوحة 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 ) Link to comment
TAPL Posted July 4, 2022 Share Posted July 4, 2022 مافهمت انت حافظ السيريال في قاعدة البيانات ليش؟ Link to comment
Mr.Hugin Posted July 4, 2022 Share Posted July 4, 2022 11 hours ago, AhmadRS said: السلام عليكم ورحمة الله وبركاته .. شباب انا كنت ابغى اسوي مود يرسل رسائل لكل اللاعبين .. والرسالة المفروض تظهر لكل اللاعبين وتنحفظ بقاعدة بيانات بحيث لو رسترت السيرفر او المود الرسايل تفضل موجودة. الحمدلله عرفت اسوي الفكرة هذه بس واجهتني مشكلة وهي ان لو انا وخويي بنفس السيرفر , وارسلت رسالة باللوحة الرسالة بتظهر لي وله وبتنحفظ بقاعدة البيانات ومابتختفي نهائياً . بس لو انا كنت لحالي بالسيرفر وارسلت رسالة , بتنحفظ عندي تمام بس مابتظهر لأي لاعب بيدخل السيرفر بعدين. وهذه صورة للوحة 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 ) -- server side connection = dbConnect("sqlite", "database.db") dbExec(connection,"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(connection,"INSERT INTO MessageSaver3(serial, text, playername) VALUES(?, ?, ?)", getPlayerSerial(source), TextInEditBox, playerName ) end end ) addEvent("GetTheDataFromBase",true) addEventHandler("GetTheDataFromBase",root, function ( ) local selectt = executeSQLQuery(connection,"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 ) جرب كذا بس لازم تعدل اشياء كمان بس بدي اعرف كمان اي واحد يرسل رساله للسيرفر يعني نص Link to comment
AhmadRS Posted July 5, 2022 Author Share Posted July 5, 2022 7 hours ago, TAPL said: مافهمت انت حافظ السيريال في قاعدة البيانات ليش؟ وش ممكن احط بدل السيريال؟ 6 hours ago, Mr.Hugin said: -- server side connection = dbConnect("sqlite", "database.db") dbExec(connection,"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(connection,"INSERT INTO MessageSaver3(serial, text, playername) VALUES(?, ?, ?)", getPlayerSerial(source), TextInEditBox, playerName ) end end ) addEvent("GetTheDataFromBase",true) addEventHandler("GetTheDataFromBase",root, function ( ) local selectt = executeSQLQuery(connection,"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 ) جرب كذا بس لازم تعدل اشياء كمان بس بدي اعرف كمان اي واحد يرسل رساله للسيرفر يعني نص اخوي مشكور بس في خطأ بالسطر 81 Link to comment
TAPL Posted July 5, 2022 Share Posted July 5, 2022 16 hours ago, AhmadRS said: وش ممكن احط بدل السيريال؟ اخوي مشكور بس في خطأ بالسطر 81 حاليا كودك يحفظ السيريال في قاعدة البيانات ويستخرج الرسائل من قاعدة البيانات لصاحب السيريال فقط فما اشوف له داعي إذا ما له استخدم ضمن الكود لان حسب كلمك المفروض الرسائل تظهر لكل اللاعبين مو فقط الي ارسلها 16 hours ago, AhmadRS said: if (#database == 0 ) then مو معرف وماله داعي تقدر تحذفه database عندك في هذا السطر او تستبدله بهذا السطر if (connection) then Link to comment
#\_oskar_/# Posted July 5, 2022 Share Posted July 5, 2022 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( ) guiSetVisible(wnd, not guiGetVisible( wnd )) showCursor( guiGetVisible( wnd )) triggerServerEvent("GetTheDataFromBase", localPlayer) end) addEventHandler("onClientGUIClick",inbtn,function () local TextInEditBox = guiGetText(editb) if TextInEditBox == "" then outputChatBox( "#FF0000* #FF8000Testo System #FF0000: #FFFFFF Huh?", 255, 255, 255, true ) return end 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 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,false) 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 ) end) addEvent ( "ReturnDataFromBaseToWindow", true ) addEventHandler ( "ReturnDataFromBaseToWindow", root,function (selectt) guiGridListClear( grd ) for _,v in ipairs (selectt) do row = guiGridListAddRow ( grd ) guiGridListSetItemText ( grd, row, colmn1, v.text , false, false ) guiGridListSetItemText ( grd, row, colmn2, v.name, false, false ) end end) addEventHandler( "onClientResourceStart", resourceRoot,function( ) triggerServerEvent("GetTheDataFromBase", localPlayer) end) addEventHandler("onResourceStart",resourceRoot, function () database = executeSQLQuery("CREATE TABLE IF NOT EXISTS MessageServer3 (text,name)") outputDebugString ("successfully") end) addEvent("TheTextWrittenInEditBox",true) addEventHandler("TheTextWrittenInEditBox",root,function ( TextInEditBox, playerName ) --if #executeSQLQuery("SELECT * FROM MessageServer3 WHERE text=?", TextInEditBox ) == 0 then executeSQLQuery("INSERT INTO MessageServer3 (text,name) VALUES(?, ?)", TextInEditBox, getPlayerName(source)) triggerClientEvent(root,"AddToTheGridForAllPlayers",source, TextInEditBox, getPlayerName(source) )-- send it back with the same message and player name --else outputChatBox("* it is already there",source,255,255,0,true) end end) addEvent("GetTheDataFromBase",true) addEventHandler("GetTheDataFromBase",root,function ( ) triggerClientEvent(source,"ReturnDataFromBaseToWindow",source,executeSQLQuery("SELECT * FROM MessageServer3")) end) غير مجرب Link to comment
Mr.Hugin Posted July 6, 2022 Share Posted July 6, 2022 On 05/07/2022 at 03:00, AhmadRS said: وش ممكن احط بدل السيريال؟ اخوي مشكور بس في خطأ بالسطر 81 مابعرف شو بدي اقلك بس في شوي اغلاط بلمود شوف هاذا ممكن يفيدك 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