If you're here for the solution: here it is.
Final Edit: Okay so I figured out the problem. I thought I was overwriting TTT's SendPlayerRoles method (by overwriting the method that calls this) but it turns out I wasn't. The method is this:
local function SendPlayerRoles()
for k, v in pairs(player.GetAll()) do
net.Start("TTT_Role")
net.WriteUInt(v:GetRole(), 2)
net.Send(v)
end
end
and since my role numbers require more than 2 bits, I overwrote it to contain 5. Turns out it wasn't overwriting and still sending with 2 bits, which is not enough to send my numbers. Changing this function to
local function SendPlayerRoles()
for k, v in pairs(player.GetAll()) do
net.Start("TTT_Role")
net.WriteUInt(v:GetRole(), 5)
net.Send(v)
end
end
makes everything work again.
I'm currently writing an addon that adds several custom roles to TTT, and I'm having an issue syncing the roles between Server/Client.
Right now, I have it so when they player joins, the server sends them a net message with all the current roles, and it is sending properly, I've checked:
0:
Alignment = Innocent
Color:
a = 200
b = 25
g = 200
r = 25
ID = 0
Limit = false
LimitNum = -1
Name = Innocent
Percent = -1
RequiredPlayers = -1
1:
Alignment = Traitor
Color:
a = 200
b = 25
g = 25
r = 200
ID = 1
Limit = false
LimitNum = -1
Name = Traitor
Percent = 0.15
RequiredPlayers = -1
2:
Alignment = Innocent
Color:
a = 200
b = 200
g = 25
r = 25
ID = 2
Limit = false
LimitNum = -1
Name = Detective
Percent = 0.1
RequiredPlayers = 6
3:
Alignment = None
Color:
a = 200
b = 180
g = 105
r = 255
ID = 3
Limit = true
LimitNum = 1
Name = Jester
Percent = -1
RequiredPlayers = 8
4:
Alignment = Innocent
Color:
a = 200
b = 250
g = 206
r = 135
ID = 4
Limit = false
LimitNum = -1
Name = Phoenix
Percent = 0.15
RequiredPlayers = 5
5:
Alignment = Innocent
Color:
a = 200
b = 255
g = 153
r = 204
ID = 5
Limit = false
LimitNum = -1
Name = Doctor
Percent = 0.13
RequiredPlayers = -1
6:
Alignment = Neutral
Color:
a = 200
b = 38
g = 118
r = 245
ID = 6
Limit = true
LimitNum = 1
Name = Arsonist
Percent = -1
RequiredPlayers = 10
Now, each role has their own ID, which is equivalent to ROLE_<role_name_upper>:
ROLE_INNOCENT = 0
ROLE_TRAITOR = 1
ROLE_DETECTIVE = 2
ROLE_JESTER = 3
ROLE_PHOENIX = 4
ROLE_DOCTOR = 5
ROLE_ARSONIST = 6
ROLE_NONE = ROLE_INNOCENT
However, I'm having issues with only one of these roles: the Jester:
3:
Alignment = None
Color:
a = 200
b = 180
g = 105
r = 255
ID = 3
Limit = true
LimitNum = 1
Name = Jester
Percent = -1
RequiredPlayers = 8
As you can see, this role's ID is 3, because ROLE_JESTER = 3. However, when TTT is looking for the translation name of the role (which I have specified in english.lua), it says "Translation of nil not found".
When I did some digging, I found something strange. Basically, when TTT tries to put the translated role name there:
-- cl_hud.lua
text = L[client:GetRoleStringRaw()]
-- player_ext_shd.lua
local role_strings = {
[ROLE_TRAITOR] = "traitor",
[ROLE_INNOCENT] = "innocent",
[ROLE_DETECTIVE] = "detective",
[ROLE_JESTER] = "jester",
[ROLE_PHOENIX] = "phoenix",
[ROLE_DOCTOR] = "doctor",
[ROLE_ARSONIST] = "arsonist"
}
function plymeta:GetRoleStringRaw()
return role_strings[self:GetRole()]
end
so I edited this a little, added this line:
function plymeta:GetRoleStringRaw()
MsgN(self:GetRole())
return role_strings[self:GetRole()]
end
And, when I'm Jester, it print's "7" over and over (in Yellow text, so on the Client), when it should be "3". I edited the role_strings to be this:
local role_strings = {
[ROLE_TRAITOR] = "traitor",
[ROLE_INNOCENT] = "innocent",
[ROLE_DETECTIVE] = "detective",
[ROLE_JESTER + 4] = "jester",
[ROLE_PHOENIX] = "phoenix",
[ROLE_DOCTOR] = "doctor",
[ROLE_ARSONIST] = "arsonist"
}
And things worked just fine. The only issue with this, though, is when I add a new role, their ID will be 7 and will mess with that.
Why is it that, on the server, ROLE_JESTER == 3, and on this part, client:GetRole() returns 7?
Also, I have overwritten the plymeta:GetRole() function to be this:
function plymeta:GetRole()
return self.role.ID
end
so it
SHOULD return 3 for Jester, but it doesn't. Can someone help me please?
TL;DR:
] lua_run print(player.GetByID(1):GetRole())
> print(player.GetByID(1):GetRole())...
3
] lua_run player.GetByID(1):SendLua("print(LocalPlayer():GetRole())")
> player.GetByID(1):SendLua("print(LocalPlayer():GetRole())")...
7
Why are those not the same?
EDIT: Okay so I think I've found my issue. I think my GetRole() and SetRole(role) functions aren't overwriting TTT's. Going to try to put those in an Initialize hook so they activate after TTT has loaded.
EDIT2: Just after I wrote that I figured that probably isn't the case because all the other roles work -_- I could really use some help here.
EDIT3: Just to clarify again, anything that checks if a person is a Jester only works if I check for GetRole() + 4.
Final Edit: Okay so I figured out the problem. I thought I was overwriting TTT's SendPlayerRoles method (by overwriting the method that calls this) but it turns out I wasn't. The method is this:
local function SendPlayerRoles()
for k, v in pairs(player.GetAll()) do
net.Start("TTT_Role")
net.WriteUInt(v:GetRole(), 2)
net.Send(v)
end
end
and since my role numbers require more than 2 bits, I overwrote it to contain 5. Turns out it wasn't overwriting and still sending with 2 bits, which is not enough to send my numbers. Changing this function to
local function SendPlayerRoles()
for k, v in pairs(player.GetAll()) do
net.Start("TTT_Role")
net.WriteUInt(v:GetRole(), 5)
net.Send(v)
end
end
makes everything work again.