Creature Game Object Interaction

I need to code a creature to activate a game object and then reset it(a door, for instance, so that the npc can pass through it and then quickly close it after them), when it casts a certain spell / does a certain action. How can I write this? The way I see it, there should be something like "me->ActivateObject(door) or “me->ResetObject(…)”, though it’s most likely far-fetched /emoticons/default_smile.png.

Any thoughts?

chapter1.cpp line 191-208 should help you

GameObject::UseDoorOrButton() (ResetDoorOrButton() should be similar)

there might be other solutions

Tried this:

me->GetGameObject(155421 /*object GUID*/)->UseDoorOrButton();

and it crashes the server. Guess I’m missing some arguments to those functions…

Don’t you use an IDE? Visual Studio or similar… it helps.

And object GUID isn’t the same as the DB guid or DB entry

I use VC++ 2010 to compile, although I write the scripts in Notepad++, because I find it lighter and a little more resourceful. However, VC++ compiled my code without errors, but the game won’t stop crashing when I test it. Gotta look into those GameObject structures a little deeper…

It’s really dumb to use Notepad++. Using VS would allow you to use Ctrl + J and shows errors whenever you make them. /emoticons/default_smile.png

I believe you, I use NP++ because it allows me to cycle through tabs easily, so I can open more .cpp files simultaneously. VC++ would probably do the same, but given the conditions under which I run it (I’m also running the server, WoW, SQLYog etc) it slows down my machine more than I can sometimes stand.

Nevertheless, on-topic, I’ve tried lots of pieces of code found both among my server scripts and on the Internet:

//One thing I tried, the 2nd argument of the GetGO function is the object's ingame GUID

GameObject *obj =  GameObject::GetGameObject(*me, 155416);


//The other thing I tried, same GUID argument


//Also tried the above ones with the object DB entry instead of its GUID

However, nothing has worked. My server keeps crashing when the creature should interact with the game object the way I scripted it. Thus, does anybody have any 100% working syntax?

Close WoW and SQLYog and run the goddamn IDE; it will tell you if the parameters you are passing are right or not.

Moreover, take another look to the chapter1.cpp that I pointed out above.

=> GameObject* obj = me->FindNearestGameObject(, ) => if (obj) obj->Reset/UseDoorOrButton();

Basically, if you don’t know how to script something, it has been scripted by someone else, you just have to find it. To do so, use your gaming knowledge /emoticons/default_tongue.png

Nay’s code worked. Thanks for the advice, btw, I’m only still learning /emoticons/default_smile.png