Raised This Month: $51 Target: $400
 12% 

Searched everywhere, Saving Player Settings for Plugins


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tww917
Member
Join Date: Mar 2014
Old 04-01-2014 , 05:26   Searched everywhere, Saving Player Settings for Plugins
Reply With Quote #1

I have sm_skinchooser that saves people's configurations so when they join it reloads their skin they chose when they left.
From what I know this is either cookies or clientprefs right?

I have a unusual effects plugin, and a hats plugin that needs to do the same. The hats I think I found a plugin, however the unusual particle effects is nowhere to be found.

Anyone experienced with cookies within plugins?
Perhaps mysql? If you need anything for this let me know I really want this integrated.

Help please T.T
tww917 is offline
Carl Sagan
Senior Member
Join Date: Jan 2014
Old 04-01-2014 , 19:38   Re: Searched everywhere, Saving Player Settings for Plugins
Reply With Quote #2

I'd use MySQL if it were me.
Carl Sagan is offline
tww917
Member
Join Date: Mar 2014
Old 04-01-2014 , 20:49   Re: Searched everywhere, Saving Player Settings for Plugins
Reply With Quote #3

Ya I love mysql. You can implement it into the web etc.

However, I need someone to help me add the right coding to a plugin so it will save the settings. I noticed after a lot of research and failed attempts, the best method was how sm_skinchooser did it, where it saves the settings to a txt file in the server. This method seems simple and it seems to work.

Wish I knew how to do all three methods (file in server, mysql, and cookies).

Do you know how to make plugins use mysql to save settings Carl?

Last edited by tww917; 04-01-2014 at 20:50.
tww917 is offline
Carl Sagan
Senior Member
Join Date: Jan 2014
Old 04-01-2014 , 21:07   Re: Searched everywhere, Saving Player Settings for Plugins
Reply With Quote #4

I haven't really worked with the other methods but I use a lot of MySQL. I only started learning SourcePawn back in January so I'm no master. I recommend watching this guy's videos: https://www.youtube.com/watch?v=02Kaa_Qv5pk

That's how I learned how to work with MySQL having never used it before.

Here are some basic steps in how things should go:

1. Create a handle for the SQL connection and set it to INVALID_HANDLE, also set a string for SQL connection errors, like this:

PHP Code:
new Handle:g_hDatabase INVALID_HANDLE;
new 
String:g_sError
2. Connect to the database during OnPluginStart(), it'll look something like this:

PHP Code:
public OnPluginStart()
{
    
g_hDatabase SQL_Connect("databasenamehere",true,g_sError,sizeof(g_sError));

    if (
g_hDatabase == INVALID_HANDLE)
    {
        
PrintToServer("Unable to connect to MySQL server: %s",g_sError);
    }

3. When someone uses the command to open the menu or choose a skin, however it'll work, do this so it won't function if it's not connected:

PHP Code:
public Action:Command_Callback(client,args)
{
    if (
g_hDatabase == INVALID_HANDLE)
    {
        return 
Plugin_Handled;
    }

4. When someone chooses a skin, you'll need to query the database to see if their steamid is already in the database. If it is, UPDATE that row's skin column with the new skin they chose. If their steamid isn't in the database, INSERT INTO the database their steamid and the skin they chose.

5. When they someone connects to the server, query the database to see if their steamid is in the database and if that row has a skin set. If so, set their skin to whatever's in the field.

It's kind of hard to explain over text and I could write out a plugin example for what you need but I'm too lazy

My advice is to look at the source code of other plugins that use MySQL and learn from there.

Last edited by Carl Sagan; 04-01-2014 at 21:08.
Carl Sagan is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 04-01-2014 , 22:59   Re: Searched everywhere, Saving Player Settings for Plugins
Reply With Quote #5

I don't know about you guys, but the only way I learned how to save data was through keyvalues which was sort of confusing at the beginning but I pretty much love it now.
thecount is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-02-2014 , 00:12   Re: Searched everywhere, Saving Player Settings for Plugins
Reply With Quote #6

This is what clientprefs is for.
__________________
asherkin is offline
tww917
Member
Join Date: Mar 2014
Old 04-02-2014 , 05:50   Re: Searched everywhere, Saving Player Settings for Plugins
Reply With Quote #7

Ya, I tried clientprefs, and ran into that tutorial, but I am too new to coding to do it. I'm a health science major and never did any coding before other than edit few lines of sourcemod plugins.

I had a plugin that would send data to mysql with a clientpref method, but idk why but it would not save when people rejoined.

I think sm_skinchooser uses keyvalues. I looked through the code and it seems to save a file through keyvalues. I honestly don't know what keyvalue is though xD
tww917 is offline
tww917
Member
Join Date: Mar 2014
Old 04-04-2014 , 13:23   Re: Searched everywhere, Saving Player Settings for Plugins
Reply With Quote #8

I just made the hats plugin spawn hats on join, so my players don't have to keep putting them on as the join.
Just an easier alternative for those who are looking.
tww917 is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 04-04-2014 , 16:10   Re: Searched everywhere, Saving Player Settings for Plugins
Reply With Quote #9

Quote:
Originally Posted by tww917 View Post
[...]the best method was how sm_skinchooser did it, where it saves the settings to a txt file in the server. This method seems simple and it seems to work.[...]
Which is the worst method ever. HDD access should never occur midgame, and even if you only read and write to it on map start and end, lookup will be the fastest when using a database.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.

Last edited by Dr. Greg House; 04-04-2014 at 16:10.
Dr. Greg House is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 04-04-2014 , 16:14   Re: Searched everywhere, Saving Player Settings for Plugins
Reply With Quote #10

Quote:
Originally Posted by Dr. Greg House View Post
Which is the worst method ever. HDD access should never occur midgame, and even if you only read and write to it on map start and end, lookup will be the fastest when using a database.
By default, clientprefs uses SQLite... which exists on the same machine.

Which, of course, writes to disk when you send INSERTs and UPDATEs to it.

Edit: MySQL and PgSQL will do the same thing if they're located on the same machine as the server.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 04-04-2014 at 16:19.
Powerlord is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode