miifi Posted January 24, 2019 Report Share Posted January 24, 2019 (edited) I basically have a script, that let's me learn spells from an NPC, but if I am mounted, it doesn't let me learn spells ________________________________ if (player->IsMounted()) { player->GetSession()->SendAreaTriggerMessage("|cff87CEFAYou must get down of your mount.|r"); CloseGossipMenuFor(player); return false; } ________________________________ I would like to turn the "if mounted" into a "if sql table has 30 or more rows" I imagine it would be something like this, but I don't know the exact coding for it ________________________________ int a = SELECT COUNT(*) FROM characters_spells if (int a >= 30) { player->GetSession()->SendAreaTriggerMessage("|cff87CEFAYou must get down of your mount.|r"); CloseGossipMenuFor(player); return false; } ________________________________ Can anyone help out with the code for it please? Edited January 24, 2019 by miifi Link to comment Share on other sites More sharing options...
Rochet2 Posted January 24, 2019 Report Share Posted January 24, 2019 It would be best to avoid SQL queries if you can. However as you asked for an example of how to make this query, here is one: #include "DatabaseEnv.h" int64 count = CharacterDatabase.PQuery("SELECT COUNT(*) FROM characters_spells WHERE guid = %u", player->GetGUID().GetCounter())->Fetch()[0].GetInt64(); if (count >= 30) { } In this code - the include allows you to use CharacterDatabase variable, which is a global variable. - PQuery makes a database query and allows you to use printf like syntax to format variables into the SQL. - GetCounter returns the part of the guid that is usually used in DB for players and items to identify them. - Fetch returns the current row from the query result, we call this directly as we know that a result will be returned from this specific SQL. - [0] accesses the first column in the query result. In this case it is the count. - GetInt64() takes the column data and handles it as an int64 value. Most math in SQL is done with bigint, so using uint32 or similar may actually not work on some machines. Always use proper type! - the resulting value is stored into a variable "count" and then compared against 30. Link to comment Share on other sites More sharing options...
Recommended Posts