-
Notifications
You must be signed in to change notification settings - Fork 0
/
merlinsRezHelper.lua
616 lines (526 loc) · 18.7 KB
/
merlinsRezHelper.lua
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
local LAM2 = LibAddonMenu2
local FAKETAG = 'MERLINS_REZHELPER_FAKE'
local AddonVersion = '2.1.0'
local NextPlayer = ''
local state = {
Hidden = true,
ForceBeam = false,
SetCloseIcon = false,
Angle = 0,
Linear = 0,
AbsoluteLinear = 0,
DX = 0,
DY = 0,
Color = { R = 1, G = 1, B = 1 },
Alpha = 0,
Size = 0,
Colors = nil,
Mode = nil,
Leader = nil,
Player = nil,
Settings = nil,
Constants = {
GameReticleSize = 58
}
}
local defaultSettings = {
Mode = 'Satnav',
Colors = 'Green Orange Red',
MinAlpha = 0.5,
MaxAlpha = 0.9,
MinSize = 50,
MaxSize = 60,
MinDistance = 0,
MaxDistance = 128,
PvPOnly = false,
Mimic = true,
Debug = false,
RangeLimit = false,
CloseIcon = true,
Sound = 'DUEL_WON',
LeaderArrowSize = false,
LeaderArrowDistance = true,
LeaderArrowNumeric = false
}
local lightReference = nil
-- **************** UTILS ****************
local function NormalizeAngle(c)
if c > math.pi then return c - 2 * math.pi end
if c < -math.pi then return c + 2 * math.pi end
return c
end
-- **************** ENTITIES ****************
local function UpdatePlayerEntity(entity)
if entity == nil then return end
if entity.Tag == FAKETAG then return end
entity.X, entity.Y, entity.Z = GetMapPlayerPosition(entity.Tag)
entity.Zone = GetUnitZone(entity.Tag)
entity.Name = GetUnitName(entity.Tag)
end
local function CheckLeader()
if state.Leader and state.Leader.Custom then return end
local newLeader = GetGroupLeaderUnitTag()
if newLeader == nil or newLeader == '' then
state.Leader = nil
elseif state.Leader == nil or state.Leader.Tag ~= newLeader then
state.Leader = {
Tag = newLeader
}
end
end
-- **************** UI ****************
local function UpdateReticle()
if state.Player == nil then return end
if (state.Leader == nil) or
(state.Settings.PvPOnly and not IsInAvAZone()) or
(state.Settings.Mimic and ZO_ReticleContainer:IsHidden() == true) or
(IsUnitGrouped('player') == false) then
-- state.Hidden = true
HideLight()
else
-- state.Hidden = false
state.DX = state.Player.X - state.Leader.X
state.DY = state.Player.Y - state.Leader.Y
state.D = math.sqrt((state.DX * state.DX) + (state.DY * state.DY))
state.Angle = NormalizeAngle(state.Player.H - math.atan2( state.DX, state.DY ))
state.Linear = state.Angle / math.pi
state.AbsoluteLinear = math.abs(state.Linear)
state.Alpha = state.Settings.MinAlpha + (state.Settings.MaxAlpha - state.Settings.MinAlpha) * state.AbsoluteLinear;
if state.Settings.LeaderArrowSize then
state.Size = state.Settings.MinSize + (state.Settings.MaxSize - state.Settings.MinSize) * (math.tanh(state.D * 40 - 1) + 1.0) / 2.0;
else
state.Size = state.Settings.MinSize + (state.Settings.MaxSize - state.Settings.MinSize) * state.AbsoluteLinear;
end
if state.Settings.LeaderArrowDistance then
state.Distance = state.Settings.MinDistance + (state.Settings.MaxDistance - state.Settings.MinDistance) * (math.tanh(state.D * 40 - 1) + 1.0) / 2.0;
else
state.Distance = state.Settings.MinDistance + (state.Settings.MaxDistance - state.Settings.MinDistance) * state.AbsoluteLinear;
end
ShowLight()
end
state.Colors:Update(state)
state.Mode:Update(state)
end
function CreateLight()
if state.Settings.Beam == true then
local wm = GetWindowManager()
lightReference = wm:CreateTopLevelWindow("playerPosition")
lightReference:SetDrawTier(0)
lightReference:SetDrawLayer(0)
lightReference:SetDrawLevel(0)
lightReference.texture = wm:CreateControl("light", lightReference, CT_TEXTURE)
lightReference.texture:SetTexture("MerlinsRezHelper/textures/Beam.dds")
lightReference:Create3DRenderSpace()
lightReference.texture:Create3DRenderSpace()
lightReference.texture:Set3DLocalDimensions(1, 256)
lightReference.texture:SetDrawLevel(3)
lightReference.texture:SetColor(1,1,1,1)
lightReference.texture:SetParent(lightReference)
lightReference:Set3DRenderSpaceOrigin(0,0,0)
HideLight()
end
end
function TestLight()
--TTTest()
d("Testing - /reloadui to remove the beam strip. No beam visible? Then this area is not supported yet.")
local x, y, z = GetMapPlayerPosition("player")
CalcLightPos(x, y)
lightReference:SetHidden(false)
state.ForceBeam = true
end
function ShowLight()
if state.Settings.Beam == true then
if (Lib3D ~= nil and state.Leader ~= nil and state.Leader.X ~= nil and state.Leader.Y ~= nil and state.Hidden ~= true) then
CalcLightPos(state.Leader.X, state.Leader.Y)
lightReference:SetHidden(false)
end
end
end
function CalcLightPos(x, y)
-- Parent Frame
local Wx, Wz = Lib3D:GlobalToWorld(Lib3D:GetCurrentWorldOriginAsGlobal())
lightReference:Set3DRenderSpaceOrigin(Wx, 0, Wz)
-- Beam
local worldX, worldZ = nil, nil
worldX, worldZ = Lib3D:LocalToWorld(x, y)
local _, height, _ = Lib3D:GetCameraRenderSpacePosition()
if worldX ~= nil and worldZ ~= nil then
worldX, _, worldZ = WorldPositionToGuiRender3DPosition(worldX * 100, 0, worldZ * 100)
end
lightReference.texture:Set3DRenderSpaceOrigin(worldX, height, worldZ)
-- Ausrichtung
local heading = GetPlayerCameraHeading()
if heading > math.pi then
heading = heading - 2 * math.pi
end
lightReference.texture:Set3DRenderSpaceOrientation(0, heading, 0)
end
function TTTest()
local playerX, playerY = GetMapPlayerPosition("player")
if playerX ~= nil and playerY ~= nil and playerX ~= 0 and playerY ~= 0 then
local x, y = nil, nil
local _, worldX, height, worldY = GetUnitWorldPosition("player")
x, y = Lib3D:LocalToWorld(playerX, playerY)
worldX, worldHeight, worldY = WorldPositionToGuiRender3DPosition(worldX, height, worldY)
if x ~= nil and y ~= nil then
x, height, y = WorldPositionToGuiRender3DPosition(x * 100, height, y * 100)
end
--lightReference.texture:Set3DRenderSpaceOrigin(worldX, worldHeight, worldY)
--lightReference.texture:Set3DRenderSpaceOrigin(x, height, y)
end
end
function HideLight()
if lightReference ~= nil and state.Hidden ~= false and state.ForceBeam == false then
lightReference:SetHidden(true)
end
end
-- **************** EVENTS ****************
-- onUpdate trigger
function merlinsRezHelperUpdate()
if state.Player == nil then return end
-- 2Do check for nearest group member and set "as leader"
GetClosestMember()
UpdatePlayerEntity(state.Player)
local h = NormalizeAngle(GetPlayerCameraHeading())
if h ~= nil then state.Player.H = h end
CheckLeader()
UpdatePlayerEntity(state.Leader)
if state.Leader == nil or state.Leader.X == nil or state.Leader.Y == nil then state.Leader = nil end
if state.Leader == nil or state.Leader.Name == state.Player.Name then state.Leader = nil end
UpdateReticle()
end
function GetClosestMember()
local currentTag
local currentName
local currentDistance
local closestPlayer = ''
local someoneIsDead = false
local closestDistance = 1000000
local maxDistance = 0.1
local closeDistance = 0.002
if (IsInAvAZone()) then
closeDistance = (closeDistance/10)
maxDistance = (maxDistance/10)
end
-- if in group
if IsUnitGrouped('player') == true then
-- foreach groupmember
for xmemberid = 1, GetGroupSize(), 1 do
currentTag = GetGroupUnitTagByIndex(xmemberid)
currentName = GetUnitName(currentTag)
-- if death and online and in the same zone OR debug
if ((IsUnitDead(currentTag) and
IsUnitBeingResurrected(currentTag)==false and
DoesUnitHaveResurrectPending(currentTag)==false and
IsUnitReincarnating(currentTag)==false and
IsUnitOnline(currentTag)==true and
GetUnitZone(currentTag) == GetUnitZone("player") and
(GetUnitName("player") ~= GetUnitName(currentTag))
) or state.Settings.Debug == true
) then
-- get position
currentDistance = CalcDistance(currentTag);
-- d(currentDistance)
-- dont show location of to far away members
if (currentDistance<maxDistance or state.Settings.RangeLimit ~= true) and currentDistance ~= 0 and currentDistance ~= nil then
-- some one in range is dead and its not you
someoneIsDead = true
-- override if its closer
if currentDistance<closestDistance then
closestPlayer = currentName
closestDistance = currentDistance
if (currentDistance<closeDistance and state.Settings.CloseIcon == true) then
state.SetCloseIcon = true
else
state.SetCloseIcon = false
end
end
end
end
end
if someoneIsDead then
state.Hidden = false
else
state.Hidden = true
end
if (closestPlayer ~= '') and (NextPlayer ~= closestPlayer) then
NextPlayer = closestPlayer
SetCustomLeader(closestPlayer)
end
-- hide if mouse shown / on menu interface
if (state.Settings.Mimic and ZO_ReticleContainer:IsHidden() == true) then
state.Hidden = true
end
end
end
function CalcDistance(memberTag)
playerX, playerY, playerZ = GetMapPlayerPosition('player')
memberX, memberY, memberZ = GetMapPlayerPosition(memberTag)
calcDX = playerX - memberX
calcDY = playerY - memberY
return math.sqrt((calcDX * calcDX) + (calcDY * calcDY))
end
local function FakeIt(text)
state.Leader = {
Tag = 'player'
}
UpdatePlayerEntity(state.Leader)
state.Leader.Tag = FAKETAG
state.Leader.Name = FAKETAG
state.Leader.Custom = true
--d("Leader faked.")
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NONE, GetString(SI_EXTGL_LEADER_FAKED))
end
function OnSetTargettedLeader()
SetCustomLeader(GetUnitNameHighlightedByReticle())
end
-- Slash command for custom follow target ( /glset = set to default group leader - /glset <charname> = set to custom person )
function SetCustomLeader(text)
if IsUnitGrouped('player') == false then
--d("You must be in a group to set a follow target.")
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NONE, GetString(SI_GROUPELECTIONFAILURE8))
return
end
if text == "" then
state.Leader.Custom = false
else
for xmemberid = 1, GetGroupSize(), 1 do
if string.lower(text) == string.lower(GetUnitName(GetGroupUnitTagByIndex(xmemberid))) then
--d("Successfully set '" .. text .. "' as follow target.")
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS[state.Settings.Sound], zo_strformat("<<1>> <<2>> <<3>>", GetString(SI_EXTGL_FOLLOW_TARGET1), text , GetString(SI_EXTGL_FOLLOW_TARGET2)))
state.Leader = {
Tag = GetGroupUnitTagByIndex(xmemberid)
}
UpdatePlayerEntity(state.Leader)
state.Leader.Tag = GetGroupUnitTagByIndex(xmemberid)
state.Leader.Name = GetUnitName(GetGroupUnitTagByIndex(xmember))
state.Leader.Custom = true
else
--d("ZERO MATCH ON - ".. text .. " = " .. GetUnitName(GetGroupUnitTagByIndex(xmemberid)))
end
end
if not state.Leader.Custom then
--d("Could not find anyone named '" .. text .. "' in your group.")
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NONE, zo_strformat("<<1>> <<2>> <<3>>", GetString(SI_EXTGL_NO_TARGET_FOUND1), text , GetString(SI_EXTGL_NO_TARGET_FOUND2)))
end
end
end
--Find out if your follow target has left the group and if so notify and set leader to nil
local function OnPlayerLeft(leftmemberName, reason, wasLocalPlayer)
if IsUnitGrouped('player') == false then return end -- Ignore if you just left the group
if state.Leader == nil then return end
local doesCustomExist = false
for xmemberid = 1, GetGroupSize() , 1 do
if GetGroupUnitTagByIndex(xmemberid) == state.Leader.Tag then
doesCustomExist = true
end
end
if not doesCustomExist then
--d("Your follow target has left the group. Now following group leader.")
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NONE, GetString(SI_EXTGL_FOLLOW_TARGET_LEFT))
state.Leader = nil
end
end
local function InitializePlugin()
state.Player = {
Tag = 'player'
}
CreateLight()
end
-- **************** SETTINGS ****************
local function LoadSettings()
merlinsRezHelperSettings = merlinsRezHelperSettings or {}
state.Settings = MERLINS_REZHELPER.Extend(merlinsRezHelperSettings, defaultSettings)
end
local function ChangeMode(value)
state.Settings.Mode = value
if state.Mode then state.Mode:Unit() end
state.Mode = MERLINS_REZHELPER.Modes[value]
state.Mode.Init()
end
local function ChangeColors(value)
state.Settings.Colors = value
if state.Colors then state.Colors:Unit() end
state.Colors = MERLINS_REZHELPER.Colors[value]
state.Colors.Init()
end
local function CreateSettingsMenu()
local colorYellow = "|cFFFF22"
local panelData = {
type = "panel",
name = "Merlins Rez Helper",
displayName = colorYellow.."Merlin's|r Rez Helper",
author = "@Just_Merlin",
version = AddonVersion,
slashCommand = "/merlinsRezHelper",
registerForRefresh = true,
registerForDefaults = true,
}
local cntrlOptionsPanel = LAM2:RegisterAddonPanel("merlinsRezHelper_Options", panelData)
local optionsData = {
[1] = {
type = "description",
text = colorYellow.."Merlin's|r Rez Helper",
},
[2] = {
type = "dropdown",
name = GetString(SI_EXTGL_STYLE_MODE),
choices = {"Elastic Reticle Arrows", "Satnav", "Reticle Satnav"},
default = "Elastic Reticle Arrows",
getFunc = function() return state.Settings.Mode end,
setFunc = function(bValue) ChangeMode(bValue) end,
},
[3] = {
type = "dropdown",
name = GetString(SI_EXTGL_STYLE_COLOR),
tooltip = GetString(SI_EXTGL_STYLE_COLOR_TOOLTIP),
choices = MERLINS_REZHELPER.Colors.Plugins,
default = "Always White",
getFunc = function() return state.Settings.Colors end,
setFunc = function(bValue) ChangeColors(bValue) end
},
[4] = {
type = "slider",
name = GetString(SI_EXTGL_STYLE_TARGET_OPACITY),
tooltip = GetString(SI_EXTGL_STYLE_TARGET_OPACITY_TOOLTIP),
min = 0,
max = 100,
step = 1,
default = 50,
getFunc = function() return (state.Settings.MinAlpha * 100) end,
setFunc = function(iValue) state.Settings.MinAlpha = (iValue / 100) end,
},
[5] = {
type = "slider",
name = GetString(SI_EXTGL_STYLE_BEHIND_OPACITY),
tooltip = GetString(SI_EXTGL_STYLE_BEHIND_OPACITY_TOOLTIP),
min = 0,
max = 100,
step = 1,
default = 50,
getFunc = function() return state.Settings.MaxAlpha * 100 end,
setFunc = function(iValue) state.Settings.MaxAlpha = (iValue / 100) end,
},
[6] = {
type = "slider",
name = GetString(SI_EXTGL_STYLE_TARGET_SIZE),
tooltip = GetString(SI_EXTGL_STYLE_TARGET_SIZE_TOOLTIP),
min = 0,
max = 64,
step = 2,
default = 32,
getFunc = function() return state.Settings.MinSize end,
setFunc = function(iValue) state.Settings.MinSize = iValue end,
},
[7] = {
type = "slider",
name = GetString(SI_EXTGL_STYLE_BEHIND_SIZE),
tooltip = GetString(SI_EXTGL_STYLE_BEHIND_SIZE_TOOLTIP),
min = 0,
max = 64,
step = 2,
default = 48,
getFunc = function() return state.Settings.MaxSize end,
setFunc = function(iValue) state.Settings.MaxSize = iValue end,
},
[8] = {
type = "slider",
name = GetString(SI_EXTGL_STYLE_TARGET_DISTANCE),
tooltip = GetString(SI_EXTGL_STYLE_TARGET_DISTANCE_TOOLTIP),
min = 0,
max = 512,
step = 1,
default = 256,
getFunc = function() return state.Settings.MinDistance end,
setFunc = function(iValue) state.Settings.MinDistance = iValue end,
},
[9] = {
type = "slider",
name = GetString(SI_EXTGL_STYLE_BEHIND_DISTANCE),
tooltip = GetString(SI_EXTGL_STYLE_BEHIND_DISTANCE_TOOLTIP),
min = 0,
max = 512,
step = 1,
default = 256,
getFunc = function() return state.Settings.MaxDistance end,
setFunc = function(iValue) state.Settings.MaxDistance = iValue end,
},
[10] = {
type = "dropdown",
name = GetString(SI_EXTGL_STYLE_SOUND),
choices = {"NONE", "DUEL_WON", "ELDER_SCROLL_CAPTURED_BY_ALDMERI", "SKILL_XP_DARK_ANCHOR_CLOSED", "VOICE_CHAT_MENU_CHANNEL_JOINED"},
default = "DUEL_WON",
getFunc = function() return state.Settings.Sound end,
setFunc = function(selected)
state.Settings.Sound = selected
PlaySound(SOUNDS[selected])
end,
},
[11] = {
type = "checkbox",
name = GetString(SI_EXTGL_STYLE_BEAM),
tooltip = GetString(SI_EXTGL_STYLE_BEAM_TOOLTIP),
default = true,
getFunc = function() return state.Settings.Beam end,
setFunc = function(bValue) state.Settings.Beam = bValue end
},
[12] = {
type = "checkbox",
name = GetString(SI_EXTGL_STYLE_DEBUG),
tooltip = GetString(SI_EXTGL_STYLE_DEBUG_TOOLTIP),
default = false,
getFunc = function() return state.Settings.Debug end,
setFunc = function(bValue) state.Settings.Debug = bValue end
},
[13] = {
type = "description",
text = colorYellow..GetString(SI_EXTGL_STYLE_LEADER_DISTANCE),
},
[14] = {
type = "checkbox",
name = GetString(SI_EXTGL_STYLE_ARROW_SIZE),
tooltip = GetString(SI_EXTGL_STYLE_ARROW_SIZE_TOOLTIP),
default = true,
getFunc = function() return state.Settings.LeaderArrowSize end,
setFunc = function(bValue) state.Settings.LeaderArrowSize = bValue end
},
[15] = {
type = "checkbox",
name = GetString(SI_EXTGL_STYLE_ARROW_DISTANCE),
tooltip = GetString(SI_EXTGL_STYLE_ARROW_DISTANCE_TOOLTIP),
default = true,
getFunc = function() return state.Settings.LeaderArrowDistance end,
setFunc = function(bValue) state.Settings.LeaderArrowDistance = bValue end
},
[16] = {
type = "checkbox",
name = GetString(SI_EXTGL_STYLE_CLOSE_ICON),
tooltip = GetString(SI_EXTGL_STYLE_CLOSE_ICON_TOOLTIP),
default = true,
getFunc = function() return state.Settings.CloseIcon end,
setFunc = function(bValue) state.Settings.CloseIcon = bValue end
},
[17] = {
type = "checkbox",
name = GetString(SI_EXTGL_STYLE_RANGE_LIMIT).." (Beta)",
tooltip = GetString(SI_EXTGL_STYLE_RANGE_LIMIT_TOOLTIP),
default = false,
getFunc = function() return state.Settings.RangeLimit end,
setFunc = function(bValue) state.Settings.RangeLimit = bValue end
},
}
LAM2:RegisterOptionControls("merlinsRezHelper_Options", optionsData)
end
local function OnPluginLoaded(event, addon)
if addon ~= "merlinsRezHelper" then return end
LoadSettings()
CreateSettingsMenu()
ChangeMode(state.Settings.Mode)
ChangeColors(state.Settings.Colors)
InitializePlugin()
-- SLASH_COMMANDS["/glfake"] = FakeIt
-- SLASH_COMMANDS["/glset"] = SetCustomLeader
SLASH_COMMANDS["/beam"] = TestLight
end
EVENT_MANAGER:RegisterForEvent("merlinsRezHelper", EVENT_ADD_ON_LOADED, OnPluginLoaded)
EVENT_MANAGER:RegisterForEvent("merlinsRezHelper", EVENT_GROUP_MEMBER_LEFT, OnPlayerLeft)