Castillo Posted September 26, 2012 Share Posted September 26, 2012 Your events server side are: "ShowMenuC" and "notify". Your event client side is: "telluser". Link to comment
TheNightRider Posted September 26, 2012 Author Share Posted September 26, 2012 Your events server side are: "ShowMenuC" and "notify".Your event client side is: "telluser". Yeah I forgot to relate to the addEvent of a function it now works thanks man now I can get on with the next batch of stuff LOL Link to comment
TheNightRider Posted September 26, 2012 Author Share Posted September 26, 2012 Am working on the next stage, ive got it to query for the usernames I did a test and the first username in the table showed on chat as exspected. The issue am having is passing the data to clientside so it will be displayed on the Gridlist. Serverside:- function UsrList( playerSource)--query database table for list of users to be used on clientside. local usrs = mysql:query_fetch_assoc("SELECT username FROM accounts ") if (usrs) then triggerClientEvent (( usrs["username"]),"getlist",true) outputChatBox ( tostring ( usrs ["username"] ) ) end end addCommandHandler ( "dbmanl", UsrList ) Clientside so far:- addEvent ("getlist",true) function Listing()--Display list of users in gridlist on GUI. local addrow = guiGridListAddRow(UsrList) guiGridListSetItemText(UsrList,addrow,Col,(usrs ["username"]) ,false,false) end addEventHandler("getlist",getRootElement(),Listing) Link to comment
Castillo Posted September 26, 2012 Share Posted September 26, 2012 -- client side. addEvent ( "getlist", true ) function Listing ( user ) local addrow = guiGridListAddRow ( UsrList ) guiGridListSetItemText ( UsrList, addrow, Col, user, false, false ) end addEventHandler ( "getlist", getRootElement(), Listing ) -- server side: function UsrList ( playerSource ) local result = mysql:query ( "SELECT username FROM accounts" ) if ( result ) then while true do local row = mysql:fetch_assoc ( result ) if ( not row ) then break end triggerClientEvent ( playerSource, "getList", playerSource, row [ "username" ] ) end end end addCommandHandler ( "dbmanl", UsrList ) Try it. Link to comment
TheNightRider Posted September 27, 2012 Author Share Posted September 27, 2012 -- server side: function UsrList ( playerSource ) local usrs = mysql:query_fetch_assoc ( "SELECT username FROM accounts" ) if ( usrs ) then triggerClientEvent ( playerSource, "getList", playerSource, usrs ) end end addCommandHandler ( "dbmanl", UsrList ) -- client side: addEvent ( "getlist", true ) function Listing ( users ) for _, user in ipairs ( users ) do local addrow = guiGridListAddRow ( UsrList ) guiGridListSetItemText ( UsrList, addrow, Col, user [ "username" ], false, false ) end end addEventHandler ( "getlist", getRootElement(), Listing ) Try it. I did try it what you wrote and there was no output to gridedit and no errors. Link to comment
Castillo Posted September 27, 2012 Share Posted September 27, 2012 Copy the code again. Link to comment
TheNightRider Posted September 27, 2012 Author Share Posted September 27, 2012 -- client side. addEvent ( "getlist", true ) function Listing ( user ) local addrow = guiGridListAddRow ( UsrList ) guiGridListSetItemText ( UsrList, addrow, Col, user, false, false ) end addEventHandler ( "getlist", getRootElement(), Listing ) -- server side: function UsrList ( playerSource ) local result = mysql:query ( "SELECT username FROM accounts" ) if ( result ) then while true do local row = mysql:fetch_assoc ( result ) if ( not row ) then break end triggerClientEvent ( playerSource, "getList", playerSource, row [ "username" ] ) end end end addCommandHandler ( "dbmanl", UsrList ) Try it. Thanks man that works great Link to comment
TheNightRider Posted September 27, 2012 Author Share Posted September 27, 2012 Am working on the next piece of code for some reason it keeps on returning a boolean for each guiSetText although I guess it could be cos of the other issue. When I try to make the trigger work 1 am not too sure what the first argument I should be using in this case and why its saying the 2nd argument is saying expected element got string when the argument is an addEvent. PS its a TextEdit box am using to display the data for each id, admin etc. I'll be most thankful to anyone who gives me some good advice on the related issues. ClientSide addEvent("takedata",true) function retrieve(userdata) local selected = guiGridListGetSelectedItem(UsrList) if (selected) then triggerServerEvent( addrow, "SelectD", true ) local id=guiSetText(IDEd,userdata["id"]) local usr=guiSetText(UsrN,userdata["username"]) local admin=guiSetText(ALvl,userdata["admin"] ) local reason=guiSetText(Banned,userdata["banned_reason"] ) else if not(selected) then return 0 end end end addEventHandler("takedata",getRootElement(),retrieve) ServerSide addEvent("selectD",true) function getselected() local result = mysql:query ( "SELECT id, admin, adminjail_time,banned_reason FROM accounts WHERE 'username'="..select.."'" ) if (result["select"]) then local data= mysql:fetch_assoc(result) -- outputChatBox ( data["admin"] ) end triggerClientEvent ( playerSource, "takedata", playerSource, data ) end addEventHandler("SelectD",getRootElement(),getselected Link to comment
Renkon Posted September 27, 2012 Share Posted September 27, 2012 GuiSetText only returns true or false. To get the text you should use GuiGetText Link to comment
TheNightRider Posted September 27, 2012 Author Share Posted September 27, 2012 GuiSetText only returns true or false.To get the text you should use GuiGetText Thanks man I wondering whats with the triggerServerSide I cannot fathom out the issue. I changed it to what you said but its still telling me that userdata is boolean. Link to comment
Renkon Posted September 27, 2012 Share Posted September 27, 2012 Read https://wiki.multitheftauto.com/wiki/triggerServerEvent Link to comment
TheNightRider Posted September 27, 2012 Author Share Posted September 27, 2012 (edited) Read https://wiki.multitheftauto.com/wiki/triggerServerEvent Thanks ive fixed that part Its supposed to get the data from the guigridlist if selected and run it within the sql query so it gets the data of that username. I am not sure where am going wrong with this section. The problem is it doesn't seem to be passing the data onto the ClientSide. addEvent("SelectD",true) function getselected(take) outputChatBox ( take ) local result = mysql:query_fetch_assoc ( "SELECT id, admin, adminjail_time,banned_reason FROM accounts WHERE 'username'="..take.."'" ) if (result["take"]) then local data= mysql:fetch_assoc(result) end triggerClientEvent ( playerSource, "takedata", playerSource, data["id"] ) end addEventHandler("SelectD",getRootElement(),getselected ClientSide:- addEvent("takedata",true) function retrieve(selected) local selected = guiGridListGetSelectedItem(UsrList) if (selected) then triggerServerEvent( "SelectD",getRootElement(), UsrList ) local id=GuiGetText(IDEd,selected["id"]) local usr=GuiGetText(UsrN,selected["username"]) local admin=GuiGetText(ALvl,selected["admin"] ) local reason=GuiGetText(Banned,selected["banned_reason"] ) else if not(selected) then return 0 end end end addEventHandler("takedata",getRootElement(),retrieve) Edited September 28, 2012 by Guest Link to comment
Renkon Posted September 27, 2012 Share Posted September 27, 2012 Serverside where's playerSource defined btw? and triggeringServerEvent I'd rather use localPLAYER than GetRootElement. Link to comment
TheNightRider Posted September 27, 2012 Author Share Posted September 27, 2012 (edited) Serverside where's playerSource defined btw?and triggeringServerEvent I'd rather use localPLAYER than GetRootElement. Okay thanks for that but am not able to figure out why its not passing the data to ClientSide as its always returning a Boolean value You know that is off subject cos its got nothing to do with why a value is returning a value whatsoever and its getLocalPlayer which does Sweet FA eg in this instance it returns an error Edited September 28, 2012 by Guest Link to comment
TheNightRider Posted September 28, 2012 Author Share Posted September 28, 2012 I divided the clientside function into 2 in the hope to solve the issue but the problem still remains, could you explain why selected returning a Boolean value ddEvent("item",true) function selecteditem(datainput) local datainput = guiGridListGetSelectedItem(UsrList) if (datainput) then triggerServerEvent( "SelectD",getRootElement(), UsrList ) else if not (datainput) then return 0 end end end addEventHandler("item",getRootElement(),selecteditem) addEvent("takedata",true) function retrieve(selected) if not (selected) then outputChatBox ( selected ) return 0 else if (selected) then local id=GuiGetText(IDEd,selected["id"]) local usr=GuiGetText(UsrN,selected["username"]) local admin=GuiGetText(ALvl,selected["admin"] ) local reason=GuiGetText(Banned,selected["banned_reason"] ) end end end addEventHandler("takedata",getRootElement(),retrieve) Link to comment
Anderl Posted September 29, 2012 Share Posted September 29, 2012 Server-side: addEvent('selector:query', true) addEventHandler('selector:query', root, function(szUser) --outputChatBox(mValue) local pQuery = mysql:query_fetch_assoc('SELECT id, admin, adminjail__time, banned_reason FROM `accounts` WHERE username = "'..szUser..'"') pQuery = mysql:fetch_assoc(pQuery) -- triggerClientEvent(source, 'selector:retrieve', source, pQuery, szUser) end ) Client-side: addEvent('selector:retrieve', true) addEventHandler('selector:retrieve', root, function(pData, szUser) guiSetText(IDEd, pData.id) guiSetText(UsrN, szUser) guiSetText(ALvl, pData.admin) guiSetText(Banned, pData['banned_reason']) end ) Just trigger server-side event "selector:query" with username as string when you need to get details. P.S. Not tested. Link to comment
TheNightRider Posted October 3, 2012 Author Share Posted October 3, 2012 Server-side: addEvent('selector:query', true) addEventHandler('selector:query', root, function(szUser) --outputChatBox(mValue) local pQuery = mysql:query_fetch_assoc('SELECT id, admin, adminjail__time, banned_reason FROM `accounts` WHERE username = "'..szUser..'"') pQuery = mysql:fetch_assoc(pQuery) -- triggerClientEvent(source, 'selector:retrieve', source, pQuery, szUser) end ) Client-side: addEvent('selector:retrieve', true) addEventHandler('selector:retrieve', root, function(pData, szUser) guiSetText(IDEd, pData.id) guiSetText(UsrN, szUser) guiSetText(ALvl, pData.admin) guiSetText(Banned, pData['banned_reason']) end ) Just trigger server-side event "selector:query" with username as string when you need to get details. P.S. Not tested. Thanks budy but it returns an error saying attempt to index local pData (boolean value) regarding the following line:- guiSetText(IDEd, pData.id) PS is the function which retrieves selected user from gridlist:- function selecteditem(datainput) local datainput = guiGridListGetSelectedItem(UsrList) if(datainput) then triggerServerEvent( "selector:query",getRootElement(), datainput) end end Link to comment
Castillo Posted October 3, 2012 Share Posted October 3, 2012 guiGridListGetSelectedItem doesn't return the text of the selected item, it returns the row and column index of the selected item. function selecteditem ( ) local row, col = guiGridListGetSelectedItem ( UsrList ) if ( row and col and row ~= -1 and col ~= -1 ) then local playerName = guiGridListGetItemText ( UsrList, row, 1 ) triggerServerEvent ( "selector:query", localPlayer, playerName ) end end Link to comment
TheNightRider Posted October 3, 2012 Author Share Posted October 3, 2012 guiGridListGetSelectedItem doesn't return the text of the selected item, it returns the row and column index of the selected item. function selecteditem ( ) local row, col = guiGridListGetSelectedItem ( UsrList ) if ( row and col and row ~= -1 and col ~= -1 ) then local playerName = guiGridListGetItemText ( UsrList, row, 1 ) triggerServerEvent ( "selector:query", localPlayer, playerName ) end end Thanks mate got that section working finally LOl. PS the pData is still returning as Boolean do you have any idea's why this is so? Link to comment
Anderl Posted October 3, 2012 Share Posted October 3, 2012 My mistake, local pQuery = mysql:query_fetch_assoc('SELECT id, admin, adminjail__time, banned_reason FROM `accounts` WHERE username = "'..szUser..'"') pQuery = mysql:fetch_assoc(pQuery) Change to: local pQuery = mysql:query_fetch_assoc('SELECT id, admin, adminjail__time, banned_reason FROM `accounts` WHERE username = "'..szUser..'"') Link to comment
TheNightRider Posted October 3, 2012 Author Share Posted October 3, 2012 My mistake, local pQuery = mysql:query_fetch_assoc('SELECT id, admin, adminjail__time, banned_reason FROM `accounts` WHERE username = "'..szUser..'"') pQuery = mysql:fetch_assoc(pQuery) Change to: local pQuery = mysql:query_fetch_assoc('SELECT id, admin, adminjail__time, banned_reason FROM `accounts` WHERE username = "'..szUser..'"') Thanks mate that did the trick works fine I just need to alter it in places so it only does if true eg if there is nothing for example banned_reason it won't try to show it on GUI otherwise it flags a bad argument but I can do that myself. Am still bit of a Noob when it comes to LUA for MTA but am slowly finding my way around things. You guys have been most helpful Link to comment
Anderl Posted October 4, 2012 Share Posted October 4, 2012 My mistake, local pQuery = mysql:query_fetch_assoc('SELECT id, admin, adminjail__time, banned_reason FROM `accounts` WHERE username = "'..szUser..'"') pQuery = mysql:fetch_assoc(pQuery) Change to: local pQuery = mysql:query_fetch_assoc('SELECT id, admin, adminjail__time, banned_reason FROM `accounts` WHERE username = "'..szUser..'"') Thanks mate that did the trick works fine I just need to alter it in places so it only does if true eg if there is nothing for example banned_reason it won't try to show it on GUI otherwise it flags a bad argument but I can do that myself. Am still bit of a Noob when it comes to LUA for MTA but am slowly finding my way around things. You guys have been most helpful Glad I could help. 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