View Full Version : [SOLVED] Error with queryresult C++

03-27-2014, 01:56 PM
Hi people, I have an error when try to add a queryresult:

The code:

The idea is a trigger that summons a creature if a player stay in the trigger 20 seconds. This works perfect but the problem is when I add the query result looking for a mob with id 5000 in creature table (NOT creature_template). WorldServer crash when Im near the npc who have the scriptname. Worldserver crash thanks to:

//Look for in DB a mob with id = 5000
QueryResult comprobar_mob = WorldDatabase.PQuery("SELECT id FROM creature WHERE `id` = 5000"); //Worl Server crash if there aren't entry 5000 in "creature"

Because if there aren't npcs with entry 5000 crash (I tried with an existing id and dont crash.)

The idea is that if this npc (id 5000) is already summoned the trigger does nothing. If not, the trigger will summon it...


Regards, Eleinder.

03-27-2014, 02:05 PM
Try again with after the QueryResult

03-27-2014, 02:16 PM
New code: http://paste2.org/ZEKwPgaJ

Same result, worldserver crash.

Thanks for your answer.

03-27-2014, 02:38 PM
You need to do the check RIGHT after querying. Before you use comprobar_mob.

Note that tickTimer is not set to anything so it crashes if you use it before you set it.

//Maybe check if there are >=1 creatures with id 5000
You can use comprobar_mob->GetRowCount() to get rows.
that code you have just gets the ID, so 5000.

03-27-2014, 06:51 PM
I think I dont understand you 'cause worldserver still crash:

Code: http://paste2.org/VKzaxhYP

But thanks for the answer.

PD: Any example how to set up correctly the timer?

03-27-2014, 07:06 PM
Are you planning on using the query to query actual mobs by 'me->GetEntry()', rather than setting the 'id' yourself? If not, there's really no need in having a query at all. Use 'Query' instead of 'PQuery' because 'PQuery' allows you to supply different params, whilst 'Query' lets you query like you're doing now. Not entirely familiar with how you're using your timer variable. Why are you incrementing instead of decrementing?

Try this:

class endless_games_dynamic_events_1 : public CreatureScript
endless_games_dynamic_events_1() : CreatureScript("endless_games_dynamic_events_1") { }

struct endless_games_dynamic_events_1AI : public ScriptedAI
endless_games_dynamic_events_1AI(Creature* creature) : ScriptedAI(creature) { }

uint32 tickTimer;

void Reset()
tickTimer = 20000;

void UpdateAI(uint32 diff)
//Look for in DB a mob with id = 5000
QueryResult result = WorldDatabase.Query("SELECT id FROM creature WHERE `id` = 5000"); //Worl Server crash if there aren't entry 5000 in "creature"
if(!result) // Check before continuing HERE
tickTimer = 20000;

Field* fields = result->Fetch();
uint32 comprobador = fields[0].GetUInt32();

if (tickTimer <= diff) //time 20 seconds, working.
if (Player* player = me->SelectNearestPlayer(10.0f))
me->SummonCreature(5000, 1238.40f, -4417.21f, 23.20f, 0.36f, TEMPSUMMON_TIMED_DESPAWN, 15000); //summon a creature with ID 5000
//SaveToDb(); Maybe to solve WorldServer Error "Trying to delete not saved npc" that appears when you do .npc del (npc with id 5000), but dont know the function
std::ostringstream ss;
player->GetSession()->SendAreaTriggerMessage("Check 2"); //Only for check if this "else" is working or not
ss << "|cFF81CF42" << player->GetName() << "|r ha activado el evento dinamico .:Guerra Fria:. en la Isla de Muerte Gelida (5 jugadores recomendados)|cFFFFFFFF";
sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
tickTimer = 20000;
tickTimer -= diff;

CreatureAI* GetAI(Creature* creature) const
return new endless_games_dynamic_events_1AI(creature);

03-27-2014, 07:36 PM
Hmmmm I think you dont understand the idea of what I want to do. (It's my fault for not explaining it well). (The npc doesn't summon the creature after 20 sec.)

I want to do the next thing:
If the mob(id 5000) ISNīT in the world, the npc spawn this mob after 20 seconds but only if the player is in the trigger.
When the mob is summoned, if the player is into the trigger then should not happen anything, so the mod cant be summoned two times. (My basic english dont allow me explain correctly xD)

And timers are a pain in head for me, but I will take your example and I will apply it in my future scripts.

03-28-2014, 12:16 PM