harryh Posted March 20, 2017 Share Posted March 20, 2017 Hi, I cant seem to call a serverside event which runs a function to get infomation from the database then return it to clientside to update the clientside text label. Client: triggerServerEvent( "checkDog", getLocalPlayer( ) ) guiSetText( DogPanel.dogName, getDInfo["Name"] ) server: function loadPlayerInfo() local dbid = getElementData(source, "account:id") getDInfo = mysql:query_fetch_assoc("SELECT * FROM dogs WHERE pID = '" ..dbid.."'") gettheplayer = getPlayerName(source) outputChatBox("dbid:" ..tostring(dbid)) --InfoArray = getDInfo(result) if getDInfo then setElementData(source, "haveDog", true) outputChatBox("Your Dog is Called " ..getDInfo["Name"]) dogInfo = getDInfo getSkin = getDInfo["DogSkin"] return true, getDInfo elseif not getDInfo then setElementData(source, "haveDog", false) --No dog saved to DB outputChatBox("No Dog In DB.") else outputChatBox("Fatal Error has occured please contact administrator.") end end addEvent("checkDog", true) addEventHandler("checkDog", getRootElement(), loadPlayerInfo) addCommandHandler("loaddogs", loadPlayerInfo) Link to comment
Discord Moderators Zango Posted March 21, 2017 Discord Moderators Share Posted March 21, 2017 Is there any reason you're using the old mysql module and not MTA's database functions? Could you provide some more information on any errors you get? (use /debugscript 3) Is this the full code? When you run clientside code it runs in your MTA client, and when you run serverside code it runs in the MTA server. You can only communicate between these two by events and element data. So when you want to transfer the results from the database, you need to use triggerClientEvent to send it back to the client and put it into the text label. Link to comment
harryh Posted March 22, 2017 Author Share Posted March 22, 2017 I have fixed the problem and I didn't know mta had DB functions that work for mysql. I thought it was only sqlite. Im not going to change everything because the mysql module works fine. 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