Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Development

Development::Development Forum for development topics and for those interested in EQEMu development. (Not a support forum)

Reply
 
Thread Tools Display Modes
  #1  
Old 08-28-2019, 12:47 AM
jsr
Hill Giant
 
Join Date: Aug 2008
Location: melbourne
Posts: 188
Default Advnpcspawn maketype error

This query is generating an error, but I can't see why based on the query that I think is doing the insert. The code has an int32 value of 28, but the error is showing 734375700. Any ideas?

Code:
query = StringFormat("

INSERT INTO npc_types 

(name, level, race, class, 
hp, gender, texture, helmtexture, 
size, loottable_id, merchant_id, face, 
runspeed, prim_melee_type, sec_melee_type) "

"VALUES(\"%s\", %i, %i, %i, %i, %i, %i, %i, %f, %i, %i, %i, %i, %i, %i)",

tmpstr, spawn->GetLevel(), spawn->GetRace(), spawn->GetClass(), 
spawn->GetMaxHP(), spawn->GetGender(), spawn->GetTexture(), spawn->GetHelmTexture(), 
spawn->GetSize(), spawn->GetLoottableID(), spawn->MerchantType, 0, 
spawn->GetRunspeed(), 28, 28);

Error:
Code:
[MySQL Error] 1264: Out of range value for column 'sec_melee_type' at row 1 
INSERT INTO npc_types 
(name, level, race, class, 
hp, gender, texture, helmtexture, 
size, loottable_id, merchant_id, face, 
runspeed, prim_melee_type, sec_melee_type) 

VALUES("a", 1, 1, 1, 
11, 0, 0, 0, 
6.000000, 0, 0, 0, 
0.000000, 28, 734375700)
Reply With Quote
  #2  
Old 08-28-2019, 01:50 AM
Uleat's Avatar
Uleat
Developer
 
Join Date: Apr 2012
Location: North Carolina
Posts: 2,815
Default

I know there have been issues like this before in regards to string formatting.

The only thing I can think to try are these two changes:
Code:
query = StringFormat(
	"INSERT INTO npc_types (
	"name,"
	" level,"
	" race,"
	" class,"
	" hp,"
	" gender,"
	" texture,"
	" helmtexture,"
	" size,"
	" loottable_id,"
	" merchant_id,"
	" face,"
	" runspeed,"
	" prim_melee_type,"
	" sec_melee_type"
	")"
	" VALUES ("
	"'%s',"
	" %i,"
	" %i,"
	" %i,"
	" %i,"
	" %i,"
	" %i,"
	" %i,"
	" %f,"
	" %i,"
	" %i,"
	" %i,"
	" %f,"
	" %i,"
	" %i"
	")",
	tmpstr,
	spawn->GetLevel(),
	spawn->GetRace(),
	spawn->GetClass(), 
	spawn->GetMaxHP(),
	spawn->GetGender(),
	spawn->GetTexture(),
	spawn->GetHelmTexture(), 
	spawn->GetSize(),
	spawn->GetLoottableID(),
	spawn->MerchantType,
	0, 
	(float)spawn->GetRunspeed(),
	28,
	28
);
The database storage type for `runspeed` is float and there could be a conversion issue in the interpreter.
__________________
Uleat of Bertoxxulous

Compilin' Dirty
Reply With Quote
  #3  
Old 08-28-2019, 02:17 AM
jsr
Hill Giant
 
Join Date: Aug 2008
Location: melbourne
Posts: 188
Default

Thanks for the response Uleat.

I tried %f and cast to float, unfortunately the same error is returned with the exception of that third last element now being a float. Which at least confirms I was looking at the right query.


For context, I'm doing
>spawn a
>(target a)
>advnpcspawn maketype

Which is how I've gone about creating npcs>spawngroups>spawns in the past. It's been a few years since I was doing this though so this may be an old method that isn't maintained?
Reply With Quote
  #4  
Old 08-28-2019, 07:48 AM
jsr
Hill Giant
 
Join Date: Aug 2008
Location: melbourne
Posts: 188
Default

Ok, if I change the last field value to an empty string, rather than int: 28, the last two field values get corrupted.

(error with)
INSERT INTO npc_types (name, level, race, class, hp, gender, texture, helmtexture, size, loottable_id, merchant_id, face, runspeed, prim_melee_type, sec_melee_type)
VALUES("a", 1, 1, 1, 11, 0, 0, 0, 6.000000, 0, 0, 0, 0.000000, 34383726, -2100638871)

So I'm guessing there's a trailing character on the query string that is being incorrectly handled by the c_type function.
Reply With Quote
  #5  
Old 08-28-2019, 08:20 AM
jsr
Hill Giant
 
Join Date: Aug 2008
Location: melbourne
Posts: 188
Default

This is messy, but it has fixed the error.

Code:
uint32 ZoneDatabase::AddNPCTypes(const char *zone, uint32 zone_version, Client *client, NPC *spawn, uint32 spawnGroupID)
{
	uint32 npc_type_id;
	char numberlessName[64];

	EntityList::RemoveNumbers(strn0cpy(numberlessName, spawn->GetName(), sizeof(numberlessName)));
	std::string query =
	    StringFormat("INSERT INTO npc_types (name, level, race, class, hp, gender, "
			 "texture, helmtexture, size, loottable_id, merchant_id, face, "
			 "runspeed, prim_melee_type, sec_melee_type) "
			 "VALUES(\"%s\", %i, %i, %i, %i, %i, %i, %i, %f, %i, %i, %i, %f, %i, %f)",
			 numberlessName, spawn->GetLevel(), spawn->GetRace(), spawn->GetClass(), spawn->GetMaxHP(),
			 spawn->GetGender(), spawn->GetTexture(), spawn->GetHelmTexture(), spawn->GetSize(),
			 spawn->GetLoottableID(), spawn->MerchantType, 0, (float) spawn->GetRunspeed(), 28, (float) 28);
	auto results = QueryDatabase(query);
	if (!results.Success())
		return 0;
	npc_type_id = results.LastInsertedID();

	if (client)
		client->Message(Chat::White, "%s npc_type ID %i created successfully!", numberlessName, npc_type_id);

	return 1;
}
Reply With Quote
Reply

Thread Tools
Display Modes

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 04:13 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3