Jump to content

Sending datas between server and client side


Noname20

Recommended Posts

Hi! I'm makeing a hud what can save the datas when the player is quit and load it when a player connect. I made the MYSQL part it can save and it can load but I dont know how to send the loaded datas to the client side to make itt appear in a dxdraw. 

This is the Server sided part

addEvent("adatokBetoltese", true)
addEventHandler("adatokBetoltese", resourceRoot,
	function(username, health, food, armor, drink, money)
		local queryHandler = dbQuery(con, 'SELECT * FROM characters')
		local result = dbPoll(queryHandler, 500)
		--outputChatBox("Lefut")
		if (result) then
			--outputChatBox("Itt is")
			if (#result > 0) then
				--outputChatBox("Itt szintén")
				local username = getPlayerName(client)
				if (result[1]["username"] == username) then
					local pH = setElementHealth(client, result[1]["health"])
					local pF = tonumber(setElementData(client, "karakter:ehseg", result[1]["food"]))
					local pA = setPedArmor(client, result[1]["armor"])
					local pW = tonumber(setElementData(client, "karakter:szomjusag", result[1]["drink"]))
					local pM = tonumber(setPlayerMoney(client, result[1]["money"]))
					outputChatBox("1. " ..result[1]["username"])
					outputChatBox("2. " ..result[1]["health"])
					outputChatBox("3. " ..result[1]["food"])
					outputChatBox("4. " ..result[1]["armor"])
					outputChatBox("5. " ..result[1]["drink"])
					outputChatBox("6. " ..result[1]["money"])
					triggerClientEvent("adatLekerdezes", client, pA, pF, pA, pW, pM)
					--outputChatBox("Egyezik!")
					--outputChatBox("Mysql username: " ..result[1]["username"])
				end
			end
		end
	end
)

And this is the client side part. It gives a true or false but idk how to make it a number 

  local pA = triggerServerEvent("adatokBetoltese", localPlayer, pA)
  local pF = tonumber(triggerServerEvent("adatokBetoltese", localPlayer, pF)) or 0
  local pW = tonumber(triggerServerEvent("adatokBetoltese", localPlayer, pW)) or 0
  local pM = tonumber(triggerServerEvent("adatokBetoltese", localPlayer, pM)) or 0

 

Edited by Noname20
Link to comment

Sending data between server and client is called Syncing. You can sync easily, however you only want the traffic to go from server to client and not the other way around. If you were to go the other way around then players would be able to exploit certain parts of your data transfer. You can sync using element data (which is faster, I tested myself) or the safer and more reliable way with events. Either one should work just fine.

Az adatok küldése a kiszolgáló és az ügyfél között szinkronizálás. Könnyedén szinkronizálható, de csak azt szeretné, ha a forgalom kiszolgálóról ügyfélre megy, és nem fordítva. Ha a másik irányba megy, akkor a játékosok képesek lesznek kihasználni az adatátvitel bizonyos részeit. Szinkronizálhatja az elemadatokat (ami gyorsabb, teszteltem magam) vagy a biztonságosabb és megbízhatóbb módokat az eseményekkel. Bármelyiknek jól kell működnie.

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