-
Notifications
You must be signed in to change notification settings - Fork 25
Role change events for Custom Roles #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 11 commits
0534a4c
01920fb
fa0c2f4
9bf26de
bf35935
26e61ec
9168279
acdce5a
cbebd64
dac675c
c24d003
1d818e2
4e27efc
563e2ed
de0e801
d6a944e
fa274a0
b3dd409
f7fc67d
5f20956
384a933
8d4a9c2
5b3a3db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -679,11 +679,45 @@ hook_Add("PlayerInitialSpawn", "PlayerInitialSpawn_RDM_Manager", function(ply) | |
| end) | ||
| end) | ||
|
|
||
| local function CheckRevive(ply) | ||
| if CR_VERSION and ply:IsRespawning() then | ||
| return true | ||
| elseif TTT2 and ply:IsReviving() then | ||
| return true | ||
| end | ||
| return false | ||
| end | ||
|
|
||
| hook_Add("PlayerDeath", "RDM_Manager", function(ply) | ||
|
|
||
| if GetRoundState() == ROUND_ACTIVE and (TTT2 or CR_VERSION) then | ||
| --Instant Respawn Cases | ||
| timer.Simple(1, function() | ||
| if ply:Alive() then return end | ||
| end) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't do anything? |
||
| -- Delayed Respawn Check | ||
| if CheckRevive(ply) then | ||
| net.Start("DL_Delayed") | ||
| net.Send(ply) | ||
|
|
||
| timer.Create("RDM_RespawnDelay_" .. ply:SteamID64(), 5, 1, function() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would 5 seconds be long enough for the respawn mechanics? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately role respawns vary and are often controlled by cvars so a flat 5 second timer may not work.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe instead, we should look at closing the report window if a player is respawned (and the round is active). If they've already started typing out a response, we should probably keep track of it.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I'm commonly seeing, there are 3 kinds of role respawns, The checks cover the first 2, while conditional has only 5-second grace before having to respond to reports. |
||
| net.Start("DL_Death") | ||
| net.Send(ply) | ||
| end) | ||
| return | ||
| end | ||
| end | ||
|
|
||
| net.Start("DL_Death") | ||
| net.Send(ply) | ||
| end) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could simplify this function to always wait 5 seconds before requesting that the dead player replies to their reports. |
||
|
|
||
| hook_Add("PlayerSpawn", "RDM_RespawnCancel", function(ply) | ||
| if timer.Exists("RDM_RespawnDelay_" .. ply:SteamID64()) then | ||
| timer.Remove("RDM_RespawnDelay_" .. ply:SteamID64()) | ||
| end | ||
| end) | ||
|
|
||
| hook_Add("TTTEndRound", "RDM_Manager", function() | ||
| net.Start("DL_Death") | ||
| net.Broadcast() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| if SERVER then | ||
| --Global Variables Unavailable? find how to hook later | ||
| --if CR_VERSION then | ||
| Damagelog:EventHook("TTTPlayerRoleChanged") | ||
| Damagelog:EventHook("TTTPlayerRoleChangedByItem") | ||
| Damagelog:EventHook("TTTPlayerSpawnForRound") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will these cause problems for the regular TTT or TTT2 gamemodes? |
||
| --elseif TTT2 then | ||
| --TODO | ||
| --else | ||
| --UNUSED | ||
| --end | ||
| else | ||
| Damagelog:AddFilter("filter_show_roles", DAMAGELOG_FILTER_BOOL, true) | ||
| Damagelog:AddColor("color_roles", Color(128, 64, 0)) | ||
| end | ||
| local event = {} | ||
| event.Type = "ROLE" | ||
|
|
||
| function event:TTTPlayerRoleChanged(ply, oldRole, newRole) | ||
| if oldRole == nil or oldRole == ROLE_NONE or oldRole == newRole or newRole == ROLE_NONE then return end | ||
| self.CallEvent({ | ||
| [1] = 1, | ||
| [2] = ply:GetDamagelogID(), | ||
| [3] = oldRole, | ||
| [4] = newRole | ||
| }) | ||
| Damagelog:UpdateRecentRole(ply, newRole) | ||
| end | ||
|
|
||
| function event:TTTPlayerRoleChangedByItem(ply, tgt, item) | ||
| if not IsValid(item) then return end | ||
| self.CallEvent({ | ||
| [1] = 2, | ||
| [2] = ply:GetDamagelogID(), | ||
| [3] = tgt:GetDamagelogID(), | ||
| [4] = IsEntity(item) and item:GetClass() or item | ||
| }) | ||
| end | ||
|
|
||
| function event:TTTPlayerSpawnForRound(ply, deadOnly) | ||
| self.CallEvent({ | ||
| [1] = 3, | ||
| [2] = ply:GetDamagelogID(), | ||
| }) | ||
| end | ||
|
|
||
|
|
||
| function event:ToString(v, roles) | ||
| local ply = Damagelog:InfoFromID(roles, v[2]) | ||
|
|
||
| if v[1] == 1 then | ||
| return string.format(TTTLogTranslate(GetDMGLogLang, "role_change"), ply.nick, Damagelog:StrRole(v[3]), Damagelog:StrRole(v[4])) | ||
| elseif v[1] == 2 then | ||
| local tgt = Damagelog:InfoFromID(roles, v[3]) | ||
| return string.format(TTTLogTranslate(GetDMGLogLang, "role_item"), ply.nick, Damagelog:StrRole(ply.role), Damagelog:GetWeaponName(v[4]), tgt.nick, Damagelog:StrRole(tgt.role)) | ||
| elseif v[1] == 3 then | ||
| return string.format(TTTLogTranslate(GetDMGLogLang, "revive"), ply.nick, Damagelog:StrRole(ply.role)) | ||
| end | ||
| end | ||
|
|
||
| function event:IsAllowed(tbl) | ||
| return Damagelog.filter_settings["filter_show_roles"] | ||
| end | ||
|
|
||
| function event:Highlight(line, tbl, text) | ||
| return table.HasValue(Damagelog.Highlighted, tbl[1]) | ||
| end | ||
|
|
||
| function event:GetColor(tbl) | ||
| return Damagelog:GetColor("color_roles") | ||
| end | ||
|
|
||
| function event:RightClick(line, tbl, roles, text) | ||
| line:ShowTooLong(true) | ||
| local ply = Damagelog:InfoFromID(roles, tbl[2]) | ||
| if tbl[1] == 2 then | ||
| local tgt = Damagelog:InfoFromID(roles, tbl[3]) | ||
| line:ShowCopy(true, {ply.nick, util.SteamIDFrom64(ply.steamid64)}, {tgt.nick, util.SteamIDFrom64(tgt.steamid64)}) | ||
| return | ||
| end | ||
| line:ShowCopy(true, {ply.nick, util.SteamIDFrom64(ply.steamid64)}) | ||
| end | ||
|
|
||
| Damagelog:AddEvent(event) | ||
Uh oh!
There was an error while loading. Please reload this page.