[DarkRP]: printing the players balance on loading screen

Hello i have been making a loading screen and its is almost to my liking, i would like to print “Your Balance:” in it but i have not found a way of doing so. if you would like to view what i have, it is here. it has been entered but doesn’t give a value at the moment as i do not know how to put it there.

Loading Screen:
http://coldfgaming.site.nfoservers.com/Loadingscreens/DarkRP/gmod-loadingscreen-master/

On the server you would make an addon that whenever a player disconnects inserts his steamid and his balance into a MySQL table and simply read it on the website since you can use $_GET to get the player’s steamid.

im not the best with coding addons lol, could you give me an example on how to send it to MySQL i can take it from there. if you dont mind.

You’d run the following SQL query on your server ( with PHP you’d need to connect to MySQL, and select the database ) then run mysql_fetch_assoc or row… ‘SELECT balance FROM users_table WHERE steamid="’ . mysql_real_escape_string( $_GET[ “steamid” ] ) . ‘"’;

change balance to the proper column name, and users_table to the proper table name, and steamid to the proper column name which holds the steamid, and “steamid” to the proper GET value…

Basic example: http://www.w3schools.com/php/func_mysql_real_escape_string.asp

… 0_o okay, well im sure of the files to access. i have not used mysql before so could you go a tad but more in-depth with this? i don’t mean to bother you.

[editline]23rd October 2014[/editline]

Unsure*

How do you store the balance right now?

i do not. I want to get what the balance for a player is in the DarkRP server and place it on the loading screen for when they join. im guessing that it store in the MySQL but iv never worked with it before. so thats why im asking for an example if someone could. :stuck_out_tongue:

Does your server have a file called “sv.db” in your server/garrysmod/ directory?

Open that using SQLite Manager, a firefox addon. It’ll allow you to browse the tables. Chances are it isn’t stored in MySQL but in flat-file / SQLite database which makes it that much more difficult to get to…

If it is stored via MySQL then it should be straight-forward.

Who is your host? Is it an unmodified DarkRP ( see DarkRP help-thread, they’d know more about how the data is stored, see links below )? Is it modified? Do you have libmysql.dll in server/garrysmod/ folder? Do you have gmsv_mysqloo_win32.dll or gmsv_tmysql_win32.dll or similar dll files in server/garrysmod/lua/bin/? If not, it isn’t likely that you’re using MySQL. If so, then you might be; find the configuration file which tells you the login information and that can be used to login… Did you set up your server, or did your host set it up, or someone else?

Usually, if you’re running MySQL you’d know about it.

Hey, welcome to FacePunch.
This forum is for devs that need help working on things. Here are some resources to help you get started:

Generalized Lua Help ( Links to Wikis, Answers the question of “Where do I post a simple question or DarkRP Specific question”, links to other resources compiled by forum members )
https://dl.dropboxusercontent.com/u/26074909/tutoring/___welcome_docs/_welcome_general_lua_learning.lua.html

Useful Programs ( SteamCMD, Autosizer, Desktops, Process Explorer ) and Notepad++ Upgrades
https://dl.dropboxusercontent.com/u/26074909/tutoring/___welcome_docs/_welcome_useful_programs_and_notepadpp_upgrades.lua.html

i have sv.bd, libmysqll.dll, gmsv_tmysql_win32.dll, The servers host is NFO and it was setup by them initially, edited by me, so its a modified DarkRP. (just the basic DarkRP changes like jobs/weapons/ammo/ect…)

NFO usually sets up MySQL, so that’s good. sv.db could be for the money, or other things depending on your config. If you have MySQL dlls it is set up ( doesn’t mean it is set up to connect to a server though ). You’ll need to look for a config file for the MySQL, or config for DarkRP that switches between flat-file/sqlite/MySQL.

I’m not too familiar with DarkRP ( they’d be in the DarkRP thread ), but there should be config somewhere which defines what type of data-storage system you’re using.

Its going to be hard, for someone who has no knowledge in coding.

no no, thats not what i said, i do Lua,html and batch if that counts but i know nothing about MySQL

If you are experienced with Lua and HTML you should have no problem picking up SQL.

But, to access the players money on the loading screen you will have to store it in an SQL database, like others have suggested. If you want to make this easy, DarkRP has an option to save with mysqloo, so I would use that. This will then give you a table called darkrp_player, this table has everything you need. Match the connecting players SteamID with their unique ID and then display the data

ok so would i go to garrysmod/gamemode/darkrp/gamemode/config/_MySQL.lua and change the info there to my MySQL information? then they link and save? also where how to i get into the MySQL to find the information?

after that i think i can probably do what i need to.

[editline]24th October 2014[/editline]

i have gotten into sv.db and i have found the info you talked about.

INSERT INTO playerinformation VALUES(2378256880,‘STEAM_0:1:10541603’);
INSERT INTO darkrp_player VALUES(2378256880,‘Dan’,45,1918);

what from here?

[editline]24th October 2014[/editline]

id think id have to get it to look for steamid and print the last value. but idk what the last value is called. like ex: rpbalance plybalance balance… not sure what to use. please correct me if im wrong.

i have found 2 codes, i feel like they are autorun files, can you take a look and tell me if this is 1. somthing to place in lua/autorun and 2. if this will give me what i need if i get the site to call the information from “money”.
Code 1



function tables_exist()
 
	if (sql.TableExists("player_info") && sql.TableExists("player_skills")) then
		Msg("Both tables already exist !")
	else
		if (!sql.TableExists("player_info")) then
			query = "CREATE TABLE player_info ( unique_id varchar(255), money int )"
			result = sql.Query(query)
			if (sql.TableExists("player_info")) then
				Msg("Succes ! table 1 created 
")
			else
				Msg("Somthing went wrong with the player_info query ! 
")
				Msg( sql.LastError( result ) .. "
" )
			end	
		end
		if (!sql.TableExists("player_skills")) then
			query = "CREATE TABLE player_skills ( unique_id varchar(255), speech int, fish int, farm int )"
			result = sql.Query(query)
			if (sql.TableExists("player_skills")) then
				Msg("Succes ! table 2 created 
")
			else
				Msg("Somthing went wrong with the player_skills query ! 
")
				Msg( sql.LastError( result ) .. "
" )
			end	
		end
	end
 
end
 
function new_player( SteamID, ply )
 
		steamID = SteamID
		sql.Query( "INSERT INTO player_info (`unique_id`, `money`)VALUES ('"..steamID.."', '100')" )
		result = sql.Query( "SELECT unique_id, money FROM player_info WHERE unique_id = '"..steamID.."'" )
		if (result) then
 
			sql.Query( "INSERT INTO player_skills (`unique_id`, `speech`, `fish`, `farm`)VALUES ('"..steamID.."', '1', '1', '1')" )
			result = sql.Query( "SELECT unique_id, speech, fish, farm FROM player_skills WHERE unique_id = '"..steamID.."'" )
			if (result) then
				Msg("Player account created !
")
				sql_value_stats( ply )
				sql_value_skills( ply )
			else
				Msg("Something went wrong with creating a players skills !
")
			end
 
		else
			Msg("Something went wrong with creating a players info !
")
		end
end
 
function player_exists( ply )
 
	steamID = ply:GetNWString("SteamID")
 
	result = sql.Query("SELECT unique_id, money FROM player_info WHERE unique_id = '"..steamID.."'")
	if (result) then
			sql_value_stats( ply ) -- We will call this to retrieve the stats
			sql_value_skills( ply ) -- We will call this to retrieve the skills
	else
		new_player( steamID, ply ) -- Create a new player :D
	end
end
 
function Initialize()
	tables_exist()
end
 
function PlayerInitialSpawn( ply )
 
	timer.Create("Steam_id_delay", 1, 1, function()
		SteamID = ply:SteamID()
		ply:SetNWString("SteamID", SteamID)
		timer.Create("SaveStat", 10, 0, function() saveStat( ply ) end)
		player_exists( ply ) 
	end)
 
end
 
hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", PlayerInitialSpawn )
hook.Add( "Initialize", "Initialize", Initialize )
 


Next
Code 2



function sql_value_stats ( ply )
	unique_id = sql.QueryValue("SELECT unique_id FROM player_info WHERE unique_id = '"..steamID.."'")
	money = sql.QueryValue("SELECT money FROM player_info WHERE unique_id = '"..steamID.."'")
	ply:SetNWString("unique_id", unique_id)
	ply:SetNWInt("money", money)
end
 
function sql_value_skills ( ply )
	unique_id = sql.QueryValue("SELECT unique_id FROM player_skills WHERE unique_id = '"..steamID.."'")
	speech = sql.QueryValue("SELECT speech FROM player_skills WHERE unique_id = '"..steamID.."'")
	fish = sql.QueryValue("SELECT fish FROM player_skills WHERE unique_id = '"..steamID.."'")
	farm = sql.QueryValue("SELECT farm FROM player_skills WHERE unique_id = '"..steamID.."'")
	ply:SetNWString("unique_id", unique_id)
	ply:SetNWInt("speech", speech)
	ply:SetNWInt("fish", fish)
	ply:SetNWInt("farm", farm)
end
 
function saveStat ( ply )
	money = ply:GetNWInt("money")
	unique_id = ply:GetNWString ("SteamID")
	speech = ply:GetNWInt("speech")
	fish = ply:GetNWInt("fish")
	farm = ply:GetNWInt("farm")
	sql.Query("UPDATE player_skills SET speech = "..speech..", fish = "..fish..", farm = "..farm.." WHERE unique_id = '"..unique_id.."'")
	sql.Query("UPDATE player_info SET money = "..money.." WHERE unique_id = '"..unique_id.."'")
	ply:ChatPrint("Stats updated !")
end
 
function tables_exist()
 
	if (sql.TableExists("player_info") && sql.TableExists("player_skills")) then
		Msg("Both tables already exist !")
	else
		if (!sql.TableExists("player_info")) then
			query = "CREATE TABLE player_info ( unique_id varchar(255), money int )"
			result = sql.Query(query)
			if (sql.TableExists("player_info")) then
				Msg("Succes ! table 1 created 
")
			else
				Msg("Somthing went wrong with the player_info query ! 
")
				Msg( sql.LastError( result ) .. "
" )
			end	
		end
		if (!sql.TableExists("player_skills")) then
			query = "CREATE TABLE player_skills ( unique_id varchar(255), speech int, fish int, farm int )"
			result = sql.Query(query)
			if (sql.TableExists("player_skills")) then
				Msg("Succes ! table 2 created 
")
			else
				Msg("Somthing went wrong with the player_skills query ! 
")
				Msg( sql.LastError( result ) .. "
" )
			end	
		end
	end
 
end
 
function new_player( SteamID, ply )
 
		steamID = SteamID
		sql.Query( "INSERT INTO player_info (`unique_id`, `money`)VALUES ('"..steamID.."', '100')" )
		result = sql.Query( "SELECT unique_id, money FROM player_info WHERE unique_id = '"..steamID.."'" )
		if (result) then
 
			sql.Query( "INSERT INTO player_skills (`unique_id`, `speech`, `fish`, `farm`)VALUES ('"..steamID.."', '1', '1', '1')" )
			result = sql.Query( "SELECT unique_id, speech, fish, farm FROM player_skills WHERE unique_id = '"..steamID.."'" )
			if (result) then
				Msg("Player account created !
")
				sql_value_stats( ply )
				sql_value_skills( ply )
			else
				Msg("Something went wrong with creating a players skills !
")
			end
 
		else
			Msg("Something went wrong with creating a players info !
")
		end
end
 
function player_exists( ply )
 
	steamID = ply:GetNWString("SteamID")
 
	result = sql.Query("SELECT unique_id, money FROM player_info WHERE unique_id = '"..steamID.."'")
	if (result) then
			sql_value_stats( ply ) -- We will call this to retrieve the stats
			sql_value_skills( ply ) -- We will call this to retrieve the skills
	else
		new_player( steamID, ply ) -- Create a new player :D
	end
end
 
function Initialize()
	tables_exist()
end
 
function PlayerInitialSpawn( ply )
 
	timer.Create("Steam_id_delay", 1, 1, function()
		SteamID = ply:SteamID()
		ply:SetNWString("SteamID", SteamID)
		timer.Create("SaveStat", 10, 0, function() saveStat( ply ) end)
		player_exists( ply ) 
	end)
 
end
 
hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", PlayerInitialSpawn )
hook.Add( "Initialize", "Initialize", Initialize )


[editline]24th October 2014[/editline]

also an idea of mine.



if (isset($_GET['steamid'])) {
    $data = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=07D591DD50614036689A5E33AC63A041&steamids='.$_GET['steamid'];
    $f = file_get_contents($data);
    $arr = json_decode($f, true);
    if (isset($arr['response']['players'][0]['personaname']))
        $plname = $arr['response']['players'][0]['personaname'];
    if (isset($arr['response']['players'][0]['avatar']))
        $avatar = $arr['response']['players'][0]['avatar'];
	if (isset ($arr['response']['players'][0]['money']))
		$money = $arr['response']['players'][0]['money'];
    
}




		Your balance: $<b><?php echo $money?><br>