• Pricing System
    6 replies, posted
First off I just want to pre-requisite this by saying I feel really silly asking this question but I've looked and I can't find an answer and don't know how to do it or what to search... So! I just need someone to explain to me how I can link a table of entities with prices to something like an addMoney system. Here's a sample of what I have, plz be nice: ScavangerHunt_Item_Worth = { ScavangerHunt_Common = 10000, ScavangerHunt_Uncommon = 50000, ScavangerHunt_Rare_Item = 100000, ScavangerHunt_Mythic_Item = 150000, ScavangerHunt_Universal_Item = 1000000 } for k, v in pairs(ScavangerHunt_Item_Worth) do ply:addMoney I plan to have multiple entities with the names in the table but I don't know how to give the player money based on the table contents or if what I have is even correct. Again I know it's silly but I legitimately couldn't find specific information on how to do this.
example from an old gamemode i worked on with some friends, you're going to want to use net messages to and from the server to handle buying cl_init.lua weapon table local Weapon = {     { NAME = "weapon_stunstick", ALIAS = "Stunstick", MODEL = "models/weapons/w_stunbaton.mdl", COST = 300, AMMO = 0 },     { NAME = "weapon_357", TYPE = "357", ALIAS = "Magnum", MODEL = "models/weapons/w_357.mdl", COST = 950, AMMO = 32 },     { NAME = "weapon_smg1", TYPE = "SMG1", ALIAS = "Sub Machine Gun", MODEL = "models/weapons/w_smg1.mdl", COST = 1000, AMMO = 90 },     { NAME = "weapon_ar2", TYPE = "AR2", ALIAS = "I-Rifle", MODEL = "models/weapons/w_irifle.mdl", COST = 1600, AMMO = 100 },     { NAME = "weapon_crossbow", TYPE = "XbowBolt", ALIAS = "Crossbow", MODEL = "models/weapons/w_crossbow.mdl", COST = 1200, AMMO = 32 },     { NAME = "weapon_shotgun", TYPE = "Buckshot", ALIAS = "Shotgun", MODEL = "models/weapons/w_shotgun.mdl", COST = 1800, AMMO = 64 },     { NAME = "weapon_frag", TYPE = "Grenade", ALIAS = "Grenade/Frag", MODEL = "models/weapons/w_frag.mdl", COST = 800, AMMO = 3 },     { NAME = "weapon_slam", TYPE = "slam", ALIAS = "Slam", MODEL = "models/weapons/w_slam.mdl", COST = 1250, AMMO = 3 }, } cl_init.lua send buy request for i, v in pairs( Weapon ) do     local item = vgui.Create( "SpawnIcon", PanelOne )     item:SetModel( tostring(v.MODEL) )     PanelOne:AddItem( item )          item:SetToolTip(v.ALIAS.."\nPurchase for $"..v.COST)          item.DoClick=function()         net.Start( "buy" )         net.WriteTable(Weapon[i])         net.SendToServer()     end          end init.lua (server) receive and handle buy request util.AddNetworkString( "buy" ) net.Receive( "buy", function(len, ply)     v = net.ReadTable()     if ply:GetNWInt( "Money" ) < v.COST then ply:ChatPrint("You don't have enough money!") return end     ply:Give(v.NAME)     ply:AddMoney(-v.COST)     ply:GiveAmmo(v.AMMO, v.TYPE, false) end ) init.lua (server) PlayerInitialSpawn function GM:PlayerInitialSpawn( ply )     local cash = ply:GetPData("money")     if tonumber(cash) == nil then         ply:SetPData("money", MONEY_STARTAMOUNT)         ply:SetMoney( MONEY_STARTAMOUNT )     else         ply:SetMoney(tonumber(cash))     end end
Luckily I don't have to worry about networking really I'm just explicitly selling them. Thought your table still gave me a bit of insight
pretty sure selling them is still going to need some networking
Not on my end! ;D DarkRP and the server I'm making the addon for (I'll be adding it to the workshop with credits when I'm done), already handles the networking. All I'm doing is borrowing the function that adds money! Very happy I don't need to network for this one.
Should give you an idea ScavengerHunt_ItemWorth = { Common = 10000, Uncommon = 25000, Rare = 50000, Mythic = 10000, Universal = 50000 } ScanverHunt_Items = { { Name = "AK-47", Rarity = "Common", EntClass = "weapon_ak47", model = "ak47.mdl"} } for i, v in pairs(ScavengerHunt_Items) do -- i is the key [1, 2, 3, because this is a numerical table] -- v is the value which in our case is the table we define each item in local name = v.Name local rarity = v.Rarity local entClass = v.EntClass local model = v.Model -- Now look up the cost by indexing the ItemWorth table with the rarity from our item local cost = ScavengerHunt_ItemWorth[rarity] end
Alright well I got the thing to sell only issue is that I don't know how to only sell it for the one item in the table that's being sold. Since it's running the loop and I don't know how to make it choose an item from the table it just gives me all the cash. local ScavangerHunt_Items = { {SIName = "ScavangerHunt_Common_Item", SISellPrice = 10000}, {SIName = "ScavangerHunt_Uncommon_Item", SISellPrice = 50000}, {SIName = "ScavangerHunt_Mythic_Item", SISellPrice = 150000}, {SIName = "ScavangerHunt_Universal_Item", SISellPrice = 1000000}, } local ply = player.GetByID(1)             local Table, Num=ply.darkRPPocket or {},0             for key,item in pairs(Table)do                 if(item.Class=="coin_pickup")then --name of entity being sold "coin_pickup"                     local Bag=ply:dropPocketItem(key)                     if(Bag)then SafeRemoveEntity(Bag) end                     Num=Num+1                 end             end             if(Num>0)then                 for k, v in pairs(ScavangerHunt_Items) do --Not sure how to do the check here          ply:addMoney(v.SISellPrice)                 DarkRP.notify(ply,4,4,"Sold Scavanger Hunt Items for $"..tostring(v.SISellPrice)         end     end end)
Sorry, you need to Log In to post a reply to this thread.