forked from 666netz/trinity_scripts_335a
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NPC_Teleport_Database.cpp
242 lines (240 loc) · 9.88 KB
/
NPC_Teleport_Database.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
NPC_Teleport_Database
testet: 3.3.5a
stand: 01.11.2016
SET @CREATURTEMPLATE_ENTRY = 96004;
SET @CREATURTEMPLATE_NAME = "TeleportViaDatabase NPC";
SET @CREATURTEMPLATE_SUBNAME = "Darkstanley Inc.";
SET @CREATURTEMPLATE_MODELID = 24978;
DELETE FROM world.creature WHERE id = @CREATURTEMPLATE_ENTRY;
DELETE FROM world.creature_template WHERE entry = @CREATURTEMPLATE_ENTRY;
INSERT INTO world.creature_template (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `scale`, `rank`, `dmgschool`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `spell1`, `spell2`, `spell3`, `spell4`, `spell5`, `spell6`, `spell7`, `spell8`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `InhabitType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `DamageModifier`, `ExperienceModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES
(@CREATURTEMPLATE_ENTRY, 0, 0, 0, 0, 0, @CREATURTEMPLATE_MODELID, 0, 0, 0, @CREATURTEMPLATE_NAME, @CREATURTEMPLATE_SUBNAME, 'Directions', 0, 80, 80, 0, 35, 3, 1, 1.14286, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '', 0, 3, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 'NPC_Teleport_Database', 0);
*/
// ******************************************************************************
// namespace
// ******************************************************************************
using namespace std;
// ******************************************************************************
// class
// ******************************************************************************
class NPC_Teleport_Database : public CreatureScript
{
// ******************************************************************************
// public
// ******************************************************************************
public: NPC_Teleport_Database() : CreatureScript("NPC_Teleport_Database") { }
// ******************************************************************************
// init
// ******************************************************************************
struct DBvector
{
uint32 id;
float position_x;
float position_y;
float position_z;
float orientation;
uint32 map;
string name;
string icon;
};
vector<DBvector> NPC_Teleport_Database_DATAMYSQL;
uint32 StartIndex = 0;
// ---
// ******************************************************************************
// OnGossipHello
// ******************************************************************************
bool OnGossipHello(Player* player, Creature* creature) override
{
ClearGossipMenuFor(player);
AddGossipItemFor(player, GOSSIP_ICON_TAXI, "|cff000000|TInterface\\icons\\Spell_Arcane_PortalShattrath:30:30:-18|t aus 'game_tele'|r", GOSSIP_SENDER_MAIN, 105);
AddGossipItemFor(player, GOSSIP_ICON_TAXI, "|cff000000|TInterface\\icons\\Spell_Arcane_PortalShattrath:30:30:-18|t aus 'areatrigger_teleport'|r", GOSSIP_SENDER_MAIN, 110);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|cff000000|TInterface\\buttons\\UI-GroupLoot-Pass-Down:30:30:-18|t auf Wiedersehen|r", GOSSIP_SENDER_MAIN, 999);
SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
return true;
}//OnGossipHello
// ******************************************************************************
// OnGossipSelect
// ******************************************************************************
bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action) override
{
if (sender == GOSSIP_SENDER_MAIN)
{
// --- verlassen
if (action == 999)
{
creature->Say("Auf Wiedersehen.", LANG_UNIVERSAL, NULL);
ClearGossipMenuFor(player);
CloseGossipMenuFor(player);
return true;
}
// --- im Kampf
if (player->IsInCombat())
{
creature->Say("Du befindest Dich in einem Kampf. Da kann ich Dir nicht helfen !", LANG_UNIVERSAL, NULL);
ClearGossipMenuFor(player);
CloseGossipMenuFor(player);
return true;
}
// --- Hauptmenu (Option 1)
if (action == 105)
{
string Tabelle = "game_tele";
FN_getMYSQL(Tabelle);
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- Hauptmenu (Option 2)
if (action == 110)
{
string Tabelle = "areatrigger_teleport";
FN_getMYSQL(Tabelle);
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- Submenu (abbruch)
if (action == 99997)
{
StartIndex = 0;
CloseGossipMenuFor(player);
OnGossipHello(player, creature);
return true;
}
// --- Submenu (weiter)
if (action == 99998)
{
StartIndex = StartIndex + 25;
if (StartIndex > NPC_Teleport_Database_DATAMYSQL.size())
StartIndex = 0;
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- Submenu (zurueck)
if (action == 99999)
{
StartIndex = StartIndex - 25;
if (StartIndex < 1)
StartIndex = 0;
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- Submenu (auswahl)
if (action >= 10000 && action < 99997)
{
uint32 i = (action - 10000);
if (i <= 0) {
creature->Say("Diesen Ort kenne ich garnicht !", LANG_UNIVERSAL, NULL);
ClearGossipMenuFor(player);
CloseGossipMenuFor(player);
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
creature->Say("Ich habe Dich teleportiert.", LANG_UNIVERSAL, NULL);
player->TeleportTo(NPC_Teleport_Database_DATAMYSQL[i].map, NPC_Teleport_Database_DATAMYSQL[i].position_x, NPC_Teleport_Database_DATAMYSQL[i].position_y, NPC_Teleport_Database_DATAMYSQL[i].position_z, NPC_Teleport_Database_DATAMYSQL[i].orientation);
ClearGossipMenuFor(player);
CloseGossipMenuFor(player);
return true;
}
}//if sender
}//OnGossipSelect
// ******************************************************************************
// OnGossipSelect_Sub
// ******************************************************************************
bool OnGossipSelect_Sub(Player* player, Creature* creature, uint32 StartIndex)
{
ClearGossipMenuFor(player);
uint32 zaehler = 0;
uint32 MaxIndex = NPC_Teleport_Database_DATAMYSQL.size();
for (uint32 i = StartIndex; i < MaxIndex; i++)
{
// ---
AddGossipItemFor(player, GOSSIP_ICON_TAXI, "|cff000000|t " + NPC_Teleport_Database_DATAMYSQL[i].name + "|r", GOSSIP_SENDER_MAIN, 10000 + i);
// ---
zaehler = zaehler + 1;
if (zaehler == 25)
{
StartIndex = i;
break;
}//if
}//for
if (StartIndex > 25)
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|cff000000|TInterface\\buttons\\UI-SpellbookIcon-PrevPage-Up:30:30:-18|t zurueck|r", GOSSIP_SENDER_MAIN, 99999);
if (StartIndex < MaxIndex)
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|cff000000|TInterface\\buttons\\UI-SpellbookIcon-NextPage-Up:30:30:-18|t weiter|r", GOSSIP_SENDER_MAIN, 99998);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|cff000000|TInterface\\buttons\\UI-SpellbookIcon-PrevPage-Up:30:30:-18|t Hauptmenu|r", GOSSIP_SENDER_MAIN, 99997);
SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
return true;
};//OnGossipSelect_Sub
// ******************************************************************************
// FN_getMYSQL
// ******************************************************************************
void FN_getMYSQL(string tTabelle)
{
NPC_Teleport_Database_DATAMYSQL.clear();
// ---
if (tTabelle == "game_tele")
{
QueryResult result = WorldDatabase.PQuery("SELECT id,position_x,position_y,position_z,orientation,map,name FROM world.game_tele ORDER BY name ASC");
if (result)
{
Field * fields = NULL;
do
{
fields = result->Fetch();
DBvector data;
if (fields[6].GetString().length() > 2)
{
data.id = fields[0].GetUInt32();
data.position_x = fields[1].GetFloat();
data.position_y = fields[2].GetFloat();
data.position_z = fields[3].GetFloat();
data.orientation = fields[4].GetFloat();
data.map = fields[5].GetUInt32();
data.name = fields[6].GetString();
NPC_Teleport_Database_DATAMYSQL.push_back(data);
}//if gueltig
} while (result->NextRow());
}
else
{
TC_LOG_ERROR("misc", "DATABASE ERROR - NPC_Teleport_Database");
}
}//if game_tele
// ---
if (tTabelle == "areatrigger_teleport")
{
QueryResult result = WorldDatabase.PQuery("SELECT ID,Name,target_map,target_position_x,target_position_y,target_position_z,target_orientation FROM world.areatrigger_teleport ORDER BY Name ASC");
if (result)
{
Field * fields = NULL;
do
{
fields = result->Fetch();
DBvector data;
if (fields[1].GetString().length() > 2)
{
data.id = fields[0].GetUInt32();
data.position_x = fields[3].GetFloat();
data.position_y = fields[4].GetFloat();
data.position_z = fields[5].GetFloat();
data.orientation = fields[6].GetFloat();
data.map = fields[2].GetUInt32();
data.name = fields[1].GetString();
NPC_Teleport_Database_DATAMYSQL.push_back(data);
}//if gueltig
} while (result->NextRow());
}
else
{
TC_LOG_ERROR("misc", "DATABASE ERROR - NPC_Teleport_Database");
}
}//if areatrigger_teleport
}//FN_getMYSQL
};
// ******************************************************************************
// AddSC_...
// ******************************************************************************
void AddSC_NPC_Teleport_Database()
{
new NPC_Teleport_Database();
};