Log in

View Full Version : strncpy question


mByte
01-05-2003, 06:24 PM
I am working on a small side project for me to add npc's just by being in the world.

I am saving them to the database but now I want to remove the 000's

can somebody over look this code tell me what is wrong and someway to fix it.


void Database::SaveSpawn(const char* s1, int8 s2, int16 s3, int8 s4, sint32 s5, int8 s6, int8 s7, int8 s8, float s9, int8 s10)
{
char errbuf[MYSQL_ERRMSG_SIZE];
int snl = strlen(s1)-3;
char snbuff[64];
char *query = 0;
int32 affected_rows = 0;
MYSQL_RES *result;
MYSQL_ROW row;

if(strstr(s1, "00") != 0){
strncpy(snbuff,s1,snl);
}

char* sqlQuery = "INSERT INTO npc_types (name, level, race, class, hp, gender, texture, helmtexture, size, social) values('%s','%i','%i','%i','%i','%i','%i','%i','%f ','%i')";

RunQuery(query, MakeAnyLenString(&query, sqlQuery, snbuff,s2,s3,s4,s5,s6,s7,s8,s9,s10));
delete[] query;
}

npc name being passed is 'hot000'

It is removing the three 000's but replacing with this other crap any tips?
[code]
hot

Joolz
01-05-2003, 06:33 PM
The 000's MUST be there. Well it should be 00 (Hogie changed it in the next release). Never remove them. Otherwise, things won't work properly. (Like horses etc.)

mByte
01-05-2003, 07:00 PM
Yea,I understand that but when you put them in the NPC_TYPES table you do not need 000's the 00's are added by the emulator and client or you would need to have a shit load of the same spawn records there for defeting the pourpse of a database.

I dont want to remove them from the game just the record i am putting into the database from walking around the zone!

ontop of that the question was is there a way to fix my problem its in no way part of the release that hoggie and all the awsome dev's do. Just a simple function I want to use.

Joolz
01-05-2003, 11:49 PM
Then just do snbuff[snl] = 0;

mByte
01-06-2003, 01:09 PM
Spank You!

I kept trying to do it
char snbuffer[snl]; and it wasnt working now i know why :)

:) *I learn something new everyday* :)