Jump to content

mySQL or getAccount for inventory system?


Cronoss

Recommended Posts

I know I asked something like this before in this topic but now I'm confused, I wanted to create an Inventory system, so i searched info, sadly, the only tutorial that I found about it (using SQL), it's a type of inventory I don't really like. My idea was making a inventory with a gui, get the player objets (like weapons) and showing the data in the gui panel with a text, I don't know if this is possible, but it's how I want to it looks like. I'm not trying to make new objets wich the player can give to other players like food, I want to create an inventory that would save the weapons, and other parameters that the player CAN'T give to other players. Example if this is possible wich commands I can use ? 

 

example of what I'm talking about:

function lalala()
  player = getPlayerAccount(source)
  weapon = getPedWeapons(source)
  textgui = your weapon is ..weapon
end
addEventHandler("onResourceStart", root, lalala)

------------ then

guiSetText( myLabel, textgui )

  

Sorry for my bad english

Link to comment

Either SQL or the built in account system will work just fine, what I whould do is locally store player data in a table and ONLY change that table ( A lot faster and better than sending SQL requests/execute get/setAccountData all the time ) and save/load that table to account system/SLQ 

I made you a quick example :

 

playerData = {}; -- This is the table that will serve us as a database!


addEventHandler("onPlayerLogin", root, function(oldAcc, acc)
	if not playerData[source] then
		playerData[source] = {}; -- create a entry on the table for our player!
	end
	local data = getAccountData(acc, "server.data.table") or false; -- get player data if stored already
	if data then
		playerData[source] = fromJSON(data); -- cash data in table for later use!
	end
end);

function playerHasLeft(player)
	if playerData[player] then
		local acc = getPlayerAccount(player);
		if acc then
			setAccountData(acc, "server.data.table", toJSON(playerData[player]));
			playerData[player] = {}; --clear cash
		end
	end
end

addEventHandler("onPlayerQuit", root, function()
	playerHasLeft(source);
end);
addEventHandler("onPlayerLogout", root, function()
	playerHasLeft(source);
end);

function setPlayerSomeData(player, key, data)
	if player and key and data then
		if not playerData[player] then
			playerData[player] = {};
		end
		playerData[player][key] = data; -- save to cash table
		return true;
	end
	return false;
end

function getPlayerSomeData(player, key)
	if player and key then
		if not playerData[player] then
			return false;
		end
		return playerData[player][key];
	end
	return false;
end


addCommandHandler("test1", function(player)
	setPlayerSomeData(player, "M4", 5);
	setPlayerSomeData(player, "AK-47", 1);
end);
-- etc...

-- TEST
addCommandHandler("test2", function(player)
	outputChatBox("You have:");
	for key, value in pairs(playerData[player]) do
		outputChatBox(value.." x "..key);
	end
end);

 

 

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