Embed DerpRP buyers into DarkRP

How would I embed these into the DarkRP gamemode so I don’t need an addons folder to use these?

I restructured the files so that they would sit well with darkrp.

http://www.mediafire.com/?r8iv1368pbvkfh1

You can extract that just how it is and then you only have to make this small edit to darkrp/gamemode/init.lua.

On line 84 add

[lua]include(“drpnpc.lua”)[/lua]

Thank you very much, your very kind and helpful.

One problem:
[gamemodes\darkrp\gamemode\drpnpc.lua:13] attempt to index global ‘buyers’ (a nil value)

Would you mind adding me to steam? I have one more tiny problem people looking like minges in certain classes.

Replace that file with the following.

[lua]AddCSLuaFile(“cl_drpnpc.lua”)
AddCSLuaFile(“drpnpcshared.lua”)
AddCSLuaFile(“colchat.lua”)

require(“glon”)

local npcs = {}

local function makenpc(ply, cmd, args)
local buyers = npcs
if !ply:IsSuperAdmin() then return end

local kind = args[1]
if buyers[kind] == nil then return end

local mdl = args[2] or "models/barney.mdl"
if UTIL_IsUselessModel( mdl ) then return end

local nam = args[3] or "John"

local ent = ents.Create("npc_buyer")
ent:SetPos(ply:GetEyeTraceNoCursor().HitPos + Vector(0,0,5))
local ihatepitch = ply:EyeAngles()
ihatepitch.p = 0 -- OWNED HAHA TAKE THAT USELESS ANGLE ATTRIBUTE
ent:SetAngles(ihatepitch)
ent.buytype = kind
ent.model = mdl
ent.name = nam
ent:Spawn()
ent:Activate()

table.insert(npcs, ent)

ply:ColChat("DrpNPC", Color(0,255,0), "Buyer succesfully created! Use drp_labpos " .. ent:EntIndex() .. " to set the label for this npc.")

end
concommand.Add(“drp_makebuyer”, makenpc)

local function saveall(ply,cmd,args)
if !ply:IsSuperAdmin() then return end

local data = {}
for k,v in pairs(npcs) do
	if v:GetDTVector(0) == Vector(0,0,0) then
		print("Skipped npc with model " .. v.model .. " because of missing label.")
	else
		table.insert(data, {mdl = v.model, pos = v:GetPos(), ang = v:GetAngles(), tipe = v.buytype, lpos = v:GetDTVector(0), lang = v:GetDTAngle(0), nam = v.name})
	end
end
local dir = "drpnpc/" .. game.GetMap() .. ".txt"
file.Write(dir, glon.encode(data))

end
concommand.Add(“drp_savenpcs”, saveall)

local function setlabpos(ply,cmd,args)
if !ply:IsSuperAdmin() then return end

local id = args[1]
local ent = Entity(id)

if IsValid(ent) and ent:GetClass() == "npc_buyer" then
	local tr = ply:GetEyeTrace()
	ent:SetDTVector(0, tr.HitPos + tr.HitNormal*2)
	ent:SetDTAngle(0, (tr.HitNormal):Angle())
end

end
concommand.Add(“drp_labpos”, setlabpos)

local function gravpickup( ply, ent )
ent.picker = ply
end
hook.Add(“GravGunOnPickedUp”, “setpicker”, gravpickup)

local function gravdrop(ply,ent)
if ent.picker then ent.picker = nil end
end
hook.Add( “GravGunOnDropped”, “removepicker”, gravdrop)

local function load()
local dir = “drpnpc/” … game.GetMap() … “.txt”
if file.Exists(dir) then
for k,v in pairs(glon.decode(file.Read(dir))) do
local ent = ents.Create(“npc_buyer”)
ent.model = v.mdl
ent:SetPos(v.pos)
ent:SetAngles(v.ang)
ent.buytype = v.tipe
ent.name = v.nam
ent:Spawn()
ent:Activate()

		table.insert(npcs, ent)
		
		ent:SetDTVector(0, v.lpos)
		ent:SetDTAngle(0, v.lang)
	end
end

end
hook.Add( “InitPostEntity”, “addstuff”, load)

local function latenoob(ply)
for k,v in pairs(ents.FindByClass(“npc_buyer”)) do
umsg.Start(“buyerinfo”, ply)
umsg.Short(v:EntIndex())
umsg.String(v.name)
umsg.String(v.buytype)
umsg.End()
end
end
hook.Add( “PlayerInitialSpawn”, “loser”, latenoob)[/lua]

I’m not certain, but it should work.

I don’t get any error now but no NPC spawns at all now.