• Can someone help me with storage and sell methods?
    20 replies, posted
I'm wanting to make it so that certain items when walked over get put into a player's darkrp inventory then they can walk up to a vendor and press "E" on them. All of the items that are compatible with that vendor are sold in one go (like meth buyer npc's). I know how to initiate Entities and how to make them interact with the player when they touch it. I've been researching for about an hour and a half and a couple of people have mentioned there are more efficient ways to store data so I don't know what the best way to store the data is first off. Second issue is all of the addons I've been able to find for free that work similarly - they've coded it so whatever item you're selling has to be out of your inventory first before you can sell it. I made a related post a couple hours ago talking about the "getPocketItem" DarkRP function, but I don't know how to use it. Can anyone point me in the right direction?
Efficient ways to store data? There are many ways to store data which are basically done the same way, which makes it debatable to say 'which is the best option'. The easiest way to store data in singular form would be PData, stores data to the sv.db. The second easiest way (to me), to store tables, would be file.Write, and util.TableToJSON, then file.Read and util.JSONToTable. The third option, which can confuse many Category SQL Another option is mysql, but you can search up how to do that.
When you say easiest way in single form what do you mean? I'm looking to have the npc retrieve the player's inventory information and if it matches specific items then the player can sell those items
Singular form is one input. Nothing else, just one input. Also, if the inventory is already setup just find out how to grab the inventory, and store it in a table? Then do a for loop to check if what you are looking for is in that table.
Kind of like this? hook.Add("KeyPress","JackaJobWeedSelling",function(ply,key)     if(key==IN_USE)then         local Tr=ply:GetEyeTraceNoCursor()         if((Tr.Hit)and(Tr.Entity.JackaJobNPCDealer)and((Tr.HitPos-ply:GetShootPos()):Length()<70))then             local Tab,Num=ply.darkRPPocket or {},0             for key,item in pairs(Tab)do                 if(item.Class=="ent_jack_job_weedbag")then                     local Bag=ply:dropPocketItem(key)                     if(Bag)then SafeRemoveEntity(Bag) end                     Num=Num+1                 end             end             if(Num>0)then                 local IllegallyGottenCash=Num*JackaJob_WeedSellPrice                 ply:addMoney(IllegallyGottenCash)                 local Path,Approval="vo/npc/male01/",{"nice.wav","fantastic01.wav","fantastic02.wav"}                 if(string.find(Tr.Entity:GetModel(),"female"))then                     Path="vo/npc/female01/"                     Approval={"nice01.wav","nice02.wav","fantastic01.wav","fantastic02.wav"}                 end                 Tr.Entity:EmitSound(Path..table.Random(Approval),65,100)                 timer.Simple(1.5,function() Tr.Entity:EmitSound(Path.."answer10.wav",60,100) end)                 timer.Simple(3.5,function() Tr.Entity:EmitSound(Path.."illstayhere01.wav",70,100) end)                 DarkRP.notify(ply,4,4,"Sold marijuana for $"..tostring(IllegallyGottenCash))             end         end     end end) I found this addon in the workshop spent a while looking through the lua and found it. I don't think it's exactly what I'm looking for (and seems pretty messy?) but is this basically what you're talking about?
Pretty much.
Slightly different question but still relevant to the table - I don't have much experience with tables (combined with darkrp) but, is there a way to remove specific entities from DarkRP pockets using the Class name? I tried net.Receive("myMessage", function()     PrintTable(player.GetByID(1):getPocketItems()) end) which obviously prints the class name and model, and I am planning to change "GetByID" to Steam64, but I don't know how to check for the class and then remove the item if it's a match. I have looked through the gmod library and found the Entity:GetClass() but I don't know how to use it for this purpose.
table.remove for k, v in pairs( ply:getPocketItems() ) do if v.Name == "sassauge" then local tab = ply:getPocketItems() table.Remove( tab, k ) ply:setPocketItems( tab ) end end idk how pocket items work, but thats the gist
tbh... I'm fed up with darkrp's pocket system at this point. I'm making a scavenger hunt type system. I'd like to make it so that the player just walks over the items scattered around the map that spawn at different locations at different times. My workaround for the pockets is, instead, just giving the player points - those points can then be exchanged for darkRP money. I was going to do PData like you suggested but I don't know how to do it so that it's compatible with DarkRP. And while yes I could just give the player DarkRP money when they find the scavenger items - I specifically want them to turn the points in to an NPC. Mostly as a way to get experience with GLua. If you could help me find a way around the darkrp pocket system I'd probably die of relief. Do you have a more direct way of messaging like through Discord or something? I plan to upload this to the workshop when it's done. The only thing I'm looking for here is experience and I'm willing to listen.
I've never seen darkrp code or worked with it but that code you posted should be able to do what you are trying to achieve if you modify it slightly. But you will also need to make your new vendor entity you will be pressing E on to sell items, and make new items that will be removed & inserted into your "pocket" once touched. This last two things you will have to figure out on your own. But if this script below doesn't at least guide you in some way, you might be a bit in over your head. Wall of text incoming if my code brackets don't work and no one can tell me how to wrap it lol. [lua] --This is the same as the other script, but you would need to figure out how to create a new vendor entity with a custom variable on initailize, and create new items that you are able to add to your "pocket", that also have 1 custom variable on initialize. -- ENT.ScavangerHuntVendor needs to be 'true' in your vendor entity you are pressing E(Use) on. -- ENT.Class needs to be "Valid_ScavangerHunt_Item" in your items you are picking up to be sold at your new vendor entity. -- ScavangerHunt_Item_Worth should be set to whatever you want each of these new items to be worth that you are trying to pick up and sell at the new vendor. ScavangerHunt_Item_Worth = 100 --You are setting a global variable here that tells your vendor script how much each scavanger hunt item is worth. hook.Add("KeyPress","ScavangerHuntSellScript",function(ply,key) --The "ScavangerHuntSellScript" is the name of your new hook you are creating. This hook runs every time the player presses their "use" key.     if(key==IN_USE)then --Player is pressing their "use" key. (Or E by default)         local Tr=ply:GetEyeTraceNoCursor() --Grab a trace of the players view.         if((Tr.Hit)and(Tr.Entity.ScavangerHuntVendor)and((Tr.HitPos-ply:GetShootPos()):Length()<70))then --The variable 'ScavangerHuntVendor' needs to be set to true in the vendor entity for code to continue. Also a valid entity must be within 70 units in front of players crosshair.             local Table, Num=ply.darkRPPocket or {},0 --You are setting two variables here. Table is a copy of your "pocket", and Num is how many valid scavanger hunt entities you have in your pocket that are about to be sold.             for key,item in pairs(Table)do --This is now looping through your pocket to pick out valid scavanger hunt entities, and remove them. (The code below is about to pay the player for all valid entities found & removed, once loop is complete.)                 if(item.Class=="Valid_ScavangerHunt_Item")then --The variable 'Class' needs to be set to "Valid_ScavangerHunt_Item" in the entity that is in your pocket.                     local Bag=ply:dropPocketItem(key) --I imagine this function is "dropping" the valid scavanger hunt entity out of your pocket, so it can be removed with the function below. (Because it is being "sold")                     if(Bag)then SafeRemoveEntity(Bag) end --I imagine, if the function above was allowed to drop the item out of your pocket, then this function is removing it from the world. (Because it is being "sold")                     Num=Num+1 --Make sure you count how many scavanger hunt items get sold once this loop is complete.                 end             end             if(Num>0)then --If you sell at least 1 item in the loop above, continue below to pay player for items.                 local CashFromItems = Num * ScavangerHunt_Item_Worth --Here you are taking the Num, which is the amount of items found and removed from your pocket in the loop above. And multiplying it by your global varaible of how much each scavanger hunt item is worth.                 ply:addMoney(CashFromItems) --This adds the actual money to the player for their items removed(sold) in the loop above.                 DarkRP.notify(ply,4,4,"Sold Scavanger Hunt Items for $"..tostring(CashFromItems)) --Notify the player, they have been paid for the scavanger hunt items that were currently just removed from their "pocket".                 --This stuff below just does audio effects from the vendor entity. If you are creating your own vendor entity, i would suggest just leave the sound code below commented out. It looks like it may use custom sound files that are meant for certain npc models.                 --[[                     local Path, Approval="vo/npc/male01/",{"nice.wav","fantastic01.wav","fantastic02.wav"} --There are multiple sound files for the model "male01". Here you are creating two variables, the 'Path' is the beginning path for those sound files. The 'Approval' is going to be the end half of that path that is randomly choosen below.                     if(string.find(Tr.Entity:GetModel(),"female"))then --If the vendor model is a "female", then use the female sound files instead of the male sound files set to your variables just above.                         Path="vo/npc/female01/" --New path to female sound files.                         Approval={"nice01.wav","nice02.wav","fantastic01.wav","fantastic02.wav"} --The end of the path for the 4 available female sound files starting with "vo/npc/female01/"                     end                     Tr.Entity:EmitSound(Path..table.Random(Approval),65,100) --This randomly picks the end of your sound file path and emits it from the entity immediately.                     timer.Simple(1.5,function() Tr.Entity:EmitSound(Path.."answer10.wav",60,100) end) --Emit a sound file 1.5 seconds after this first sound.                     timer.Simple(3.5,function() Tr.Entity:EmitSound(Path.."illstayhere01.wav",70,100) end)  --Emit a second sound file 3.5 seconds after the first sound that was emited.                 --]]             end         end     end end) [/lua]
to wrap lua code on the forum just highlight your code and press this button: https://imgur.com/QtlbblJ I do have the vendor here: https://imgur.com/gqa8Png I just need to figure out how to network the points to be exchanged for darkrp money and an efficient way to store multiple entities (scavenger props) with different prices. I am over my head currently because I've never done this before but I really want to. This would be my first community addon and it seems pretty simple for a lot of people. I'm going to quote your code and wrap it for reference: ScavangerHunt_Item_Worth = 100 --You are setting a global variable here that tells your vendor script how much each scavanger hunt item is worth. hook.Add("KeyPress","ScavangerHuntSellScript",function(ply,key) --The "ScavangerHuntSellScript" is the name of your new hook you are creating. This hook runs every time the player presses their "use" key. if(key==IN_USE)then --Player is pressing their "use" key. (Or E by default) local Tr=ply:GetEyeTraceNoCursor() --Grab a trace of the players view. if((Tr.Hit)and(Tr.Entity.ScavangerHuntVendor)and((Tr.HitPos-ply:GetShootPos()):Length()<70))then --The variable 'ScavangerHuntVendor' needs to be set to true in the vendor entity for code to continue. Also a valid entity must be within 70 units in front of players crosshair. local Table, Num=ply.darkRPPocket or {},0 --You are setting two variables here. Table is a copy of your "pocket", and Num is how many valid scavanger hunt entities you have in your pocket that are about to be sold. for key,item in pairs(Table)do --This is now looping through your pocket to pick out valid scavanger hunt entities, and remove them. (The code below is about to pay the player for all valid entities found & removed, once loop is complete.) if(item.Class=="Valid_ScavangerHunt_Item")then --The variable 'Class' needs to be set to "Valid_ScavangerHunt_Item" in the entity that is in your pocket. local Bag=ply:dropPocketItem(key) --I imagine this function is "dropping" the valid scavanger hunt entity out of your pocket, so it can be removed with the function below. (Because it is being "sold") if(Bag)then SafeRemoveEntity(Bag) end --I imagine, if the function above was allowed to drop the item out of your pocket, then this function is removing it from the world. (Because it is being "sold") Num=Num+1 --Make sure you count how many scavanger hunt items get sold once this loop is complete. end end if(Num>0)then --If you sell at least 1 item in the loop above, continue below to pay player for items. local CashFromItems = Num * ScavangerHunt_Item_Worth --Here you are taking the Num, which is the amount of items found and removed from your pocket in the loop above. And multiplying it by your global varaible of how much each scavanger hunt item is worth. ply:addMoney(CashFromItems) --This adds the actual money to the player for their items removed(sold) in the loop above. DarkRP.notify(ply,4,4,"Sold Scavanger Hunt Items for $"..tostring(CashFromItems)) --Notify the player, they have been paid for the scavanger hunt items that were currently just removed from their "pocket". --This stuff below just does audio effects from the vendor entity. If you are creating your own vendor entity, i would suggest just leave the sound code below commented out. It looks like it may use custom sound files that are meant for certain npc models. --[[ local Path, Approval="vo/npc/male01/",{"nice.wav","fantastic01.wav","fantastic02.wav"} --There are multiple sound files for the model "male01". Here you are creating two variables, the 'Path' is the beginning path for those sound files. The 'Approval' is going to be the end half of that path that is randomly choosen below. if(string.find(Tr.Entity:GetModel(),"female"))then --If the vendor model is a "female", then use the female sound files instead of the male sound files set to your variables just above. Path="vo/npc/female01/" --New path to female sound files. Approval={"nice01.wav","nice02.wav","fantastic01.wav","fantastic02.wav"} --The end of the path for the 4 available female sound files starting with "vo/npc/female01/" end Tr.Entity:EmitSound(Path..table.Random(Approval),65,100) --This randomly picks the end of your sound file path and emits it from the entity immediately. timer.Simple(1.5,function() Tr.Entity:EmitSound(Path.."answer10.wav",60,100) end) --Emit a sound file 1.5 seconds after this first sound. timer.Simple(3.5,function() Tr.Entity:EmitSound(Path.."illstayhere01.wav",70,100) end) --Emit a second sound file 3.5 seconds after the first sound that was emited. --]] end end end end)
I edited a few things, so I would use the code in my original post as a reference. I think the commented code in the already --[[ --]] comment block will throw errors, so that is what I edited.
Alright thank you for your help that will make understanding the function of it all easier to understand. A friend of mine mentioned networking entities but I can't seem to find any good tutorials on the subject. I know how to network points but not entities.
Setting specific price per ent, you would need to add a price variable to each entity. Then in your loop, instead of simple counting up with the Num variable. Pull the entities worth varaible currently being processed in loop the loop and add to your Num variable. (Num = Num + item.WorthVariable)
is there a way to create all entities in one lua file? I don't want to make a bunch of folders and cl, sh, sv files if i don't have to, ya know?
Look up a tutorial on creating custom entities in gmod if you are unfamiliar with creating entities.
I have the entity and the vendor I just need to connect everything. But I've never done that so that's why I'm here
That script i just gave you does exactly that. You may need to put in some hours of testing and diagnosing to learn and get it working or find someone to do it for you honestly.
I will definitely try what you've suggested I'm just spent at this point but figured I'd give more context
I've never created an entity/item class before so I ended up doing this (from the gmod library ENT Structure): function ENT:ClassName("coin_pickup")     self:Valid_ScavangerHunt_Item() end which resulted with this [ERROR] addons/adv_entity/lua/entities/coin_pickup/init.lua:28: <name> or '...' expected near '"coin_pickup"'   1. unknown - addons/adv_entity/lua/entities/coin_pickup/init.lua:0 The code, was of course, put into the Entity's init file.
Entity init: https://pastebin.com/3824b8iM Vendor init: https://pastebin.com/HYZkLWkM there's the current file state. Current issue is that at Vendor line (42) @ "print("fk1")" the script stops running preventing the entity from being dropped out of the pocket and exchanged for DarkRP money
Sorry, you need to Log In to post a reply to this thread.