Skip to content
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

Fix: Workaround for localized texts in DarkRP not loading correctly #3262

Merged
merged 5 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gamemode/modules/animations/sh_animations.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local Anims = {}

-- Load animations after the languages for translation purposes
hook.Add("loadCustomDarkRPItems", "loadAnimations", function()
hook.Add("Think", "loadAnimations", function()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the problem. Looking quickly at the rest of the file, it seems that the server only uses Anims to see whether an animation is registered. It ignores the actual translation. The client does show the animation in the menu.

Other than that, instead of creating and removing a think hook, on can run a timer.Simple(0,...). Note that either option will run the code quite a bit later than now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I'm not able to reproduce this issue. This may be due to my misconfiguration on my part. I'll revert this change.

Anims[ACT_GMOD_GESTURE_BOW] = DarkRP.getPhrase("bow")
Anims[ACT_GMOD_TAUNT_MUSCLE] = DarkRP.getPhrase("sexy_dance")
Anims[ACT_GMOD_GESTURE_BECON] = DarkRP.getPhrase("follow_me")
Expand All @@ -11,6 +11,7 @@ hook.Add("loadCustomDarkRPItems", "loadAnimations", function()
Anims[ACT_GMOD_GESTURE_AGREE] = DarkRP.getPhrase("thumbs_up")
Anims[ACT_GMOD_GESTURE_WAVE] = DarkRP.getPhrase("wave")
Anims[ACT_GMOD_TAUNT_DANCE] = DarkRP.getPhrase("dance")
hook.Remove("Think", "loadAnimations")
end)

function DarkRP.addPlayerGesture(anim, text)
Expand Down
10 changes: 9 additions & 1 deletion gamemode/modules/language/sh_language.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
local rp_languages = {}
local selectedLanguage = GetConVar("gmod_language"):GetString() -- Switch language by setting gmod_language to another language
local selectedLanguage = "en" -- Switch language by setting gmod_language to another language
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think even if the convar is empty, we should still try to use it. That way it will still work if some other server managed to configure it differently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll revert this back too.


cvars.AddChangeCallback("gmod_language", function(cv, old, new)
selectedLanguage = new
end)

hook.Add("Think", "DarkRPSetLanguage", function()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be covered by the cvars.AddChangeCallback call above? After all, the moment the car goes from empty to set, that function should trigger.

Maybe the empty string check can be moved there instead. That would remove the need of the separate hook.

Copy link
Contributor Author

@jjyao88 jjyao88 Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the cvars.AddChangeCallback above doesn't work at all no matter what language codes I changed from dedicated server-side. This could be the bug directly from Facepunch...
However, I could make it work by starting the server from the main game.

Copy link
Contributor Author

@jjyao88 jjyao88 Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems gmod_language only works for client side by design.

I haven't managed to make cvars.AddChangeCallback("gmod_language", ...) work on server side.

gmodLanguage = GetConVar("gmod_language"):GetString()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this introduces a new global variable, by the way.

if gmodLanguage != "" then
selectedLanguage = gmodLanguage
end
hook.Remove("Think", "DarkRPSetLanguage")
end)

function DarkRP.addLanguage(name, tbl)
local old = rp_languages[name] or {}
rp_languages[name] = tbl
Expand Down