Getting a keyvalue set in Hammer for use in a lua script?

I’m working on a DM gamemode, and looking for a way to assign spawnpoints to teams in lua. So far i’ve added a keyvalue in the info_player_start ents called “team” (in hammer) with a value of either red or blue. I’ve been trying to retreive the values by doing:

for k,v in pairs(ents.FindByClass("info_player_start")) do
	if v:GetKeyValues().team == "red" then
		print("Red spawn added")
	if v:GetKeyValues().team == "blue" then
		print("Blue spawn added")

I know I’m getting the correct ents, but i cant get the keyvalues, so i was wondering how i’d get that to work.

Thanks in advance!

That looks right to me, what do you get with PrintTable(v:GetKeyValues())?

Suprisingly enough, i get nothing at all when i do that. Is this function broken or something?


I did a little test, and found out that ents.FindByClass(“info_player_start”) does not return anything, although thats the classname of the spawn ent. Should i be using a different ent?

Yes, it’s broken. Well, at least partly. It doesn’t return all of the keyvalues of an entity properly, and most of the returned values are usually wrong.
You can use the “EntityKeyValue” hook instead to get the correct keyvalues:
You could also just create a new SENT for the spawnpoints, and then get the keyvalues using ENT.KeyValue. That’s what I’d do.

I managed to solve it by using two different spawn ents, but thanks anyway!