Log in

View Full Version : Weird MySQL error with #spawn/#npcspawn create


Shendare
08-01-2015, 09:02 PM
I got the latest code from Github and compiled and copied over, and decided to try out #spawn and #npcspawn create and #npcedit, but I am getting the oddest error when using #spawn and #npcspawn create.

I'll make a hotkey or manually type out the #spawn command:


#spawn WoodElf 4 25 0 - 1 0 0 0 0 1


Then manually type out:

#npcspawn create


And I'll get the following error in red in my chat window:


08-01-2015 :: 17:41:11] [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("WoodElf", 25, 4, 0, 723, 1, 0, 0, 0.000000, 0, 0, 0, 0.000000, 28, -1508384059)


The last value is for a byte, and should be 28 like prim_melee_type, and not just because it's in the spawn struct that way, but because it's actually been -hard coded- that way:


zone/npc.cpp - Line 1059-1066

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, spawn->GetRunspeed(), 28, 28);
auto results = QueryDatabase(query);


How in the world is sec_melee_type getting set to an arbitrary negative int32? I checked and double-checked the number of fields and values being passed, made sure there are as many %s/%i/%f format specifiers as arguments being supplied to StringFormat, and I'm just scratching my head.

I tried it both without (above) and with (below) the #npcspawn create extra parameter of 1:


[08-01-2015 :: 18:05:01] [MySQL Error] 1264: Out of range value for column 'sec_melee_type' at row 1
INSERT INTO npc_types (id, name, level, race, class, hp, gender, texture, helmtexture, size, loottable_id, merchant_id, face, runspeed, prim_melee_type, sec_melee_type) VALUES(54308, "WoodElf" , 25, 4, 0, 723, 1, 0, 0, 0.000000, 0, 0, 0, 0.000000, 28, -1508384059)


Anybody have an idea?

Kingly_Krab
08-01-2015, 11:39 PM
Spawn works like this: #spawn [name] [race] [level] [material] [hp] [gender] [class] [priweapon] [secweapon] [merchantid]
You're doing #spawn WoodElf 4 25 0 - 1 0 0 0 0 1
So "WoodElf" Name, Wood Elf Race, Level 25, 0 Material, - Hp, 1 Gender, 0 class, 0 Primary, 0 Secondary, 1 Merchant ID.

Shendare
08-02-2015, 12:51 AM
That's close, but #spawn help is saying:


Format: #spawn name race level material hp gender class priweapon secweapon merchantid bodytype


The only difference is bodytype at the end. You missed a 0 between that and gender 1. I seem to be feeding the parameters correctly.

I thought maybe class 0 was the problem, since there is no class 0, but changing it to 1 for warrior didn't make a difference.

Kingly_Krab
08-02-2015, 01:12 AM
Regardless, an additional parameter is not the issue. You're passing the minus symbol (-) as the value for hp, which could be an issue. I know I don't have any issues making NPCs.

Shendare
08-02-2015, 01:33 AM
The minus symbol tells it to calculate the NPC's MaxHP based on its level. It's calculating it to 723, so that feature's working okay.

I'm experimenting with StringFormat and MessageBox now, to figure out when the last arg changes from 28 to an arbitrary value.

You know what the weird thing is? I changed the affected line in the source (npc.cpp line 1052) from:


spawn->MerchantType, 0, spawn->GetRunspeed(), 28, 28);


...to:


spawn->MerchantType, 0, spawn->GetRunspeed(), 28, 28, 0);


The query runs as:


INSERT INTO npc_types (id, name, level, race, class, hp, gender, texture, helmtexture, size, loottable_id, merchant_id, face, runspeed, prim_melee_type, sec_melee_type) VALUES(54308, "WoodElf" , 25, 4, 0, 723, 1, 0, 0, 0.000000, 0, 0, 0, 0.000000, 28, 0)

And when I change the line to:


spawn->MerchantType, 0, spawn->GetRunspeed(), 28, 28, 28);


...it gets run successfully as:


INSERT INTO npc_types (id, name, level, race, class, hp, gender, texture, helmtexture, size, loottable_id, merchant_id, face, runspeed, prim_melee_type, sec_melee_type) VALUES(54308, "WoodElf" , 25, 4, 0, 723, 1, 0, 0, 0.000000, 0, 0, 0, 0.000000, 28, 28)

Something funky is going on after that first 28. It's skipping over an argument after it.

Shendare
08-02-2015, 01:52 AM
Through chatting, KK and I figured out that the code is trying to pass GetRunSpeed() as a float in the format string ("%f"), when it's actually an integer, and my Visual Studio 2013 is b0rking at that mismatch.

Changing that %f to %i in both query format strings fixes the problem. Too weird.

Shendare
08-02-2015, 02:22 AM
A couple more glitches in #npc create are causing problems.

spawngroupid and npc_type_id aren't being set in the spawn struct when they're created in the database, so the values for those in the Mob class are zeroes.

Fixes with these three new lines:

zone/npc.cpp:

@@ -1076,6 +1076,9 @@ uint32 ZoneDatabase::CreateNewNPCCommand(const char *zone, uint32 zone_version,
return false;
}
uint32 spawngroupid = results.LastInsertedID();

+ spawn->SetSp2(spawngroupid);
+ spawn->SetNPCTypeID(npc_type_id);

query = StringFormat("INSERT INTO spawn2 (zone, version, x, y, z, respawntime, heading, spawngroupID) "
"VALUES('%s', %u, %f, %f, %f, %i, %f, %i)",


zone/mob.h

@@ -431,6 +431,7 @@ public:
((static_cast<float>(cur_mana) / max_mana) * 100); }
virtual int32 CalcMaxMana();
uint32 GetNPCTypeID() const { return npctype_id; }
+ void SetNPCTypeID(uint32 npctypeid) { npctype_id = npctypeid; }
inline const glm::vec4& GetPosition() const { return m_Position; }
inline const float GetX() const { return m_Position.x; }
inline const float GetY() const { return m_Position.y; }

Shendare
08-02-2015, 03:48 AM
And all fixed. Akkadius is the man.

https://github.com/EQEmu/Server/commit/a04e78cfd1001e1e4e0f766c9d122fd954d35b4b