-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathrenamer.lua
More file actions
112 lines (97 loc) · 3.81 KB
/
Copy pathrenamer.lua
File metadata and controls
112 lines (97 loc) · 3.81 KB
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
--[[
TEO DOES NOT CARE PUBLIC LICENSE
Version 1, July 18 2016
Copyright (C) 2016 TeoTwawki <https://github.com/TeoTwawki>
Everyone is permitted to copy and distribute verbatim or modified copies of this
license document, and changing it is allowed as long as the name is changed and
you neither claim nor imply it or the associated code to be your original work.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
1. You may not represent the license or code this license applies to as your original work.
This condition DOES NOT apply to any changes you make.
2. Nothing! Do whatever you want!
TEO DOES NOT CARE!
]]--
_addon.author = "TeoTwawki & atom0s";
_addon.name = "renamer";
_addon.version = "1.1";
require("common")
require("mathex")
local renamer =
{
listFile = nil;
active = false;
}
ashita.register_event("command", function(cmd, nType)
local args = cmd:args();
if (#args <= 1 or args[1] ~= "/renamer") then
return false;
end
-- Display current list, if we have one loaded.
if (#args == 2 and args[2] == "status") then
if (renamer.listFile ~= nil) then
print(string.format("Renamer: names from '%s' currently loaded.", renamer.listFile));
else
print("Renamer: renaming is not active.");
end
return true;
end
-- Stop the addon.
if (#args == 2 and (args[2] == "stop" or args[2] == "unload")) then
renamer.active = false;
renamer.listFile = nil;
print("Renamer: renaming stopped.");
return true;
end
if (#args == 2 and args[2] == "load") then
print(string.format("Renamer: You must specify a file to load names from."));
return false;
end
-- Load the list.
if (#args == 3 and args[3] ~= nil and args[2] == "load") then
-- if (io.open("lists/" .. args[3],"r") ~= nil) then
package.loaded["lists/" .. args[3]] = nil;
require("lists/" .. args[3]);
renamer.active = true;
print(string.format("Renamer: names from file '%s' loaded.", args[3]));
if (renamer.listFile == nil) then
print("Renamer: renaming activated.");
end
renamer.listFile = args[3];
return true;
--[[
else
print(string.format("Renamer: file '%s' not found.", args[3]));
return false;
end
]]
end
print("Usage:");
print(" /renamer status");
print(" Displays current loaded list, if any.");
print(" /renamer load filename");
print(" Load specified list file.");
print(" /renamer unload (or) /renamer stop");
print(" Stop renaming and unload the list.");
return false;
end);
ashita.register_event("prerender", function()
-- Don't run this if a name list isn't loaded!
if (renamer.active == true) then
local zone_id = AshitaCore:GetDataManager():GetParty():GetMemberZone(0);
local targetObject = ObjectList[zone_id];
if (targetObject ~= nil) then
for _, v in pairs(targetObject) do
-- Obtain the short ID (Nth object of zone) from its long ID (dat file index number).
local index = bit.band(v[1], 0x0FFF);
-- Getting the zone was considered to, but that"s too much extra
-- processing so we specify zone IDs in our name lists instead.
AshitaCore:GetDataManager():GetEntity():SetName(index, v[2]); -- Set entity name.
end
end
end
--[[
Downside to this is it is called pretty constantly.
It IS possible to get the objects in the clients memory as it sees them, and rename them on the spot.
However we currently have no method to do that via ashita"s lua scripts.
]]
end);