Jump to content

Script object activating


Guest dlxxxko

Recommended Posts

Please I need one small help if someone want to help me :tinysmile_fatgrin_t

I make script with extern variable (uint32) in boss script and I want to open object when this variable get

some number. I tested it external variable is OK, and get in instance script right value too but it doesn't do

anything :tinysmile_shutup_t2.

Instance script


#include "ScriptedPch.h"
#include "halls_of_reflection.h"

#define MAX_ENCOUNTER 3
[color="red"]extern int SendObjPkg;[/color]


/* Halls of Reflection encounters:
0- Falric
1- Marwyn
2- The Lich King
*/

struct instance_halls_of_reflection : public ScriptedInstance
{
   instance_halls_of_reflection(Map* pMap) : ScriptedInstance(pMap) {Initialize();};

   uint64 uiFalric;
   uint64 uiMarwyn;
   uint64 uiLichKing;

   uint32 m_auiEncounter[MAX_ENCOUNTER];

   void Initialize()
   {
       uiFalric = 0;
       uiMarwyn = 0;
       uiLichKing = 0;

       for (uint8 i = 0; i < MAX_ENCOUNTER; ++i)
           m_auiEncounter[i] = NOT_STARTED;
   }

   void OnCreatureCreate(Creature* pCreature, bool add)
   {
       switch(pCreature->GetEntry())
       {
           case CREATURE_FALRIC:
               uiFalric = pCreature->GetGUID();
               break;
           case CREATURE_MARWYN:
               uiMarwyn = pCreature->GetGUID();
               break;
           case CREATURE_LICHKING:
               uiLichKing = pCreature->GetGUID();
               break;    
       }
   }

   void OnGameObjectCreate(GameObject* pGo, bool add)
   {

   }



//   Here is my action =========================================


void Update(uint32 diff)
{


   if (SendObjPkg == 1)
       {

           HandleGameObject(222223,true);
           printf("one %d", SendObjPkg);

       }

       if (SendObjPkg == 2)
       {
           HandleGameObject(222224,true);
           printf("two %d", SendObjPkg);

       }

       if (SendObjPkg == 3)
       {
           HandleGameObject(222224,false);
           printf("three %d", SendObjPkg);

       }

       if (SendObjPkg == 4)
       {
           HandleGameObject(222223,false);
           printf("four %d", SendObjPkg);

       }

    }

// =====================================================



   void SetData(uint32 type, uint32 data)
   {
    }

   uint32 GetData(uint32 type)
   {
       switch(type)
       {
           case DATA_FALRIC_EVENT:         return m_auiEncounter[0];
           case DATA_MARWYN_EVENT:         return m_auiEncounter[1];
           case DATA_LICHKING_EVENT:       return m_auiEncounter[2];
       }

       return 0;
   }
/*
   uint64 GetData64(uint32 identifier)
   {
       switch(identifier)
       {
       }

       return 0;
   }
*/
   std::string GetSaveData()
   {
       OUT_SAVE_INST_DATA;

       std::ostringstream saveStream;
       saveStream << "H R " << m_auiEncounter[0] << " " << m_auiEncounter[1] << m_auiEncounter[2];

       OUT_SAVE_INST_DATA_COMPLETE;
       return saveStream.str();
   }

   void Load(const char* in)
   {
       if (!in)
       {
           OUT_LOAD_INST_DATA_FAIL;
           return;
       }

       OUT_LOAD_INST_DATA(in);

       char dataHead1, dataHead2;
       uint16 data0, data1, data2;

       std::istringstream loadStream(in);
       loadStream >> dataHead1 >> dataHead2 >> data0 >> data1 >> data2;

       if (dataHead1 == 'H' && dataHead2 == 'R')
       {
           m_auiEncounter[0] = data0;
           m_auiEncounter[1] = data1;
           m_auiEncounter[2] = data2;

           for (uint8 i = 0; i < MAX_ENCOUNTER; ++i)
               if (m_auiEncounter[i] == IN_PROGRESS)
                   m_auiEncounter[i] = NOT_STARTED;

       } else OUT_LOAD_INST_DATA_FAIL;

       OUT_LOAD_INST_DATA_COMPLETE;
   }
};

InstanceData* GetInstanceData_instance_halls_of_reflection(Map* pMap)
{
   return new instance_halls_of_reflection(pMap);
}

void AddSC_instance_halls_of_reflection()
{
   Script *newscript;
   newscript = new Script;
   newscript->Name = "instance_halls_of_reflection";
   newscript->GetInstanceData = &GetInstanceData_instance_halls_of_reflection;
   newscript->RegisterSelf();
}

Thanks for Everything ...

Link to comment
Share on other sites

do not use global variables, store as member variable instead and access through instance data

oh, and instance scripts dont have Update() callback, if you need to call a function from "outside" use:

// assuming you defined m_pInstance as most scripts do
if (instance_halls_of_reflection *inst = dynamic_cast<instance_halls_of_reflection*>(m_pInstance))
   inst->YourCustomFunctionCall();

Link to comment
Share on other sites

Thanks for your reply.

I think this is not problem becouse function Update() works me :)

I make debug and it write printf("one %d", SendObjPkg); approximately every one second with nuber one >>> correct value ....

But function HandleGameObject(222224,true); do nothing but it passed with no error...

Your help is for me a bit difficualt can you give me some example? Thanks you !

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use