Hello.
I am gonna start making a trading system for the pointshop items, And wanted to ask if you guys know if there is a funtion which gets all of the player's items.
Thanks in advanced.
[lua]function Player:PS_LoadData()
self.PS_Points = 0
self.PS_Items = {}
PS:GetPlayerData(self, function(points, items)
self.PS_Points = points
self.PS_Items = items
self:PS_SendPoints()
self:PS_SendItems()
self.PS_FirstLoadCompleted = true
end)
end
[/lua]
sv_player_extension.lua.
So I'm guessing PS:GetPlayerData( ply, callbackfunc ) is what you're looking for.
Edit: Or just ply.PS_Items
-snip-
ninjad
[QUOTE=Internet1001;44783900][lua]function Player:PS_LoadData()
self.PS_Points = 0
self.PS_Items = {}
PS:GetPlayerData(self, function(points, items)
self.PS_Points = points
self.PS_Items = items
self:PS_SendPoints()
self:PS_SendItems()
self.PS_FirstLoadCompleted = true
end)
end
[/lua]
sv_player_extension.lua.
So I'm guessing PS:GetPlayerData( ply, callbackfunc ) is what you're looking for.[/QUOTE]
Will this be a global function?
It's a server-side function, but the player stores their own items on their own object (LocalPlayer().PS_Items) and the server does it the same way (ply.PS_Items), meaning you wouldn't have to network the items to the player or to the server as they already are.
Please check my post again, there's a better way than using the GetPlayerData method. The pointshop items are stored on the player as I described in this post.
is it an array?
How would it work?
All PointShop items:
[lua]
for _, ITEM in pairs(PS.Items) do
PrintTable(ITEM)
end
[/lua]
All items for a player:
[lua]
for item_id, item in pairs(ply.PS_Items) do
local ITEM = PS.Items[item_id]
PrintTable(item)
end
[/lua]
Reading the code for pointshop will explain how both of these work in more detail.
[QUOTE=adamdburton;44787935]All PointShop items:
[lua]
for _, ITEM in pairs(PS.Items) do
PrintTable(ITEM)
end
[/lua]
All items for a player:
[lua]
for item_id, item in pairs(ply.PS_Items) do
local ITEM = PS.Items[item_id]
PrintTable(item)
end
[/lua]
Reading the code for pointshop will explain how both of these work in more detail.[/QUOTE]
First of all Thanks!
And how what are the paramters of the item?
Like is there an item.Model for example?
[quote][code]PrintTable(item)[/code][/quote]
This will show you the structure of an item.
[QUOTE=tzahush;44823256]First of all Thanks!
And how what are the paramters of the item?
Like is there an item.Model for example?[/QUOTE]
In both examples ITEM is the same as the ITEM table from each item, and item (lowercase) is a table with Equipped (boolean) and Modifiers (table) keys.
[QUOTE=adamdburton;44823276]In both examples ITEM is the same as the ITEM table from each item, and item (lowercase) is a table with Equipped (boolean) and Modifiers (table) keys.[/QUOTE]
ok, is there anyways of obtaining the model of an ITEM?
[QUOTE=tzahush;44823301]ok, is there anyways of obtaining the model of an ITEM?[/QUOTE]
[url]https://github.com/adamdburton/pointshop[/url]
[url]http://pointshop.burt0n.net/items[/url]
Go wild.
So if I finally understand how it's done, you'll have to do something like this:
[lua]local ply = player.GetByID( 1 )
for k, item in pairs( ply.PS_Items ) do -- Iterate through the players items
local ITEM = PS.Items[ item ] -- Get the item table from the ID
if ITEM.Model then print( ITEM.Model ) end -- prints the model if it has one
end[/lua]
[QUOTE=Internet1001;44823351]So if I finally understand how it's done, you'll have to do something like this:
[lua]local ply = player.GetByID( 1 )
for k, item in pairs( ply.PS_Items ) do -- Iterate through the players items
local ITEM = PS.Items[ item ] -- Get the item table from the ID
if ITEM.Model then print( ITEM.Model ) end -- prints the model if it has one
end[/lua][/QUOTE]
Right ok, Now thanks first of all.
second of all, I wanna make a window full of the guy's inventory, how would i do that?
I mean how can i present the models in a window?
[QUOTE=tzahush;44823358]Right ok, Now thanks first of all.
second of all, I wanna make a window full of the guy's inventory, how would i do that?
I mean how can i present the models in a window?[/QUOTE]
Would you like fries with that?
[url]http://wiki.garrysmod.com/page/VGUI/Elements[/url] to show window
then for loop each item and add it to the window.
[QUOTE=AnonTakesOver;44823365]Would you like fries with that?
[url]http://wiki.garrysmod.com/page/VGUI/Elements[/url] to show window
then for loop each item and add it to the window.[/QUOTE]
Yoo mate im not trying to take the code, but to understand how to do it.
Didn't state that im kinda new to lua.
and thanks.
[QUOTE=tzahush;44823392]Yoo mate im not trying to take the code, but to understand how to do it.
Didn't state that im kinda new to lua.
and thanks.[/QUOTE]
It just seems like you want us to make it, the way you wrote it to me, just seemed that you wanted us to make the entire thing, we will help you, but try to do some research first?
[QUOTE=AnonTakesOver;44823415]It just seems like you want us to make it, the way you wrote it to me, just seemed that you wanted us to make the entire thing, we will help you, but try to do some research first?[/QUOTE]
ok mate, my bad I'll google it better next time :P
But couldn't find anything with showing a model.
[QUOTE=tzahush;44823431]ok mate, my bad I'll google it better next time :P
But couldn't find anything with showing a model.[/QUOTE]
When working with peoples addons, it's essentially an API, read their code, I linked you to the github and documentation earlier.
Independence is a good programming trait.
Sorry, you need to Log In to post a reply to this thread.