How to spawn entity on ttt map.

Hello, i’m new to lua.
I need a help with my lua script.
I need to spawn a entity on map with pos.
I used this, but it doesn’t seems to work.


-- Put your Lua here
entitydb = {}

entitydb["ttt_67thway_v14"] = "-1206.575684, -33.329056, 163.422180"








--------------------------------------------------------

local map = game.GetMap()
local pos = entitydb[map]
local round_state = GAMEMODE.round_state
local name = "mediaplayer_tv"

if round_state == ROUND_PREP then
    print("[Spawner] Spawning entity " .. name .. " on " .. map .. " with getpos: " .. pos)
    local media = ents.Create("mediaplayer_tv")
    media.SetModel("models/gmod_tower/suitetv_large.mdl")
    media.SetPos(Vector(pos))
    media.Spawn()
else
    print("[Spawner] Not available for current map. D:")
end


What i have done wrong?
P.s sorry for my bad english.

You need to run your code in a hook, and use vectors instead of strings for positions. Also, run functions with a colon on entities since they’re meta functions.

Example:


entitydb = {
   ["ttt_67thway_v14"] = Vector(x, y, z)
}

hook.Add("InitPostEntity", "foo", function()
   local pos = entitydb[game.GetMap()]
   
   if (pos) then
      local myent = ents.Create("foobar")
      myent:SetPos(pos)
      myent:Spawn()
   else
      print("Not available")
   end
end)

And only one question, how to make this work only on TTT Round Prep state?

Create the entity in TTTPrepareRound, remove it in TTTBeginRound.