Hi all,
Looking for a simple NPC addon for darkrp I can set a location for where players can "E" on the NPC and that will open up PoinstShop.
I have seen a few on here via search, but all links are broken or files outdated. I have tried looking into NPC creation tutorials but everything ends up being to spawn massive amounts of NPC's.
Well I got a working solution, all thanks to: [url]http://coderhire.com/users/view/2082[/url]
For anyone searching the internet to find this, I hope this helps:
1. Make a folder in [B]gamemodes/darkrp/entities/entities[/B] called [B]npc_pointshop[/B]
2. Create the 3 .lua files below and copy the code in.
3. If you're using rp_evilmelon_v1 then it's already got a custom setpos location for this outside police station.
If you want your own location, stand and face where you want it, type [B]setpos[/B] in the console and note the coordinates in console, add this to the shared.luz file like this:
(NOTE: must have commas between coordinates!)
[code]
npc_SpawnPositions = {
["rp_map_name_here_NO .bsp needed!"] = {
{pos = Vector([B]-1301, -304, -81[/B]), ang = Angle([B]0, 0, 0[/B])},
},
}
[/code]
[B]cl_init.lua[/B]
[code]
include('shared.lua')
hook.Add("PostDrawOpaqueRenderables", "ps_npc", function()
for _, ent in pairs (ents.FindByClass("npc_pointshop")) do
if ent:GetPos():Distance(LocalPlayer():GetPos()) < 1000 then
local Ang = ent:GetAngles()
Ang:RotateAroundAxis( Ang:Forward(), 90)
Ang:RotateAroundAxis( Ang:Right(), -90)
cam.Start3D2D(ent:GetPos()+ent:GetUp()*80, Ang, 0.35)
draw.SimpleTextOutlined( 'Pointshop', "HUDNumber5", 0, 0, Color( 0, 150, 255, 255 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 1, Color(0, 0, 0, 255))
cam.End3D2D()
end
end
end)
hook.Add("HUDPaint", "openpointshop", function()
local tr = LocalPlayer():GetEyeTrace()
if (!IsValid(tr.Entity) or tr.Entity:GetClass() != "npc_pointshop") then return end
if (tr.HitPos:Distance(LocalPlayer():GetPos()) > 128) then return end
draw.SimpleTextOutlined("Pointshop!", "DarkRPHUD1", ScrW() * 0.5, ScrH() * 0.6, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, color_black)
end)
[/code]
[B]init.lua[/B]
[code]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize( )
self:SetModel( "models/humans/group01/female_01.mdl" )
self:SetHullType( HULL_HUMAN )
self:SetHullSizeNormal( )
self:SetNPCState( NPC_STATE_SCRIPT )
self:SetSolid( SOLID_BBOX )
self:CapabilitiesAdd( CAP_ANIMATEDFACE )
self:SetUseType( SIMPLE_USE )
self:DropToFloor()
self:SetMaxYawSpeed( 90 )
end
function ENT:OnTakeDamage()
return false
end
function ENT:AcceptInput( name, act, ply )
if !ply then return end
if name == "Use" and ply:IsPlayer() then
ply:PS_ToggleMenu()
end
end
hook.Add("InitPostEntity", "createnpc", function()
if (!npc_SpawnPositions[game.GetMap()]) then
print("PS NPC not setup correctly!")
return
end
for _, v in pairs (npc_SpawnPositions[game.GetMap()]) do
local ent = ents.Create("npc_pointshop")
ent:SetPos(v.pos)
ent:SetAngles(v.ang)
ent:Spawn()
ent:Activate()
end
end)
[/code]
[B]shared.lua[/B]
[code]
ENT.Base = "base_ai"
ENT.Type = "ai"
ENT.PrintName = "NPC Pointshop"
ENT.Author = "N/A"
ENT.Contact = "N/A"
ENT.Purpose = "NPC for Pointshop"
ENT.Instructions = "1. stuff"
ENT.AutomaticFrameAdvance = true
ENT.AdminSpawnable = true
npc_SpawnPositions = {
["gm_construct"] = {
{pos = Vector(-1301, -304, -81), ang = Angle(0, 0, 0)},
},
}
npc_SpawnPositions = {
["rp_downtown_evilmelon_v1"] = {
{pos = Vector(-2298.968750, 586.456238, 49.031250), ang = Angle(1.540009, -2.499372, 0.000000)},
},
}
function ENT:SetAutomaticFrameAdvance( bUsingAnim )
self.AutomaticFrameAdvance = bUsingAnim
end
[/code]
Sorry, you need to Log In to post a reply to this thread.