How to save a loadout

I’m trying to do a custom loadout, so that whenever you select a weapon and spawn, it will save that loadout for next time you join, like Bad Company 2 does.

Should I use an SQL database?

Well. If you use an SQL database to also save other kinds of information yes.

If your only saving a loadout, you could simply save it to a .txt file.

PS: I always like MySQL saving because it allows me to show statistics on my website :3

Oh ok :smiley: thankyou :smiley:

[editline]11:28AM[/editline]

Gah MySQL is not installing, it keeps giving me the errors message:


Could not start the service MySQL. Error: 0

Can anyone help with this?

I can provide you with a database(free of charge), although that one will be external.
Tell me if you’re interested.

I’d rather set up my own database, I just want someone to help me fix that error

Google reveals many people are having the same issue.

Most issues are fixed by deleting the mySQL directories and registery keys, rebooting the PC. Then to retry the installation.

It’s possible the service is running in the background while you’re running the installer:

http://www.astahost.com/info.php/Error-Installing-Mysql-Server_t3605.html

Quote:
This is a known problem. Do you remember how you’d to create a MySQL Service and specify a common windows service name for MySQL when you setup 4.018 ? When you simply uninstall MySQL, it removes the present installation - without terminating the service. Under such circumstances, the original .exe file that runs as the windows service doesn’t get deleted, and still keeps loading/running in the background. When you try to install a newer version over it, the running service prevents the .exe being overwritten and this generates that error message you’re getting.

Your simplest way out, is to reinstall the old MySQL again, use it to Stop and Disable the Service and then uninstall it. Next install the newer version.

Second method: Goto Control Panel > Administrative Options > Services. From the list of services, find out the MySQL service and Stop It. Then Disable it from running for good. Next go to the mysql installation directory and remove it entirely. Now you can install the new version without a hitch.

Delete any registery data too.

You’re wrong, i’m not upgrading, I installed MySQL first time, and it gave me the error, it didn’t run anything.

Edited post.

Instead of narrowing your focus on this, my offer still stands.
I can create a db where you can develop on, since getting the tmysql or mysql module to run “can” be a pain.

is ther any way to safe a faction to a database or can that be saved to a .txt file as well

Make sure libMySQL.dll is in the right dir.

Unless you have multiple servers, it’s much much much easier to just use the database and library included with GMod.

How would I go about using these.

(Sorry, i’ve never used databases before)

Here’s the library: http://wiki.garrysmod.com/?title=Sql

If you don’t know any SQL, well then I would recommend learning. It’s very useful to know.

Thankyou, you’re a very helpful person :smiley:

Also, using the commands like sql.TableExists do I need to put that code in a seperate folder, or in shared.lua? The tutorial isn’t very clear.

Gah double post D:

Dunno if this helps

[lua]
require( “glon” )

hook.Add( “PlayerLoadout”, “SethLoadouts”, function( ply )
local weps = glon.decode( ply:GetPData( “Weapons” ) )
if !weps then return end
for k, v in pairs( weps ) do
ply:Give( v )
end
end )

concommand.Add( “ld_setweapon”, function( ply, cmd, args )
if !ValidEntity( ply ) or ply:IsSuperAdmin() then
if !args[2] then return end
for k, v in ipairs( player.GetAll() ) do
if string.find( string.lower( v:Nick() ), string.lower( args[1] ) ) then
local weps = glon.decode( v:GetPData( “Weapons” ) ) or {}
table.insert( weps, args[2] )
v:SetPData( “Weapons”, glon.encode( weps ) )
v:Give( args[2] )
if !ValidEntity( ply ) then
print( "Set " … args[2] … " for " … v:Nick() … “.” )
else
ply:ChatPrint( "Set " … args[2] … " for " … v:Nick() … “.” )
end
end
end
else
ply:ChatPrint( “Superadmin access required.”)
end
end )

concommand.Add( “ld_takeweapon”, function( ply, cmd, args )
if !ValidEntity( ply ) or ply:IsSuperAdmin() then
if !args[2] then return end
for k, v in ipairs( player.GetAll() ) do
if string.find( string.lower( v:Nick() ), string.lower( args[1] ) ) then
local weps = glon.decode( v:GetPData( “Weapons” ) ) or {}
for k, v in pairs( weps ) do
if v == args[2] then
table.remove( weps, k )
end
end
v:SetPData( “Weapons”, glon.encode( weps ) )
if !ValidEntity( ply ) then
print( "Removed " … args[2] … " from " … v:Nick() … “.” )
else
ply:ChatPrint( "Removed " … args[2] … " from " … v:Nick() … “.” )
end
end
end
else
ply:ChatPrint( “Superadmin access required.”)
end
end )

concommand.Add( “ld_takeallweapons”, function( ply, cmd, args )
if !ValidEntity( ply ) or ply:IsSuperAdmin() then
if !args[1] then return end
for k, v in ipairs( player.GetAll() ) do
if string.find( string.lower( v:Nick() ), string.lower( args[1] ) ) then
local weps = {}
v:SetPData( “Weapons”, glon.encode( weps ) )
v:StripWeapons()
if !ValidEntity( ply ) then
print( "Removed all of " … v:Nick() … “'s weapons.” )
else
ply:ChatPrint( "Removed all of " … v:Nick() … “'s weapons.” )
end
end
end
else
ply:ChatPrint( “Superadmin access required.”)
end
end )
[/lua]

If you’ve ever played BC2, you’ll know that when you choose your weapons and spawn with them it saves that particular loadout for that class, that’s what I want to do.

Okay, i’ve created the SQL code ( Thanks to Entoros ) where does it go? will it be in shared.lua?

:ninja: Failmerge strikes again :ninja:

Serverside code. Go’s in init.lua.

Have some Love iRzilla :smiley: