Coder Social home page Coder Social logo

PurchaseData about pointshop2 HOT 8 CLOSED

pkmnmstr98 avatar pkmnmstr98 commented on July 17, 2024
PurchaseData

from pointshop2.

Comments (8)

pkmnmstr98 avatar pkmnmstr98 commented on July 17, 2024 2

It works perfectly!

from pointshop2.

ValentinFunk avatar ValentinFunk commented on July 17, 2024

It's updated instantly whenever something is changed inside the shop. What do you want to store in the purchasedata? In MySQL the purchasedata is just a JSON blob so you can put whatever you want in there. E.g.


KInventory.Item.findById( itemId ):Then( function( item )
  item.purchaseData.myExtraData = "test"
  return item:save()
end )

from pointshop2.

pkmnmstr98 avatar pkmnmstr98 commented on July 17, 2024

I wanted to add a LVL/EXP value to it. Also wanted to find someway to identify that item in specific in an inventory

from pointshop2.

pkmnmstr98 avatar pkmnmstr98 commented on July 17, 2024

@kamshak is there a way to update only that data client side?? Also, if i have the item equipped and then i move it back into inventory it removes the change i made to the item.

from pointshop2.

pkmnmstr98 avatar pkmnmstr98 commented on July 17, 2024

Here's the code im using

`
local Gitem = ply:PS2_GetItemInSlot("Hat")

KInventory.Item.findById(Gitem.id):Then(function(item)
item.purchaseData.effect = WEffect

return item:save()

end)
`

from pointshop2.

pkmnmstr98 avatar pkmnmstr98 commented on July 17, 2024

Doing this will keep it from changing if the player moves the item around.
KInventory.ITEMS[Gitem.id] = item

Still need to find a way to update it :/

from pointshop2.

ValentinFunk avatar ValentinFunk commented on July 17, 2024

If you're updating the item that is in an Inventory or slot it's important that you modify the item instance that PS2 uses, there is a global lookup table KInventory.ITEMS that you can use. If you need that data clientside after you'd need to manually network the change, you can use ITEM:ClientRPC for that, e.g.:

sh_purchase_data_update_mixin.lua

-- Extend base_item for purchase data updates
local PurchaseDataUpdateMixin = {}
function PurchaseDataUpdateMixin:included( klass )
    klass.static.AllowRPC("PurchaseDataUpdated")
end

if CLIENT then
  function PurchaseDataUpdateMixin:PurchaseDataUpdated(newData)
    self.purchaseData = newData
  end
end

if SERVER then
  function PurchaseDataUpdateMixin:UpdatePurchaseData(newData)
    self.purchaseData = newData
    return self:save( ):Then(function( )
      self:ClientRPC("PurchaseDataUpdated", newData)
    end)
  end
end

KInventory.RegisterItemClassMixin("base_pointshop_item", PurchaseDataUpdateMixin)

E.g.

local itemId = 12345

-- Get the item like this if you have the id but don't know if it's equipped or in inventory
local item = KInventory.ITEMS[12345]
-- if this is null you can use the db (KInventory.Item.findById)
-- you can also get the item from a slot or elsewhere, e.g.
-- local item = ply:PS2_GetItemInSlot("Hat")

local newPurchaseData = table.Copy(item.purchaseData)
newPurchaseData.effect = "test effect"
item:UpdatePurchaseData(newPurchaseData)

from pointshop2.

pkmnmstr98 avatar pkmnmstr98 commented on July 17, 2024

Awesome!!! Thank you for all the help!! @kamshak

from pointshop2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.