1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Sign up for news, events and more!

    You're currently visiting the official DarkRP Forums as a guest. Sign up now to participate in our community and we'll let you know when we have news.

Purchased Entities to Spawn as Owned Instead of World.

Discussion in 'DarkRP Modding Questions & Help' started by Miko, Mar 7, 2016.

  1. Miko

    Miko New Member

    Hey guys,

    So I have a few entities that players can buy from the f4 menu (Media Player, Piano, and Pool Table). However, when they are bought, they spawn as world entities. I've searched around (hopefully well enough I didn't miss the solution) , and tried a few things but it was pretty inconclusive so far.

    Essentially I want users to be able to pick them up with their phys gun, as well as have full control over them ( In the case of the media player, skipping. pausing and scrubbing) . I feel like its probably a easy solution, im just stupidly overlooking something.

    So I have decided to turn to you guys, to see if you know of a solution for this? I appreciate any help!

    Thanks.
    --- Double Post Merged, Mar 8, 2016 ---
    Welp, solved my own issue.

    Here is the solution!

    Create a new file in your editor of choice.
    Code (Text):

    local entTable = { ["mediaplayer_tv"] = true,
                     ["gmt_instrument_piano"] = true,
                    ["circl_printer_amazing_one"] = false
    }

    hook.Add("playerBoughtCustomEntity", "SetOwnerOnEntBuy", function(ply, enttbl, ent, price)



        if entTable[ent:GetClass()] then          --Check table of entities
        ent:CPPISetOwner(ply)
        end

           

    end)

     
    Save this as setentityowner.lua
    upload to your lua/autorun/server/ folder
     
    Last edited: Mar 23, 2016
    Sir Kstanker likes this.
  2. ✯B3N | The Nexus

    ✯B3N | The Nexus New Member

    this doesn't work for me. is it because im spawning it from a vendor? if so should i be putting the code somewhere else?
     
  3. Sir Klutch

    Sir Klutch Active Member

    I do believe boughtcustomentity is only ran when an item is purchased from the f4 menu. Unless, of course, your vendor runs said hook for item purchases which you might need a timer or simply find the code that takes your money then spawns the entity and right after the entity is spawned set the owner with; CPPISetOwner()
     
  4. Sorry to bump this after like, a year and half, but it isn't working for me, I put the code in, changed the entities, and it still isn't working, I put it in
    C:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod\lua\autorun\server

    local entTable = { ["mediaplayer_tv"] = true,
    ["better_shipment"] = true
    ["st_bread_oven"] = true
    ["st_bitminer1"] = true
    ["st_bitminer2"] = true
    ["st_bitminer3"] = true
    ["st_bitminer4"] = true
    ["st_bitminer5"] = true
    ["st_bitminer6"] = true
    ["st_c_microwave"] = true
    ["stnarc_chem_lab"] = true
    ["spawned_shipment"] = true
    }

    hook.Add("playerBoughtCustomEntity", "SetOwnerOnEntBuy", function(ply, enttbl, ent, price)



    if entTable[ent:GetClass()] then --Check table of entities
    ent:CPPISetOwner(ply)
    end



    end)
     

Share This Page