I'm trying to be able to save and spawn npcs with mysql, but I'm running into this problem. Here's my code
[code]
concommand.Add("spawnsql", function()
npcclass = sql.Query( "SELECT class from pkmn7 WHERE SteamID = '".. ply:SteamID() .."' " )
npcclass2 = sql.Query( "SELECT lvl from pkmn7 WHERE SteamID = '".. ply:SteamID() .."' " )
PrintTable(npcclass)
PrintTable(npcclass2)
tts = table.ToString( npcclass )
local sqlnpc = ents.Create( tts )
sqlnpc:SetPos( Vector( -223.372253, 89.284607, -12223.968750 ) )
sqlnpc:Spawn()
end)[/code]
it gives me this error
Attempted to create unknown entity type {{class="simple_nextbot",},}!
[ERROR] gamemodes/pokemon/gamemode/init.lua:223: Tried to use a NULL entity!
1. SetPos - [C]:-1
2. unknown - gamemodes/pokemon/gamemode/init.lua:223
3. unknown - lua/includes/modules/concommand.lua:54
I know the problem is there is no entity called class="simple_nextbot", but I'm not sure how to get rid of the class= part. Any help at all would be appreciated!
You didn't define ply in the concommand.Add callback.
It's still giving me the same error
Post the new code?
[code]
concommand.Add("spawnsql", function(ply)
npcclass = sql.Query( "SELECT class from pkmn7 WHERE SteamID = '".. ply:SteamID() .."' " )
npcclass2 = sql.Query( "SELECT lvl from pkmn7 WHERE SteamID = '".. ply:SteamID() .."' " )
PrintTable(npcclass)
PrintTable(npcclass2)
tts = table.ToString( npcclass )
local sqlnpc = ents.Create( tts )
sqlnpc:SetPos( Vector( -223.372253, 89.284607, -12223.968750 ) )
sqlnpc:Spawn()
end)[/code]
Just tested, works fine. Make sure you're now running it from the server console. Also, localise your variables.
I'm still getting this error
Attempted to create unknown entity type {{class="simple_nextbot",},}!
How do I make it return just the simple_nexbot part and not the class= part?
[editline]28th December 2016[/editline]
I figured it out, I had to do
[code]
concommand.Add("spawnsql", function(ply)
local npcclass = sql.QueryValue( "SELECT class from pkmn7 WHERE SteamID = '".. ply:SteamID() .."' " )
local npcclass2 = sql.Query( "SELECT lvl from pkmn7 WHERE SteamID = '".. ply:SteamID() .."' " )
local sqlnpc = ents.Create( npcclass )
sqlnpc:SetPos( Vector( 64.000000, 576.000000, -12223.080078) )
sqlnpc:Spawn()
end)[/code]
Sorry, you need to Log In to post a reply to this thread.