• One time purchase help
    25 replies, posted
So for my police armory i wanna make it where you can only buy armor 1 time in your life, so you spawn as a police officer go to the armory and you buy armor, but you go outside take damage you go back inside you cant buy armor until you die.
Do something like ply.BoughtArmor = true and check before the player tries to buy armor if ply.BoughtArmor is not nil (or true). If it's not nil (or true) dont give the player armor.
I actually finished mine yesterday. And I did it like this; ENT:Initialize() <variable> = 0 end And then you can set that variable to 1 when the player takes a weapon from the armory. net.Receive(“your net message string”,function (len,ply) if<variable> < 1 then ply:Give(net:ReadString()) else DarkRPnotify end end)
ok so im getting an error, before we start the one time purchase if anyone can help so when i buy it, it wont give me the armor that is inside the config for amount so in my config i have ["90 Armor"] = {price = 1000, amount = 90}, then in my server for armor i have net.Receive("GivePoliceArmor", function(len,pl) local armor = net.ReadUInt(16) local money = ArmorList[armor].price if pl:canAfford(money) then local arm = pl:SetArmor(pl:Armor() + amount ) pl:addMoney(-money) pl:EmitSound("items/itempickup.wav") pl:ChatPrint("[Police Armory] You bought - "..armor) arm.GivenByCP = true else pl:ChatPrint("[Police Armory] Not enough money!") pl:EmitSound("buttons/blip1.wav") end end) like i have been working on this for 3 days and i cant just figure it out tbh then when i click buy armor on it, it does not give me armor and it does not take away money either then it gives me this error https://i.imgur.com/Y7S4xik.png and line 80 inside init is https://i.imgur.com/E6SDQRl.png just confused my brain is like a jigsaw puzzle rn like deadass
why not just use the net library to assign a value to the player that has purchased it like SetNWBool("hasPurchasedArmor",false) GetNWBool()
To be honest why does it need to be networked to the client? This value really only needs to be known by the server, so when they purchase armor just apply the variable to that specific player object. ply.hasPurchasedArmor = true Then if they try to purchase it again you just take that and print to their chat like you're doing that "Hey, you've already purchased armor! You can't do this again!". In your situtation it doesn't look like the client always needs to know if they've purchased armor cause they'll already know, especially if you're already setting their armor.
I'm still relatively new with Lua and learning - when I had tried to do that before it would save for everybody.. So I take it if you do ply.variableName = blahblah saves to that specific player?
so how do i fix my problem?
Yes, provided your player object is the right player - it will save it to that specific person. Since Lua is so forgiving and lets you set a variable to literally any type it works for pretty much anything (tables, integers, strings, etc.). Then you can always access that based on the scope.
yall are talking about something way different? ok so im getting an error, before we start the one time purchase if anyone can help so when i buy it, it wont give me the armor that is inside the config for amount so in my config i have ["90 Armor"] = {price = 1000, amount = 90}, then in my server for armor i have net.Receive("GivePoliceArmor", function(len,pl) local armor = net.ReadUInt(16) local money = ArmorList[armor].price if pl:canAfford(money) then local arm = pl:SetArmor(pl:Armor() + amount ) pl:addMoney(-money) pl:EmitSound("items/itempickup.wav") pl:ChatPrint("[Police Armory] You bought - "..armor) arm.GivenByCP = true else pl:ChatPrint("[Police Armory] Not enough money!") pl:EmitSound("buttons/blip1.wav") end end) like i have been working on this for 3 days and i cant just figure it out tbh then when i click buy armor on it, it does not give me armor and it does not take away money either then it gives me this error https://i.imgur.com/Y7S4xik.png and line 80 inside init is https://i.imgur.com/E6SDQRl.png just confused my brain is like a jigsaw puzzle rn like deadass Edit: but it doesnt give me an error about giving me armor Edit: My client side for armoris function buyarmor:DoClick() local buy = 3 if armor:GetSelectedLine() then local selectedline = armor:GetLine(armor:GetSelectedLine()):GetValue(1) if ArmorList[selectedline] then net.Start("GivePoliceArmor") net.WriteUInt( buy,16 ) net.WriteString(selectedline) net.SendToServer() end end and this is what im talking about
It's not different he explained a better way to do it and I asked for clarification.. and as far as your error it's saying that line 80 is returning a nil which means nothing.. So I would go back and check my table or how ever you're passing this information and check it's sending the information.. To debug I'll add a ton of prints if I get lost to figure out where the connection is being lost.. make it print out all of your data before it's sent and make sure it's not a nil.
bro i been doing prints and everything else my brain is just confused af and dont know how to fix it
Well the only way you're going to learn is by breaking it apart. Do this - start over. With what I said, I'll give you a few hints. When you purchase the armor, in that function apply the variable to the player hasPurchasedArmor and set it to true. In that same function check to see if that variable is true, and if it is then don't let them purchase the armor. Using the OnPlayerDeath hook you will want to then set that value to false, so they can buy it again next life.
ply.hasPurchasedArmor = true is this even a thing ^ like im trying to help him with this rn and you want him to start over he been trying to do this for 3-4 days, he has rn btw im the person that is helping him doing this rn well you can say im his irl brother server side function ENT:Initialize() self:SetModel("models/props_c17/Lockers001a.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) self:SetUseType(SIMPLE_USE) end function ENT:Use(pl) if pl:isCP() then net.Start( "PoliceArmory" ) net.Send(pl) else pl:ChatPrint("[Police Armory] Sorry This is for the government only!") end end net.Receive("GivePoliceWeapon", function(len,pl) local weapon = net.ReadString() if WeaponList[weapon] and pl:isCP() then local wepclass = WeaponList[weapon].class local money = WeaponList[weapon].price if pl:HasWeapon(wepclass) then pl:ChatPrint("You already have this weapon!") pl:EmitSound("buttons/blip1.wav") return end if pl:canAfford(money) then local wep = pl:Give(wepclass) pl:addMoney(-money) pl:EmitSound("items/itempickup.wav") pl:ChatPrint("[Police Armory] You bought - "..weapon) wep.GivenByCP = true else pl:ChatPrint("[Police Armory] Not enough money!") pl:EmitSound("buttons/blip1.wav") end end end) net.Receive("GivePoliceArmor", function(len,pl) local armor = net.ReadUInt(16) local money = ArmorList[armor].price local amount = ArmorList[armor].amount if pl:canAfford(money) then local arm = pl:SetArmor(pl:Armor() + amount ) pl:addMoney(-money) pl:EmitSound("items/itempickup.wav") pl:ChatPrint("[Police Armory] You bought - "..armor) arm.GivenByCP = true else pl:ChatPrint("[Police Armory] Not enough money!") pl:EmitSound("buttons/blip1.wav") end end) client side for armor local buyarmor = vgui.Create( "DButton", frame ) buyarmor:SetText( "Buy Armor" ) buyarmor:SetTextColor(Color(255,255,255,255)) buyarmor:SetFont("buytext") buyarmor:SetPos( 230, 605 ) buyarmor:SetSize( 164, 30 ) buyarmor.Paint = function (self) draw.RoundedBox( 0, 0, 0,self:GetWide(),self:GetTall(),EssConfig.BuyWeaponBackground) end function buyarmor:DoClick() local buy = 3 if armor:GetSelectedLine() then local selectedline = armor:GetLine(armor:GetSelectedLine()):GetValue(1) if ArmorList[selectedline] then net.Start("GivePoliceArmor") net.WriteUInt( buy,16 ) net.WriteString(selectedline) net.SendToServer() end end end for k,v in pairs(ArmorList) do armor:AddLine(k,v.price, v.amount) end
Yes... It is in fact a thing. I'm not going to hold his hand. I've given him the tools he needs.
how isthat holding his hand?
If he doesn't understand some basic things such as variables and doing if checks, I recommend he goes and looks at some tutorials.
ok so we have changed up the code alittle so inside the server side we have net.Receive("GivePoliceWeapon", function(len,pl) local Armor = net.ReadUInt(16) if ArmorList[armor] and pl:isCP() then local armclass = ArmorList[armor].class local money = ArmorList[armor].price if pl:canAfford(money) then if activator:getDarkRPVar( "money" ) > price then if activator:Armor() > amount - 1 then DarkRP.notify(activator, 1, 5, "Armor is full") elseif activator:Armor() < amount then activator:SetArmor(amount) DarkRP.notify(activator, 2, 5, "Armor Set to "..amount.."%") activator:addMoney(-price) DarkRP.notify(activator, 2, 5, "Removed $"..price.." from your wallet") end end end) and inside client we have buyarmor:SetText( "Buy Armor" ) buyarmor:SetTextColor(Color(255,255,255,255)) buyarmor:SetFont("buytext") buyarmor:SetPos( 230, 605 ) buyarmor:SetSize( 164, 30 ) buyarmor.Paint = function (self) draw.RoundedBox( 0, 0, 0,self:GetWide(),self:GetTall(),EssConfig.BuyWeaponBackground) end function buyarmor:DoClick() local ass = 3 if armor:GetSelectedLine() then local selectedline = armor:GetLine(armor:GetSelectedLine()):GetValue(1) if ArmorList[selectedline] then net.Start("GivePoliceArmor") net.WriteUInt( ass,16 ) net.WriteString(selectedline) net.SendToServer() end end end for k,v in pairs(ArmorList) do armor:AddLine(k,v.price, v.amount) end
Are you sure line 79 isn't one of these? if activator:getDarkRPVar( "money" ) > price then if activator:Armor() > amount - 1 then The error message only makes sense for > or <.
nah look AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) inc..
If you want help I can help you once I'm off work in about an hour so paste the code into a paste bin and I'll load it up and see if I can figure out why it's not passing the variable.. I know you posted in another section about this saying you didn't want somebody to steal this - but you're making this 100 times harder by just posting a single line or small chunk saying nobody is helping and your brain hurts.
client server shared
You forgot the config file.
config
I've fixed it for you it's more than I want to type about - it was really just dumb simple syntax errors that you had to follow back and resolve them a lot of functions just not ended properly and such or random symbols... Add me on steam StankyFrank311 and I will go over the files with you.
adding right now!
Sorry, you need to Log In to post a reply to this thread.