Derma Item Purchasing System

I’ve managed to figure out net messages now but im still having problems. I still can’t get the buying function to work, i can’t tell if its PData or my net messages that aren’t working. I need some suggestions on how to set the players PData in when i click a derma button and then also check to see if the PData is true or false so i can use that on the derma panel. By the way i’am using a server now instead of singleplayer.

So, you are asking for help without showing us your code? You will not get good advice without your current code. Also, there are a lot of things to code for beginners, you should try something easier. :smile:

Here’s a small example:

if CLIENT then

    button.DoClick = function()

        net.Start( "buyweapon" ) --> Start the network string

        net.SendToServer() --> In this case, notifying the server that the button has been clicked.


elseif SERVER then

      util.AddNetworkString( "buyweapon" ) --> Creating the network string

      local price = 1000

      net.Receive( "buyweapon", function( len, ply ) --> Receive the message from the client

          if ply:canAfford( price ) then

              ply:addMoney( -price ) --> Taking the var 'price' and turning it into a negative, so that we can take the money from the player   

              ply:Give( "weapon_crossbow" )    --> Give the player a crossbow  


     end )


I’ve tried something similar to that but my problem is using PData to save the fact they bought it then grabbing the PData if its true or false for the client so i can disable the buy button.

[editline]10th March 2016[/editline]

My code doesnt work so i deleted it but i can post this which i believe was similar.

Client Side:

	equipKitButtonPS.DoClick = function()

		net.Start( "_PurchaseKit" )
			net.WriteInt( GlobalConInt, 5  )

Server Code:

util.AddNetworkString( "_PurchaseKit" )

net.Receive( "_PurchaseKit", function( len, ply )

	purchasedKit = net.ReadInt( 5 )

		if ply:PS_HasPoints( Kit[purchasedKit].price ) then
			ply:SetPData( "Owned" .. purchasedKit, true)
			ply:PS_TakePoints( Kit[purchasedKit].price )
			ply:ChatPrint( "You Bought the " .. Kit[purchasedKit].name )
			ply:ChatPrint( "You cannot afford this buy this kit!" )


That is what i have currently i tried sending if PData is true or false to the client but it didnt work.

How I would do it is use NWBools to send the data back and forth and then save it to pdata