Hello,
So I've been creating a gamemode, it's all working fine apart from the spawn points system, I managed to follow a tutorial to make the tables and all, this is what I have:
init.lua:
local spawnPointsVictims = {}
local spawnPointsKillers = {}
hook.Add( "PlayerSay", "SpawnCommands", function(ply, text, bteam)
text = string.lower( text )
textTable = string.Explode( " ", text )
if( textTable[1] == "!setspawn") then
if( !file.Exists( "dm/" .. game.GetMap(), "DATA" ) ) then
file.CreateDir( "dm/" .. game.GetMap(), "DATA")
end
if( !file.Exists( "dm/" .. game.GetMap() .. "/victimspawns.txt", "DATA" ) ) then
file.Write( "dm/" .. game.GetMap() .. "/victimspawns.txt", util.TableToKeyValues( spawnPointsVictims ) )
else
spawnPoints = util.KeyValuesToTable( file.Read( "dm/" .. game.GetMap() .. "/victimspawns.txt", "DATA" ) )
end
if( !file.Exists( "dm/" .. game.GetMap() .. "/killerspawns.txt", "DATA" ) ) then
file.Write( "dm/" .. game.GetMap() .. "/killerspawns.txt", util.TableToKeyValues( spawnPointsPedobears ) )
else
spawnPoints = util.KeyValuesToTable( file.Read( "dm/" .. game.GetMap() .. "/killerspawns.txt", "DATA" ) )
end
if( textTable[2] == "victims" ) then
table.insert( spawnPointsVictims, tostring( ply:GetPos() + Vector( 0, 0, 5 ) ) )
file.Write( "dm/" .. game.GetMap() .. "/victimspawns.txt", util.TableToKeyValues( spawnPointsVictims ) )
elseif( textTable[2] == "dm" ) then
table.insert( spawnPointsPedobears, tostring( ply:GetPos() + Vector( 0, 0, 5 ) ) )
file.Write( "dm/" .. game.GetMap() .. "/killerspawns.txt", util.TableToKeyValues( spawnPointsPedobears ) )
else
ply:ChatPrint( "Invalid team name entered!" )
end
if( !textTable == nil ) then
ply:ChatPrint( "Added spawnpoint for " .. textTable[2] .. "!" )
end
end
end)
sv_round.lua:
[ROUND_PREPARING] = function( gm )
game.CleanUpMap()
for k, ent in pairs(ents.GetAll()) do
if ent:IsWeapon() || ent:GetClass():match("^weapon_") then
ent:Remove()
end
if ent:GetClass():match("^item_") then
ent:Remove()
end
end
for k, v in pairs( player.GetAll() ) do
v:Spawn()
if( v:Team() == 1 ) then
v:SetPos( Vector( spawnPointsVictims[ math.random( 1, #spawnPointsVictims ) ] ) )
elseif( v:Team() == 2 ) then
v:SetPos( Vector( spawnPointsPedobears[ math.random( 1, #spawnPointsKillers) ] ) )
end
end
The error:
[ERROR] gamemodes/pedobear/gamemode/sv_round.lua:122: attempt to get length of global 'spawnPointsVictims' (a nil value)
1. unknown - gamemodes/pedobear/gamemode/sv_round.lua:122
2. SetRound - gamemodes/pedobear/gamemode/sv_round.lua:179
3. unknown - gamemodes/pedobear/gamemode/sv_round.lua:261
4. RoundThink - gamemodes/pedobear/gamemode/sv_round.lua:280
5. unknown - gamemodes/pedobear/gamemode/init.lua:405
For whatever team I spawn it says the same error for each team. Any help would be appreciated!
Thank you!
Sorry, you need to Log In to post a reply to this thread.