This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: [SOLVED] [QUESTION] TC2. Script executed after loot.  (Read 1557 times)

Daweo

  • Registred Member
  • Race Changer
  • *****
  • Posts: 39
    • View Profile
[SOLVED] [QUESTION] TC2. Script executed after loot.
« on: March 23, 2013, 07:20:37 am »
Hi, Modcraft. Is there any function for calling commands for GO after player loots chest? I have chest and I want to execute my script after looting. But the script is executed either before loot or does not work anyway. I used calling OnGossipHello() function and some condition for lootstates but doesnt work. Then I used OnLootStateChanged() function but this one doesnt execute my script (normal loot and then do nothnig). Can You help me please? Sorry for my english...
« Last Edit: March 23, 2013, 10:12:03 pm by Admin »

Ascathos

  • Moderators
  • Creator of Worlds
  • *****
  • Posts: 1129
    • View Profile
Re: [QUESTION] TC2. Script executed after loot.
« Reply #1 on: March 23, 2013, 12:44:55 pm »
I assume you talk about TrinityCore ? Could you please provide your basic code, maybe I have an idea how to do it.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Daweo

  • Registred Member
  • Race Changer
  • *****
  • Posts: 39
    • View Profile
Re: [QUESTION] TC2. Script executed after loot.
« Reply #2 on: March 23, 2013, 01:17:23 pm »
Here you go. I wanna make chest, which will be lootable only once and then will be deleted.
I tried this same script only with OnGossipHello() but it will only delete object without any loot.

Code: [Select]
#include "ScriptPCH.h"
#include "ScriptMgr.h"
#include "GameObject.h"
#include "LootMgr.h"

class despawn_script : public GameObjectScript
{
    public:

        despawn_script()
            : GameObjectScript("despawn_script")
{
}
bool OnLootStateChanged(GameObject* go, LootState* state, Player* player)
{
if (go->getLootState() == GO_JUST_DEACTIVATED)
{
go->SetRespawnTime(0);
go->Delete();
go->DeleteFromDB();
}
return true;
}

};

void AddSC_despawn_script()
{
    new despawn_script();
}
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Ascathos

  • Moderators
  • Creator of Worlds
  • *****
  • Posts: 1129
    • View Profile
Re: [QUESTION] TC2. Script executed after loot.
« Reply #3 on: March 23, 2013, 03:54:42 pm »
I reworked that a little. No idea if it works, but it may.

Code: [Select]
#include "GameObject.h"
#include "LootMgr.h"
#include "ScriptPCH.h"
#include "ScriptMgr.h"

class despawn_script : public GameObjectScript
{
    public:

        despawn_script()
            : GameObjectScript("despawn_script")
         {
         }
         bool OnLootStateChanged(GameObject* go, LootState* state, Player* player)
            {
               if (go->getLootState() == GO_JUST_DEACTIVATED && go->GetGoType() == 3)
               {
                  go->SetRespawnTime(0);
                  go->Delete();
                  go->DeleteFromDB();
               }
               return true;
            }
               
};

void AddSC_despawn_script()
{
    new despawn_script();
}

Try this.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Daweo

  • Registred Member
  • Race Changer
  • *****
  • Posts: 39
    • View Profile
Re: [QUESTION] TC2. Script executed after loot.
« Reply #4 on: March 23, 2013, 04:19:22 pm »
It does not work. I think there is not problem in condition or commands but in calling function... :-/
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Ascathos

  • Moderators
  • Creator of Worlds
  • *****
  • Posts: 1129
    • View Profile
Re: [QUESTION] TC2. Script executed after loot.
« Reply #5 on: March 23, 2013, 04:49:11 pm »
Did you add it as script for the gob?
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Daweo

  • Registred Member
  • Race Changer
  • *****
  • Posts: 39
    • View Profile
Re: [QUESTION] TC2. Script executed after loot.
« Reply #6 on: March 23, 2013, 05:01:50 pm »
I added this script to core (Custom script, ScriptLoader, etc.).  Then I added the script name for my chest. I know what i have to do when I want execute this script but the script doesnt do anything. There is problem in calling... You can normally loot the chest but nothing from script is done. That means that the script is not called by this on-function....
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Daweo

  • Registred Member
  • Race Changer
  • *****
  • Posts: 39
    • View Profile
[SOLVED] Re: [QUESTION] TC2. Script executed after loot.
« Reply #7 on: March 23, 2013, 10:07:26 pm »
I solved my problem. The main problem was that I am begginer in C++ and I did not see my mistake in calling function. For someone can be interesting changing of lootstate when you are looting.
Code: [Select]
States go in order:
GO_ACTIVATED - You open loot table and take items
O_JUST_DEACTIVATED - The loot table is closed and object come invisible
GO_NOT_READY - GameObject waits for respawn, is invisible (not for GM)
GO_READY - Gameobject waits for looter...

Thank Ascathos for help very much... :)

There is code which can maybe help somebody...
Code: [Select]
#include "ScriptPCH.h"
#include "ScriptMgr.h"
#include "GameObject.h"
#include "LootMgr.h"

class despawn_script : public GameObjectScript
{
    public:

        despawn_script()
            : GameObjectScript("despawn_script")
{
}
void OnLootStateChanged(GameObject* go, uint32 state, Unit* player)
{
switch (go->getLootState())
{
case GO_NOT_READY:
{
sLog->outString("GO_NOT_READY");
break;
}
case GO_READY:
{
sLog->outString("GO_READY");
break;
}
case GO_ACTIVATED:
{
sLog->outString("GO_ACTIVATED");
break;
}
case GO_JUST_DEACTIVATED:
{
sLog->outString("GO_JUST_DEACTIVATED");
}
}
}
};

void AddSC_despawn_script()
{
    new despawn_script();
}
« Last Edit: January 01, 1970, 01:00:00 am by Admin »