I have a question regarding a Lua file that is not working at all. I have the file located in the gamemode folder of my gamemode(which is cinema) under the name of sql_database.lua. The file does not print anything to the console, output any errors, or do basically anything. The code that I used below is edited from a tutorial on the wiki. What am I doing wrong here?
[CODE]function Set_Networked_Values_Player_Data( plyr )
player_id = sql.QueryValue( "SELECT player_id FROM player_data WHERE player_id = '"..steamID.."'" )
dankies = sql.QueryValue( "SELECT dankies FROM player_data WHERE player_id = '"..steamID.."'" )
plyr:SetNWString( "Player ID", player_id )
plyr:SetNWInt( "Dankies", dankies )
end
function Save_Player_Stats ( plyr )
dankies = ply:GetNWInt( "Dankies" )
player_id = ply:GetNWString( "SteamID" )
sql.Query( "UPDATE player_data SET dankies = "..dankies.." WHERE player_id = '"..player_id.."'" )
ply:ChatPrint( "Player Stats have been updated!" )
end
function Do_The_Tables_Exist( )
if ( sql.TableExists( "player_data" ) ) then
Msg( "The table player_data already exists! \n" )
else
if ( !sql.TableExists( "player_data" ) ) then
query = "CREATE TABLE player_data ( player_id varchar( 255 ), dankies int )"
result = sql.Query( query )
if ( sql.TableExists( "player_data" ) ) then
Msg( "Success! The table player_data was created! \n" )
else
Msg( "Something went wrong with the player_data query! \n" )
Msg( sql.LastError( result ) .. "\n" )
end
end
end
end
function Create_Player_Account( SteamID, plyr )
steamID = SteamID
sql.Query( "INSERT INTO player_data ( `player_id`, `dankies` ) VALUES ( '"..steamID.."', '100') " )
result = sql.Query( "SELECT player_id, dankies FROM player_data WHERE player_id = '"..steamID.."'" )
if ( result ) then
Msg( "Player account created !\n" )
Set_Networked_Values_Player_Data( plyr )
else
Msg( "Something went wrong with creating the player_data table! \n" )
end
end
function Player_Account_Already_Exists( plyr )
steamID = ply:GetNWString( "SteamID" )
result = sql.Query( "SELECT player_id, dankies FROM player_data WHERE player_id = '"..steamID.."'" )
if ( result ) then
Set_Networked_Values_Player_Data( plyr )
else
Create_Player_Account( steamID, plyr )
end
end
function Initialize( )
Do_The_Tables_Exist( )
end
function Player_Initial_Spawn( plyr )
timer.Create( "Steam_ID_Delay", 1, 1, function( )
SteamID = plyr:SteamID( )
plyr:SetNWString( "SteamID", SteamID )
timer.Create( "Save_Player_Stats", 10, 0, function( ) Save_Player_Stats( plyr ) end )
Player_Account_Already_Exists( plyr )
end )
end
hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", Player_Initial_Spawn )
hook.Add( "Initialize", "Initialize", Initialize )[/CODE]
The file needs to be included.
You can try a few things.
1) Make sure it is the lua folder
2) Put a print at the top and check console to make sure it's running.
3) If the file is not in autorun, then it needs to be includeed as Dope said.
[QUOTE=RealDope;47088848]The file needs to be included.[/QUOTE]
This worked. I'm stupid.
Sorry, you need to Log In to post a reply to this thread.