Help spawning an entity and deducting money (DarkRP)

Hi facepunch.

I have this code and im not sure how to make it spawn a entiyy with the models in the table, as you can see i want it so when the player presses one of the buttons it spawns that entity in front of them and deducts a certain amount of money from them (If you can help me just default all costs to 800).

[lua]function shop() – shop by Infinity1995
local drugs = {}

drugs[1] = "models/katharsmodels/contraband/zak_wiet/zak_wiet.mdl"
drugs[2] = "models/katharsmodels/syringe_out/syringe_out.mdl"
drugs[3] = "models/cocn.mdl"
drugs[4] = "models/drug_od/the_bottle_of_water.mdl"
drugs[5] = "models/ipha/mushroom_small.mdl"
drugs[6] = "models/boxopencigshib.mdl"
drugs[7] = "models/smile/smile.mdl"
drugs[8] = "models/jaanus/aspbtl.mdl"

    local frame = vgui.Create("DFrame")
local IconList = vgui.Create( "DPanelList", frame ) 

frame:Center()
frame:SetSize(220,200)
frame:SetTitle("Npc Shop")
frame:MakePopup()

IconList:EnableVerticalScrollbar( true ) 
IconList:EnableHorizontal( true ) 
IconList:SetPadding( 4 ) 
IconList:SetPos(10,30)
IconList:SetSize(200, 160)

for k,v in pairs(drugs) do
local icon = vgui.Create( "SpawnIcon", IconList ) 
icon:SetModel( v )
IconList:AddItem( icon )
icon.DoClick = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand("gm_spawn", v) end 
end 

concommand.Add( "npcshop1", shop )

end
[/lua]

Also, please dont steal this code

Thank you in advance.

[editline]10:15AM[/editline]

From what i see i must edit:


RunConsoleCommand("gm_spawn", v)

To make it spawn a entity instead of a model.

Anyone?

Why don’t you just add them in the shared.lua?

Because i want a npc to spawn them! in the shared.lua is boring, why the hell did you even post?

oh lol that would be cool i need something like this for rp

[editline]01:05PM[/editline]

and i dont no much but you dont have nothing about spawning?

That is at the moment spawning a model, not a entity:


RunConsoleCommand("gm_spawn", v)

[editline]02:18PM[/editline]

I need someone to change it to spawn a entity

[LUA]
–Use somefin like this?
local drug = ents.Create(“a_prop”)
drug:SetModel(“models/drug.mdl”)
drug:SetKeyValue(“dunnowhat”,“scripts/drug/drug.txt”) – dunno a drug thing
drug:SetPos( player:GetPos() + Vector(0, 0, 64 )); – Spawns on head
drug:SetOwner(Player)
drug:Spawn()
end;
[/LUA]

[editline]01:31PM[/editline]

thats what i use to make a car etc and where i said “dunnowhat” u need a script thing

A client can’t spawn an entity. (clientside models excluded)

You need to make something on the server(like bradmcco said)
put it in a function, make a command and run that command on the client.

[lua]
function SpawnDrugs(ply, cmd, args)
–Use somefin like this?
local drug = ents.Create(“drug”) --where drug is the name of the entity
drug:SetModel(args[1]) --note the first argument must be valid
//drug:SetKeyValue(“dunnowhat”,“scripts/drug/drug.txt”) – BRADMCCO WHAT ARE YOU DOING HERE?
//drug:SetPos( ply:GetPos() + Vector(0, 0, 64 )); – Spawns on head, or in the ceiling ._.
drug:SetPos(ply:GetEyeTrace().HitPos + Vector(0,0,50))-- that’s a bit better, spawns where you’re looking at
//drug:SetOwner(Player) --Does this function even exist?
drug:Spawn()
end
concommand.Add(“SpawnDrugs”, SpawnDrugs)[/lua]
ON THE SERVER!

Then instead of RunConsoleCommand(“gm_spawn”, v) you do
RunConsoleCommand(“SpawnDrugs”, v)

That helps but they are all different entitys for different models

[editline]04:05PM[/editline]

oK falco, if i done this


drugs[1] = "models/katharsmodels/contraband/zak_wiet/zak_wiet.mdl" , "drug_needle" , "700"  

to each of the things in the table could you change it so for each model its the different entity thats next to it in the table, then it takes the last number away from your darkrp cash

Theres a problem the npc stands like the famous mingebag with arms out and the console command dosent work

Infinity did you make it a npc like when you press E on it brings up a vgui?

Yea, it’s a entity with a citizen model

How did you do that i need it for my server :stuck_out_tongue:
so you did ents.Create(“whatpropdiduput?”)
and then set the model lol

When I finish it I’m going to release it, so go away asking for the script

lol ok