Looking for some help with a script

Trying to make this bit of code pull a value from world.characters db, and set that as characters scale.

Under player.cpp

bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) <— below this bool

[CODE]
// set which actionbars the client has active - DO NOT REMOVE EVER AGAIN (can be changed though, if it does change fieldwise)
SetByteValue(PLAYER_FIELD_BYTES, 2, fields[65].GetUInt8());

/* Start Permanent Morph Mod */
//InitDisplayIds(); <- old setting

QueryResult result2 = CharacterDatabase.PQuery("SELECT morph FROM character_morph WHERE guid = %u", fields[0].GetUInt32());
if(result2)
{
    Field *fields2 = result2->Fetch();
    SetNativeDisplayId(fields2[0].GetUInt32());
    SetDisplayId(fields2[0].GetUInt32());
}
else
    InitDisplayIds();

/* End Permanent Morph Mod */

// Start Scale system
QueryResult result3 = CharacterDatabase.PQuery("SELECT scale FROM character_scale WHERE guid = %u", fields[0].GetFloat());
if(result3)
{
    Field* fields3 = result3->Fetch();
    SetFloatValue(OBJECT_FIELD_SCALE_X, fields[0].GetFloat());
}
else
    CharacterDatabase.PExecute("REPLACE INTO `character_scale` VALUES (%u, 1, 'Default Scale');", guid);
    SetFloatValue(OBJECT_FIELD_SCALE_X, 1.0f);

// End Scale System[/CODE]

It’s skipping the

Field* fields3 = result3->Fetch();
SetFloatValue(OBJECT_FIELD_SCALE_X, fields[0].GetFloat());
And writing to db on logout

else
CharacterDatabase.PExecute(“REPLACE INTO character_scale VALUES (%u, 1, ‘Default Scale’);”, guid);
SetFloatValue(OBJECT_FIELD_SCALE_X, 1.0f);
The morph mod works just fine, only the scale one is giving me trouble.

QueryResult result3 = CharacterDatabase.PQuery(“SELECT scale FROM character_scale WHERE guid = %u”, fields[0].GetFloat());
[COLOR=rgb(102,102,0)]shouldnt it be

QueryResult result3 = CharacterDatabase.PQuery(“SELECT scale FROM character_scale WHERE guid = %u”, fields[0].GetUInt32());
character guid is not a float.

Ahh. I see… I thought I had to put that so I could use…

SetFloatValue(OBJECT_FIELD_SCALE_X, fields[0].GetFloat());
So it should really be…

// Start Scale system
QueryResult result3 = CharacterDatabase.PQuery(“SELECT scale FROM character_scale WHERE guid = %u”, fields[0].GetUInt32());
if(result3)
{
Field* fields3 = result3->Fetch();
SetFloatValue(OBJECT_FIELD_SCALE_X, fields3[0].GetUInt32());
}
else
CharacterDatabase.PExecute(“REPLACE INTO character_scale VALUES (%u, 1, ‘Default Scale’);”, guid);
SetFloatValue(OBJECT_FIELD_SCALE_X, 1.0f);

// End Scale System

If I’m understanding correctly?

No. the fields is the main character field. when you what you get the scale from the db you need the guid. then when you have that number you can set the scale field.

[CODE]
// Start Scale system
QueryResult result3 = CharacterDatabase.PQuery(“SELECT scale FROM character_scale WHERE guid = %u”, guid);
if(result3)
{
Field* fields3 = result3->Fetch();
SetFloatValue(OBJECT_FIELD_SCALE_X, fields3[0].GetFloat());
}
else
{
CharacterDatabase.PExecute(“REPLACE INTO character_scale VALUES (%u, 1, ‘Default Scale’);”, guid);
SetFloatValue(OBJECT_FIELD_SCALE_X, 1.0f);
}

// End Scale System[/CODE]

Thank you again for the response and help. That partially worked for me, and I think I understand it a little better now. It is no longer skipping straight to

else
{
CharacterDatabase.PExecute(“REPLACE INTO character_scale VALUES (%u, 1, ‘Default Scale’);”, guid);
SetFloatValue(OBJECT_FIELD_SCALE_X, 1.0f);
}
And writing that value to DB world.characters character_scale. I’m not positive why, but it is not setting the scale correctly though.

When Table is set…

http://i779.photobucket.com/albums/yy76/arioch69/Capture_zps999834a2.png

On login, you are set to Scale 1 still… instead of 3…

After, I did try changing the code again too…

// Start Scale system
QueryResult result3 = CharacterDatabase.PQuery(“SELECT scale FROM character_scale WHERE guid = %u”, guid);
if(result3)
{
Field* fields3 = result3->Fetch();
float plrScale;
plrScale = fields3[0].GetFloat();
SetFloatValue(OBJECT_FIELD_SCALE_X, plrScale);
}
else
{
CharacterDatabase.PExecute(“REPLACE INTO character_scale VALUES (%u, 1, ‘Default Scale’);”, guid);
SetFloatValue(OBJECT_FIELD_SCALE_X, 1.0f);
}
// End Scale System
But that produced the same result…

I got it… Code was fine, just placed in the wrong area… I’ll upload the whole thing as patch, and a management npc for it as soon as I get a chance to apply to a clean trinitycore and make a patch.

Patch can be found here.

http://www.trinitycore.org/f/topic/9156-permanent-scale-and-morph-system/