Jump to content

Using return to transfer serverside into back to client side after calling server


harryh

Recommended Posts

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

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

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