virusav
28.09.2011, 14:40
Есть случаи, когда при открытии меню должно срабатывать действие в зависимости от разных условий.
Патч во вложении, дубль кодом:
diff --git a/src/game/GossipDef.h b/src/game/GossipDef.h
index 9e46bb2..163ae28 100644
--- a/src/game/GossipDef.h
+++ b/src/game/GossipDef.h
@@ -49,6 +49,7 @@ enum Gossip_Option
GOSSIP_OPTION_ARMORER = 15, //UNIT_NPC_FLAG_ARMORER (4096)
GOSSIP_OPTION_UNLEARNTALENTS = 16, //UNIT_NPC_FLAG_TRAINER (16) (bonus option for GOSSIP_OPTION_TRAINER)
GOSSIP_OPTION_UNLEARNPETSKILLS = 17, //UNIT_NPC_FLAG_TRAINER (16) (bonus option for GOSSIP_OPTION_TRAINER)
+ GOSSIP_OPTION_AUTOSCRIPT = 18,
GOSSIP_OPTION_MAX
};
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
index a8591ba..828a8ed 100644
--- a/src/game/ObjectMgr.cpp
+++ b/src/game/ObjectMgr.cpp
@@ -8737,9 +8737,9 @@ void ObjectMgr::LoadGossipMenuItems()
if (gMenuItem.action_script_id)
{
- if (gMenuItem.option_id != GOSSIP_OPTION_GOSSIP)
+ if (gMenuItem.option_id != GOSSIP_OPTION_GOSSIP && gMenuItem.option_id != GOSSIP_OPTION_AUTOSCRIPT)
{
- sLog.outErrorDb("Table gossip_menu_option for menu %u, id %u have action_script_id %u but option_id is not GOSSIP_OPTION_GOSSIP, ignoring", gMenuItem.menu_id, gMenuItem.id, gMenuItem.action_script_id);
+ sLog.outErrorDb("Table gossip_menu_option for menu %u, id %u have action_script_id %u but option_id is not GOSSIP_OPTION_GOSSIP and is not GOSSIP_OPTION_AUTOSCRIPT, ignoring", gMenuItem.menu_id, gMenuItem.id, gMenuItem.action_script_id);
continue;
}
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index d4e246e..ea3ab39 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -13011,6 +13011,9 @@ void Player::PrepareGossipMenu(WorldObject *pSource, uint32 menuId)
canSeeQuests = false;
continue;
}
+
+ if (itr->second.option_id == GOSSIP_OPTION_AUTOSCRIPT)
+ GetMap()->ScriptsStart(sGossipScripts, itr->second.action_script_id, this, pSource);
}
if (pSource->GetTypeId() == TYPEID_UNIT)
Запросы для теста патча:
UPDATE `gameobject_template` SET `data3`=2211 WHERE `entry`=160445;
DELETE FROM `gossip_menu_option` WHERE `menu_id`=2211;
DELETE FROM `gossip_scripts` WHERE `id` IN (2211,6540,7);
REPLACE INTO `gossip_menu_option` (`menu_id`, `id`, `option_icon`, `option_text`, `option_id`, `npc_option_npcflag`, `action_menu_id`, `action_poi_id`, `action_script_id`, `box_coded`, `box_money`, `box_text`, `cond_1`, `cond_1_val_1`, `cond_1_val_2`, `cond_2`, `cond_2_val_1`, `cond_2_val_2`, `cond_3`, `cond_3_val_1`, `cond_3_val_2`) VALUES
(2211, 0, 0, NULL, 18, 1, -1, 0, 2211, 0, 0, NULL, 9, 3821, 0, 0, 0, 0, 0, 0, 0),
(2211, 1, 0, NULL, 18, 1, -1, 0, 6540, 0, 0, NULL, 22, 3821, 0, 0, 0, 0, 0, 0, 0),
(2211, 2, 0, 'Я не служитель культа, ты, монстр! Иди сюда и встреть свою погибель!', 1, 1, -1, 0, 7, 0, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0);
REPLACE INTO `gossip_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `comments`) VALUES
(2211, 1, 10, 9136, 60000, 0, 0, 1, 0, 0, 0, 0, -7917.38, -2610.53, 221.123, 5.04026, ''),
(7, 1, 15, 25035, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ''),
(6540, 1, 15, 24803, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '');
В таком варианте:
1. При наличии квеста 3821 - суммон нпц.
2. При отсутствии квеста 3821 - каст спелла.
3. Пункты меню выводятся независимо от автоскриптов.
Патч во вложении, дубль кодом:
diff --git a/src/game/GossipDef.h b/src/game/GossipDef.h
index 9e46bb2..163ae28 100644
--- a/src/game/GossipDef.h
+++ b/src/game/GossipDef.h
@@ -49,6 +49,7 @@ enum Gossip_Option
GOSSIP_OPTION_ARMORER = 15, //UNIT_NPC_FLAG_ARMORER (4096)
GOSSIP_OPTION_UNLEARNTALENTS = 16, //UNIT_NPC_FLAG_TRAINER (16) (bonus option for GOSSIP_OPTION_TRAINER)
GOSSIP_OPTION_UNLEARNPETSKILLS = 17, //UNIT_NPC_FLAG_TRAINER (16) (bonus option for GOSSIP_OPTION_TRAINER)
+ GOSSIP_OPTION_AUTOSCRIPT = 18,
GOSSIP_OPTION_MAX
};
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
index a8591ba..828a8ed 100644
--- a/src/game/ObjectMgr.cpp
+++ b/src/game/ObjectMgr.cpp
@@ -8737,9 +8737,9 @@ void ObjectMgr::LoadGossipMenuItems()
if (gMenuItem.action_script_id)
{
- if (gMenuItem.option_id != GOSSIP_OPTION_GOSSIP)
+ if (gMenuItem.option_id != GOSSIP_OPTION_GOSSIP && gMenuItem.option_id != GOSSIP_OPTION_AUTOSCRIPT)
{
- sLog.outErrorDb("Table gossip_menu_option for menu %u, id %u have action_script_id %u but option_id is not GOSSIP_OPTION_GOSSIP, ignoring", gMenuItem.menu_id, gMenuItem.id, gMenuItem.action_script_id);
+ sLog.outErrorDb("Table gossip_menu_option for menu %u, id %u have action_script_id %u but option_id is not GOSSIP_OPTION_GOSSIP and is not GOSSIP_OPTION_AUTOSCRIPT, ignoring", gMenuItem.menu_id, gMenuItem.id, gMenuItem.action_script_id);
continue;
}
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index d4e246e..ea3ab39 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -13011,6 +13011,9 @@ void Player::PrepareGossipMenu(WorldObject *pSource, uint32 menuId)
canSeeQuests = false;
continue;
}
+
+ if (itr->second.option_id == GOSSIP_OPTION_AUTOSCRIPT)
+ GetMap()->ScriptsStart(sGossipScripts, itr->second.action_script_id, this, pSource);
}
if (pSource->GetTypeId() == TYPEID_UNIT)
Запросы для теста патча:
UPDATE `gameobject_template` SET `data3`=2211 WHERE `entry`=160445;
DELETE FROM `gossip_menu_option` WHERE `menu_id`=2211;
DELETE FROM `gossip_scripts` WHERE `id` IN (2211,6540,7);
REPLACE INTO `gossip_menu_option` (`menu_id`, `id`, `option_icon`, `option_text`, `option_id`, `npc_option_npcflag`, `action_menu_id`, `action_poi_id`, `action_script_id`, `box_coded`, `box_money`, `box_text`, `cond_1`, `cond_1_val_1`, `cond_1_val_2`, `cond_2`, `cond_2_val_1`, `cond_2_val_2`, `cond_3`, `cond_3_val_1`, `cond_3_val_2`) VALUES
(2211, 0, 0, NULL, 18, 1, -1, 0, 2211, 0, 0, NULL, 9, 3821, 0, 0, 0, 0, 0, 0, 0),
(2211, 1, 0, NULL, 18, 1, -1, 0, 6540, 0, 0, NULL, 22, 3821, 0, 0, 0, 0, 0, 0, 0),
(2211, 2, 0, 'Я не служитель культа, ты, монстр! Иди сюда и встреть свою погибель!', 1, 1, -1, 0, 7, 0, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0);
REPLACE INTO `gossip_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `comments`) VALUES
(2211, 1, 10, 9136, 60000, 0, 0, 1, 0, 0, 0, 0, -7917.38, -2610.53, 221.123, 5.04026, ''),
(7, 1, 15, 25035, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ''),
(6540, 1, 15, 24803, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '');
В таком варианте:
1. При наличии квеста 3821 - суммон нпц.
2. При отсутствии квеста 3821 - каст спелла.
3. Пункты меню выводятся независимо от автоскриптов.