SQL Help

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

function Load_Player_Info( ply )
ply.Experience = sql.QueryValue( “SELECT Xp FROM Player_Info WHERE Player_ID = '”…ply:SteamID()…"’" )
ply.MaxExperience = sql.QueryValue( “SELECT MaxXp FROM Player_Info WHERE Player_ID = '”…ply:SteamID()…"’" )
ply.Level = sql.QueryValue( “SELECT Level FROM Player_Info WHERE Player_ID = '”…ply:SteamID()…"’" )
ply.Money = sql.QueryValue( “SELECT Money FROM Player_Info WHERE Player_ID = '”…ply:SteamID()…"’" )
end

function Initialize()
if !sql.TableExists( “Player_Info” ) then
Result = sql.Query( “CREATE TABLE Player_Info ( Player_ID varchar(255), Money int, Xp int, MaxXp int, Level int, HP int, Attack int, Defence int )” )
if !sql.TableExists( “Player_Info” ) then
Msg( sql.LastError( Result ) )
end
end
end
hook.Add( “Initialize”, “Initialize”, Initialize )

function GM:PlayerInitialSpawn( ply )
if ply:IsAdmin() or ply:IsSuperAdmin() then
ply:SetTeam( 1 )
else
ply:SetTeam( 2 )
end
ply:ConCommand( “MOTD” )
ply.Experience = 0
ply.MaxExperience = 100
ply.Level = 1
ply.Money = 0

Result = sql.Query( "SELECT Player_ID, Money, Xp, MaxXp, Level, HP, Attack, Defence FROM Player_Info WHERE Player_ID = '"..ply:SteamID().."'" )
if Result then
	Load_Player_Info( ply )
else
	sql.Query( "INSERT INTO Player_Info ( `Player_ID`, `Money`, `Xp`, `MaxXp`, `Level`, `HP`, `Attack`, `Defence` ) VALUES ( '"..ply:SteamID()..", 0, 0, 100, 1, 50, 0, 0' )" )
	Result = sql.Query( "SELECT Player_ID, Money, Xp, MaxXp, Level, HP, Attack, Defence FROM Player_Info WHERE Player_ID = '"..ply:SteamID().."'" )
	if Result then
		Load_Player_Info( ply )
	else
		Msg( sql.LastError( "SQL Error: "..Result ) )
	end
end

util.AddNetworkString( "HealthPackage" )
net.Start( "HealthPackage" )
net.WriteUInt( ply:GetMaxHealth(), 16 )
net.Send( ply )

util.AddNetworkString( "ExperiencePackage" )
net.Start( "ExperiencePackage" )
net.WriteUInt( ply.Experience, 16 )
net.WriteUInt( ply.MaxExperience, 16 )
net.WriteUInt( ply.Level, 8 )
net.Send( ply )

end

function GM:PlayerSpawn( ply )
self.BaseClass:PlayerSpawn( ply )
ply:SetGravity ( 1 )
ply:SetWalkSpeed( 100 )
ply:SetRunSpeed ( 200 )
ply:SetMaxHealth( sql.QueryValue( “SELECT HP FROM Player_Info WHERE Player_ID = '”…ply:SteamID()…"’" ) )
ply:SetHealth( 50 )
end

function GM:PlayerLoadout( ply )
ply:Give( “weapon_crowbar” )
ply:Give( “weapon_smg1” )
ply:GiveAmmo(500, “smg1”, false)
end

function GM:PlayerSwitchFlashlight(ply, SwitchOn)
return true
end

local NPCSpawns = {}

local function AddNPCSpawn(z_type,pos,ang)
table.insert(NPCSpawns,{Type = z_type,Pos = pos,Angles = ang, NPC = NULL})
end

local function SpawnANPC(NPCIndex)
local NPCSpawn = NPCSpawns[NPCIndex]
if IsValid(NPCSpawn.NPC) then NPCSpawn.NPC:Remove() end

local npc = ents.Create( NPCSpawn.Type )
npc:SetPos( NPCSpawn.Pos )
npc:SetAngles( NPCSpawn.Angles )
npc:DropToFloor()
npc.NPCIndex = NPCIndex
npc:Spawn()
 
NPCSpawn.NPC = npc

end

hook.Add(“InitPostEntity”,“InitZombieSpawn”,function()
for k,v in pairs(ents.FindByName(“ZombieSpawn”)) do AddNPCSpawn(“npc_zombie”,v:GetPos(),v:GetAngles()) end
for k,v in pairs(ents.FindByName(“FastZombieSpawn”)) do AddNPCSpawn(“npc_fastzombie”,v:GetPos(),v:GetAngles()) end
for k,v in pairs(ents.FindByName(“PoisonZombieSpawn”)) do AddNPCSpawn(“npc_poisonzombie”,v:GetPos(),v:GetAngles()) end

for i = 1, #NPCSpawns, 1 do
    SpawnANPC( i )
end

end)

hook.Add(“OnNPCKilled”, “RespawnDeadNPC”, function(Victim, Killer, Weapon)
local NPCIndex = Victim.NPCIndex
if Victim:GetClass() == “npc_fastzombie” then
Killer.Experience = Killer.Experience + math.random( 10, 20 )
if Killer.Experience >= Killer.MaxExperience then
Killer.Experience = Killer.Experience - Killer.MaxExperience
Killer.Level = Killer.Level + 1
Killer.MaxExperience = Killer.MaxExperience + 100
end
util.AddNetworkString( “ExperiencePackage” )
net.Start( “ExperiencePackage” )
net.WriteUInt( Killer.Experience, 16 )
net.WriteUInt( Killer.MaxExperience, 16 )
net.WriteUInt( Killer.Level, 8 )
net.Send( Killer )
end
if Victim:GetClass() == “npc_poisonzombie” then
Killer.Experience = Killer.Experience + math.random( 15, 25 )
if Killer.Experience >= Killer.MaxExperience then
Killer.Experience = Killer.Experience - Killer.MaxExperience
Killer.Level = Killer.Level + 1
Killer.MaxExperience = Killer.MaxExperience + 100
end
util.AddNetworkString( “ExperiencePackage” )
net.Start( “ExperiencePackage” )
net.WriteUInt( Killer.Experience, 16 )
net.WriteUInt( Killer.MaxExperience, 16 )
net.WriteUInt( Killer.Level, 8 )
net.Send( Killer )
end
if Victim:GetClass() == “npc_headcrab_poison” then
Killer.Experience = Killer.Experience + math.random( 10, 15 )
if Killer.Experience >= Killer.MaxExperience then
Killer.Experience = Killer.Experience - Killer.MaxExperience
Killer.Level = Killer.Level + 1
Killer.MaxExperience = Killer.MaxExperience + 100
end
util.AddNetworkString( “ExperiencePackage” )
net.Start( “ExperiencePackage” )
net.WriteUInt( Killer.Experience, 16 )
net.WriteUInt( Killer.MaxExperience, 16 )
net.WriteUInt( Killer.Level, 8 )
net.Send( Killer )
end
if Victim:GetClass() == “npc_headcrab_fast” then
Killer.Experience = Killer.Experience + math.random( 5, 10 )
if Killer.Experience >= Killer.MaxExperience then
Killer.Experience = Killer.Experience - Killer.MaxExperience
Killer.Level = Killer.Level + 1
Killer.MaxExperience = Killer.MaxExperience + 100
end
util.AddNetworkString( “ExperiencePackage” )
net.Start( “ExperiencePackage” )
net.WriteUInt( Killer.Experience, 16 )
net.WriteUInt( Killer.MaxExperience, 16 )
net.WriteUInt( Killer.Level, 8 )
net.Send( Killer )
end
if NPCIndex then
timer.Simple(60, function() SpawnANPC(NPCIndex) end)
end
end)[/LUA]

Error


[ERROR] gamemodes/solitude/gamemode/init.lua:44: attempt to concatenate global 'Result' (a nil value)
  1. unknown - gamemodes/solitude/gamemode/init.lua:44



try using SQLStr(ply:SteamID()). I had that same problem before and that worked. if not that then its sql.SQLStr(ply:SteamID())

Still has a problem.

[editline]27th December 2012[/editline]

Can anyone help?

http://wiki.garrysmod.com/page/Libraries/sql/LastError line 44

New Error


[ERROR] gamemodes/solitude/gamemode/init.lua:44: attempt to concatenate global 'Result' (a nil value)
  1. unknown - gamemodes/solitude/gamemode/init.lua:44



The error is in sql.LastError(), not the Result variable

Oh, Derp! XD

Error


1 values for 8 columns

Probably from line 39.