• Can anyone recommend a good point"shop" tutorial?
    4 replies, posted
I've been searching for a couple days now and haven't found anything. I'm just looking to store the points server side for the player for only that one session and then be able to use those points on things(like medkits) but also have it connect with the amount of kills a player has. I was watching Code Blue's tutorial on a gamemode but he never got around to making the video about storing, receiving and giving points.
if you want to store point for one session you need to use lua tables for ex: hook.Add("PlayerInitialSpawn","ex",function(ply) ply.kills = 0 // initializing var end) hook.Add("PlayerDeath","ex",function(ply,inf,att) att.kills = att.kils + 1 // giving one point att:ChatPrint("you got 1 point for killing. You have :"..att.kills.." points") end) concommand.Add("medkit",function(ply,cmd,args) if !IsValid(ply) then return end // we dont need error if console use this if ply.kills < 10 then ply:ChatPrint("You need to do some kills ) ") return end ply:Give("weapon_medkit") // giving weapon ply.kills = 0 // set point to 0 end)
typo line 5 att.kils :c
I've figured this out already it's just using PData, NWInt. Both of which have plenty of tutorials on youtube; they just don't come up when you google anything like point shop or purchasable entity. local ply = player.GetAll() function ply:sv_PointSave(ply)     self:SetPData("Points",self:GetNWInt("Points")) end hook.Add("Think", "savePoints", sv_PointSave) function ply:sv_PlayerIntSpawn(ply)     ply.Points = 0     if (self:GetPData("Points") == nil ) then         self:SetPData("Points", tostring(ply.Points))         self:SetNWInt("Points", tostring(ply.Points))     else         self:SetNWInt("Points", self:GetPData("Points"))     end end hook.Add("PlayerInitialSpawn", "sv_PlayerIntSpawn", sv_PlayerIntSpawn) function GM:OnNPCKilled(npc, ply, inflictor)          ply:SetNWInt("Points", ply:GetNWInt("Points") + 100)     print(ply:GetNWInt("Points")) end Not the cleanest but does the trick. I just clear the person's points when they disconnect from the server and then set them when they connect. So it's like they're joining for the first time every time. May do this with a leveling system or something but idk yet.
Set up a table inside a shared lua file, something like PlayerItems, fill it with tables of which the keys are player ids(steamid or similar). Now create serversided functions such as BuyItem, SellItem, CheckCanBuy etc etc, make sure you perform all these comparisons and checks (especially price <= money etc) on the serverside, bind them to a console command if the player has to execute them and perform validity checks on everything. Assuming you can read wiki, bind a vgui menu to a GM:ShowSpare key and create buttons, use the DoClick method on these to perform the console commands. A nice way to transfer tables from server to client is by using util.TableToJSON(), then using the net library to send a string, and performing util.JSONToTable() on it again, this is more efficient than sending a table object through the net library. Always make sure the client can't perform commands if they don't have the required permissions or privileges, or if they are even valid entities for instance. And there you go, let me know if you need any help with the code but this is a good place to start.
Sorry, you need to Log In to post a reply to this thread.