View Full Version : [SOLVED] [Command] Scaling - learn purposes.

04-20-2015, 05:38 AM
Helo emudevs, i'm currently trying to learn a more about query's in C++ and trying to add a command .tool scale.

Here's the code:

Player* player = handler->GetSession()->GetPlayer();
QueryResult result;

result = WorldDatabase.PQuery("SELECT scale_id,scale_size,comment FROM custom_scale");

if (!result)
return false;

Field *fields = result->Fetch();
uint32 scale_id = fields[0].GetInt32();
uint32 scale_size = fields[1].GetInt32();
std::string comment = fields[2].GetString();


} while (result->NextRow());

I'm trying to get it to use a unique id if that makes sense. ( Ids only in scale_id )
for example .tool scale 100. ( 100 is the scale id and 100 will set the player scale to 1 or what ever i set it to in scale_size. )

04-20-2015, 07:01 AM
uint32 id = static_cast<uint32>(atol((char*)code)); // or how it goes ...

QueryResult result = WorldDatabase.PQuery("SELECT scale_size, comment FROM custom_scale WHERE scale_id = %u", id); // you already have the ID .. use it.

if (!result)
return false;

// single row queried. No loop needed.
// also you should make scale_id the primary key if it isnt yet.
Field *fields = result->Fetch();
uint32 scale_size = fields[0].GetInt32();
std::string comment = fields[1].GetString(); // needed?


04-20-2015, 10:37 PM
Thanks Rochet2, pretty much sums it up for me.