Character Creation/Deletion with SQL query

emumu

New member
Messages
13
Points
0
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?

 
Last edited by a moderator:
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?

 
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.

 
Last edited by a moderator:
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);}
Code:
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.

 
Last edited by a moderator:
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)

 
Back
Top