Jump to content
  • 0
emumu

Character Creation/Deletion with SQL query

Question

it's a fine day & i need your great wisdom.

 

i need to throw a SQL query when character is created/deleted.

 

i wanna insert new data into some tables when new character is created.

similarly, deletion from tables is needed when character is deleted.

 

like:

character has created! -> insert into tblX (colA, colB, .....) values (dataA, dataB, .....);

character has deleted! -> delete from tblX where colA = dataA;

 

 

there are conditions that NPC script is forbidden against this problem.

 

need i modify .c/.h programs to solve this?

Edited by emumu

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Hello,

 

Yes you'd have to modiy the source code for this, as character creation is limited to char server only. 

 

For Character deletion, check delete_char_sql && make_new_char_sql, both found within char,c

As for your npc/script comment, I am not sure I understood it. Could you rephrase it please?

Share this post


Link to post
Share on other sites
  • 0

If I have read this correctly, perhaps you can achieve this without source modifications. A script command can be used to add values for new characters into the char database, so long as the columns exist. With that in mind, here's a script I wrote that you might find of use.

 

 

-    script    newcharadd    -1,{    OnPCLoginEvent:        if(!newcharcreate) {    // Check "new char" status                    // Configuration            .@dataA = 1;    // Value for colA            .@dataB = 2;    // Value for colB            .@dataC = 3;    // Value for colC                        query_sql "INSERT INTO `char` (colA,colB,colC) WHERE `char_id = " + getcharid(0) + " VALUES ('" + .@dataA + "','" + .@dataB + "','" + .@dataC + "')";                    newcharcreate = 1;    // Set "new char" status                }                end;        }

 

What this script does is update custom columns in the database with predefined values once a newly created character logs in for the first time. The values being inserted are under the // Configuration comment, which you can readjust to your liking. New characters are determined by the presence of the newcharcreate variable. The only thing you'd need to do is make sure you define the correct data type you want your custom columns to store in the database; if you'd like for them to store strings, make sure you change the .@data variables to strings (.@data$).

 

If you wanted something that specifically detected new character creation prior to logging in, you'll likely need to make source modifications. In regards to deleting data from your custom columns, is it absolutely necessary? Once a character has been deleted, the entire row is removed from the database - custom columns or not.

Edited by Via

Share this post


Link to post
Share on other sites
  • 0

thank you for reply!

 

i'm so sorry for my poor english...

i'd like to have said "i need to throw queries without npc script."

 

 

to Xgear

 

i modified char.c and solved this problem!

thanks a lot!

 

i added below codes in both parts "make_new_char_sql" & "delete_char_sql".

if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`char_id`) VALUES ('%d');", my_db_name, char_id)) {	Sql_ShowDebug(sql_handle);}
if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", my_db_name, char_id) ) {	Sql_ShowDebug(sql_handle);}

 

 

to Via

thanks for your kindness regardless of my poor sentence!

your explanation will help me when i need npc scripts that updates my original db.

Edited by emumu

Share this post


Link to post
Share on other sites
  • 0

That will work perfectly fine. Make sure you add your own queries after the proper checks are done to avoid logging false data (aka char name already taken, so character was not created, etc)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.