Making an NPC spawn in different maps

I’m making an NPC but I’m not sure how to set it’s vector for different maps I can only set it to one. Like this

[lua] local function SpawnEntities()
if SERVER then
local npc = ents.Create(“point_giver”)
npc:SetPos(Vector(26.650785, -122.792404, 14464.031250))
npc:SetAngles(Angle(-0.275660, 0.942546, 0))
npc:Spawn()
end
end
hook.Add( “InitPostEntity”, “SpawnEntities”, SpawnEntities) [/lua]

Any help would be great.

Returns the current map without the file extension.

[lua]
if SERVER then
if (game.GetMap() == “gm_flatgrass”) then
–spawn entity here
elseif (game.GetMap() == “gm_construct”) then
–spawn entity here
end
end[/lua]

You can obviously expand from this and make it more efficient than a bunch of elseif statements, but yeah just to give you a general idea.

To do that you’ll want to save a list of positions for maps. You can use game.GetMap() to get the map’s name and select from the table the correct vector.



local npc_positions = {
	["gm_flatgrass"] = Vector(5, 10, 900),
	["gm_construct"] = Vector(1, 2, 3)
}
local position = npc_positions[game.GetMap()]


Thanks for that, real quickly can I get some more help?

Here’s my init.lua file

[lua]AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )
include( ‘shared.lua’ )

function ENT:Initialize()
self:SetModel( “models/Humans/Group02/male_09.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( 180 )

end

function ENT:AcceptInput( Name, Activator, Caller )
if Name == “Use” and Caller:IsPlayer() then
umsg.Start(“PointGiverUsed”, Caller) – Prepare the usermessage to that same player to open the menu on his side.
umsg.End() – We don’t need any content in the usermessage so we’re sending it empty now.
end
end

function PointGiver()

local ply = LocalPlayer()

ply:PS_GivePoints( 25 )

end

usermessage.Hook(“PointGiverUsed”, PointGiver) --Hook to messages from the server so we know when to display the menu.[/lua]

Would you know why it dosen’t give me points and displays this in console

Warning: Unhandled usermessage ‘PointGiverUsed’

Just use activator:PS_GivePoints(num).

  • snip wrong solution -

brandonj4’s solution is correct.

Ronny, if you place it clientside it can’t find the PS_GivePoints.

[editline]27th December 2013[/editline]

Ronny, if you place it clientside it can’t find the PS_GivePoints. Also Brandon I added you on steam I’m De Cheeky Dug

  • snip, I’m dumb -