1. Post #1
    Infinity1995's Avatar
    August 2009
    959 Posts
    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).

    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
     

    Also, please dont steal this code

    Thank you in advance.

    Edited:

    From what i see i must edit:

    Code:
    RunConsoleCommand("gm_spawn", v)
    To make it spawn a entity instead of a model.

  2. Post #2
    Infinity1995's Avatar
    August 2009
    959 Posts
    Anyone?

  3. Post #3

    February 2009
    305 Posts
    Why don't you just add them in the shared.lua?

  4. Post #4
    Infinity1995's Avatar
    August 2009
    959 Posts
    Because i want a npc to spawn them! in the shared.lua is boring, why the hell did you even post?

  5. Post #5

    February 2009
    305 Posts
    oh lol that would be cool i need something like this for rp

    Edited:

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

  6. Post #6
    Infinity1995's Avatar
    August 2009
    959 Posts
    That is at the moment spawning a model, not a entity:

    Code:
    RunConsoleCommand("gm_spawn", v)
    Edited:

    I need someone to change it to spawn a entity

  7. Post #7

    February 2009
    305 Posts
    --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;
    

    Edited:

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

  8. Post #8
    Get your own DarkRP Server!
    FPtje's Avatar
    January 2006
    5,613 Posts
    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.

    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)
    ON THE SERVER!


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

  9. Post #9
    Infinity1995's Avatar
    August 2009
    959 Posts
    That helps but they are all different entitys for different models

    Edited:

    oK falco, if i done this

    Code:
    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

  10. Post #10
    Infinity1995's Avatar
    August 2009
    959 Posts
    Theres a problem the npc stands like the famous mingebag with arms out and the console command dosent work

  11. Post #11

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

  12. Post #12
    Infinity1995's Avatar
    August 2009
    959 Posts
    Yea, it's a entity with a citizen model

  13. Post #13

    February 2009
    305 Posts
    How did you do that i need it for my server :P
    so you did ents.Create("whatpropdiduput?")
    and then set the model lol

  14. Post #14
    Infinity1995's Avatar
    August 2009
    959 Posts
    When I finish it I'm going to release it, so go away asking for the script

  15. Post #15

    February 2009
    305 Posts
    lol ok