Skip to content

Commit 405a446

Browse files
committed
Clockwork 0.94.72 Beta
0.94.72 ------- * Fixed issues with command hints not showing due to recent GMOD update. * *Contributed by NightAngel.* * Added hints for voice commands that display command and phrase when typing IC. * *Contributed by NightAngel.* * Changed voice library to use a local stored table instead of a global one, added three new functions to access the table easier. * *Contributed by NightAngel.* * Added three new functions to access the voice groups table easier GetAll(), FindByID(id) and GetVoices(id). * *Contributed by NightAngel.* 0.94.69 ------- * Fixed schema version print to show properly (small bugs may occur where extra decimals are added). * *Contributed by NightAngel.* 0.94.68 ------- * Moved chatbox hooks that implement voice commands to the voice library file for better organization. * *Contributed by NightAngel.* * Added plugin call 'PlayerShouldStaminaDrain' to determine whether a player's stamina should drain while sprinting. * *Contributed by NightAngel.* * Added pitch and volume arguments to the Add function of Clockwork.voices. * *Contributed by NightAngel.* * Using a voice command will no longer display a message from the player if the phrase of the voice command is nil or empty. * *Contributed by NightAngel.*
1 parent d25bb3f commit 405a446

File tree

8 files changed

+238
-83
lines changed

8 files changed

+238
-83
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,36 @@ Changelog
22
---------
33
The following changes have been made for each official Clockwork build.
44

5+
0.94.72
6+
-------
7+
8+
* Fixed issues with command hints not showing due to recent GMOD update.
9+
* *Contributed by NightAngel.*
10+
* Added hints for voice commands that display command and phrase when typing IC.
11+
* *Contributed by NightAngel.*
12+
* Changed voice library to use a local stored table instead of a global one, added three new functions to access the table easier.
13+
* *Contributed by NightAngel.*
14+
* Added three new functions to access the voice groups table easier GetAll(), FindByID(id) and GetVoices(id).
15+
* *Contributed by NightAngel.*
16+
17+
0.94.69
18+
-------
19+
20+
* Fixed schema version print to show properly (small bugs may occur where extra decimals are added).
21+
* *Contributed by NightAngel.*
22+
23+
0.94.68
24+
-------
25+
26+
* Moved chatbox hooks that implement voice commands to the voice library file for better organization.
27+
* *Contributed by NightAngel.*
28+
* Added plugin call 'PlayerShouldStaminaDrain' to determine whether a player's stamina should drain while sprinting.
29+
* *Contributed by NightAngel.*
30+
* Added pitch and volume arguments to the Add function of Clockwork.voices.
31+
* *Contributed by NightAngel.*
32+
* Using a voice command will no longer display a message from the player if the phrase of the voice command is nil or empty.
33+
* *Contributed by NightAngel.*
34+
535
0.94.64
636
-------
737

Clockwork/garrysmod/gamemodes/clockwork/clockwork.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"settings"
66
{
77
}
8-
"version" "0.94.64"
8+
"version" "0.94.72"
99
"author" "Cloud Sixteen"
1010
"description" "A roleplaying framework developed by Cloud Sixteen for the people."
1111
"workshopid" "474315121"

Clockwork/garrysmod/gamemodes/clockwork/framework/libraries/client/cl_chatbox.lua

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,44 @@ end;
146146
function Clockwork.chatBox:IsTypingCommand()
147147
local currentText = Clockwork.chatBox:GetCurrentText();
148148
local prefix = Clockwork.config:Get("command_prefix"):Get();
149-
150-
if (string.utf8sub(currentText, 1, string.utf8len(prefix)) == prefix) then
151-
return true;
152-
else
153-
return false;
149+
150+
if (string.find(currentText, prefix) == 1) then
151+
return true;
152+
end;
153+
154+
return false;
155+
end;
156+
157+
-- A function to get whether the player is typing a voice command.
158+
function Clockwork.chatBox:IsTypingVC()
159+
local currentText = Clockwork.chatBox:GetCurrentText();
160+
local groups = Clockwork.voices:GetAll();
161+
local commands = {};
162+
163+
if (currentText != "") then
164+
for k, v in pairs(groups) do
165+
if (v.IsPlayerMember(Clockwork.Client)) then
166+
for key, voice in pairs(v.voices) do
167+
local command = string.lower(voice.command);
168+
local text = string.lower(currentText);
169+
170+
if (command == text) then
171+
commands[1] = voice;
172+
173+
break;
174+
elseif (string.find(command, text)) then
175+
commands[#commands + 1] = voice;
176+
end;
177+
178+
if (#commands == 8) then
179+
break;
180+
end;
181+
end;
182+
end;
183+
end;
154184
end;
185+
186+
return (#commands > 0), commands;
155187
end;
156188

157189
-- A function to get the spacing between messages.
@@ -754,6 +786,7 @@ function Clockwork.chatBox:Paint()
754786
local messages = self.messages;
755787
local x, y = origX, origY;
756788
local box = {width = 0, height = 0};
789+
local bIsTypingVC, voiceCommands = Clockwork.chatBox:IsTypingVC();
757790

758791
if (!bIsOpen) then
759792
if (#self.historyMsgs > 100) then
@@ -800,7 +833,7 @@ function Clockwork.chatBox:Paint()
800833
local messageY = y;
801834
local alpha = v.alpha;
802835

803-
if (bIsTypingCommand) then
836+
if (bIsTypingCommand or bIsTypingVC) then
804837
alpha = 25;
805838
elseif (bIsOpen) then
806839
alpha = 255;
@@ -924,6 +957,50 @@ function Clockwork.chatBox:Paint()
924957

925958
Clockwork.kernel:OverrideMainFont(false);
926959
end;
960+
elseif (bIsTypingVC) then
961+
local colorInformation = Clockwork.option:GetColor("information");
962+
local bSingleCommand = (#voiceCommands == 1);
963+
local colorWhite = Clockwork.option:GetColor("white");
964+
local oX, oY = origX, origY;
965+
966+
for k, v in pairs(voiceCommands) do
967+
local totalText = v.command;
968+
969+
if (bSingleCommand) then
970+
totalText = totalText.." "..v.phrase;
971+
end;
972+
973+
local tWidth, tHeight = Clockwork.kernel:GetCachedTextSize(
974+
chatBoxSyntaxFont, totalText
975+
);
976+
977+
if (k == 1) then
978+
oY = oY - tHeight;
979+
end;
980+
981+
Clockwork.kernel:DrawSimpleText(v.command, oX, oY, colorInformation);
982+
983+
if (bSingleCommand) then
984+
local pWidth = Clockwork.kernel:GetCachedTextSize(
985+
chatBoxSyntaxFont, v.command
986+
);
987+
988+
Clockwork.kernel:DrawSimpleText(v.phrase, oX, oY - tHeight - 8, colorWhite);
989+
end;
990+
991+
if (k < #voiceCommands) then oY = oY - tHeight; end;
992+
if (oY < y) then y = oY; end;
993+
994+
if (origY - oY > box.height) then
995+
box.height = origY - oY;
996+
end;
997+
998+
if (origX + tWidth - 8 > box.width) then
999+
box.width = origX + tWidth - 8;
1000+
end;
1001+
end;
1002+
1003+
Clockwork.kernel:OverrideMainFont(false);
9271004
end;
9281005

9291006
self.scroll:SetSize(box.width + 8, box.height + 8);

Clockwork/garrysmod/gamemodes/clockwork/framework/libraries/sh_voices.lua

Lines changed: 97 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,40 @@
77
--]]
88

99
Clockwork.voices = Clockwork.kernel:NewLibrary("CWVoices");
10-
Clockwork.voices.groups = {};
10+
11+
local groups = {};
12+
13+
-- A function to get the local stored voice groups.
14+
function Clockwork.voices:GetAll()
15+
return groups;
16+
end;
17+
18+
-- A function to get a certain group by ID.
19+
function Clockwork.voices:FindByID(id)
20+
return groups[id];
21+
end;
22+
23+
-- A function to get the voices of a certain group by ID.
24+
function Clockwork.voices:GetVoices(id)
25+
return groups[id].voices;
26+
end;
1127

1228
-- A function to add a voice group.
1329
function Clockwork.voices:RegisterGroup(group, bGender, callback)
1430
if (!bGender) then
1531
bGender = false;
1632
end;
1733

18-
self.groups[group] = {
34+
groups[group] = {
1935
bGender = bGender,
2036
IsPlayerMember = callback,
2137
voices = {};
2238
};
2339
end;
2440

2541
-- A function to add a voice.
26-
function Clockwork.voices:Add(groupName, command, phrase, sound, female, menu)
27-
local group = self.groups[groupName];
42+
function Clockwork.voices:Add(groupName, command, phrase, sound, female, menu, pitch, volume)
43+
local group = groups[groupName];
2844

2945
if (group) then
3046
group.hasVoices = true;
@@ -33,27 +49,30 @@ function Clockwork.voices:Add(groupName, command, phrase, sound, female, menu)
3349
phrase = phrase,
3450
female = female,
3551
sound = sound,
36-
menu = menu
52+
menu = menu,
53+
pitch = pitch,
54+
volume = volume
3755
};
3856
else
3957
ErrorNoHalt("Attempted to add voice for invalid group '"..groupName.."'.\n");
4058
end;
4159
end;
4260

61+
-- Called when the framework initializes.
4362
function Clockwork.voices:ClockworkInitialized()
4463
for k, v in pairs(Clockwork.faction:GetAll()) do
4564
local FACTION = Clockwork.faction:FindByID(v.name);
4665

4766
if (IsValid(FACTION.models.female and FACTION.models.male)) then
48-
Clockwork.voices:RegisterGroup(v.name, true, function(ply)
67+
self:RegisterGroup(v.name, true, function(ply)
4968
if (ply:GetFaction() == v.name) then
5069
return true;
5170
else
5271
return false;
5372
end;
5473
end);
5574
else
56-
Clockwork.voices:RegisterGroup(k, false, function(ply)
75+
self:RegisterGroup(k, false, function(ply)
5776
if (ply:GetFaction() == v.name) then
5877
return true;
5978
else
@@ -65,14 +84,16 @@ function Clockwork.voices:ClockworkInitialized()
6584

6685
Clockwork.plugin:Call("RegisterVoiceGroups", self);
6786
Clockwork.plugin:Call("RegisterVoices", self);
68-
Clockwork.plugin:Call("AdjustVoices", self.groups);
87+
Clockwork.plugin:Call("AdjustVoices", groups);
6988

7089
if (CLIENT) then
71-
for k, v in pairs(Clockwork.voices.groups) do
90+
for k, v in pairs(groups) do
7291
if (v.hasVoices) then
7392
Clockwork.directory:AddCategory(k, "Commands");
7493
table.sort(v.voices, function(a, b) return a.command < b.command; end);
7594
for k2, v2 in pairs(v.voices) do
95+
if (!v2.phrase) then v2.phrase = ""; end;
96+
7697
Clockwork.directory:AddCode(k, [[
7798
<div class="auraInfoTitle">]]..string.upper(v2.command)..[[</div>
7899
<div class="auraInfoText">]]..v2.phrase..[[</div>
@@ -83,4 +104,71 @@ function Clockwork.voices:ClockworkInitialized()
83104
end;
84105
end;
85106

107+
-- Called when chat box info should be adjusted.
108+
function Clockwork.voices:ChatBoxAdjustInfo(info)
109+
if (info.class == "ic" or info.class == "yell" or info.class == "whisper") then
110+
if (IsValid(info.speaker) and info.speaker:HasInitialized()) then
111+
info.text = string.upper(string.sub(info.text, 1, 1))..string.sub(info.text, 2);
112+
113+
for k, v in pairs(groups) do
114+
if (v.IsPlayerMember(info.speaker)) then
115+
for k2, v2 in pairs(v.voices) do
116+
if (string.lower(info.text) == string.lower(v2.command)) then
117+
local voice = {
118+
global = false,
119+
volume = v2.volume or 80,
120+
sound = v2.sound,
121+
pitch = v2.pitch
122+
};
123+
124+
if (v.bGender) then
125+
if (v2.female and info.speaker:QueryCharacter("Gender") == GENDER_FEMALE) then
126+
voice.sound = string.Replace(voice.sound, "/male", "/female");
127+
end;
128+
end;
129+
130+
if (info.class == "whisper") then
131+
voice.volume = voice.volume * 0.75;
132+
elseif (info.class == "yell") then
133+
voice.volume = voice.volume * 1.25;
134+
end;
135+
136+
info.voice = voice;
137+
138+
if (v2.phrase == nil or v2.phrase == "") then
139+
info.visible = false;
140+
141+
if (SERVER) then
142+
Clockwork.kernel:PrintLog(LOGTYPE_GENERIC, info.speaker:Name().." says: \""..info.text.."\"");
143+
end;
144+
else
145+
info.text = v2.phrase;
146+
end;
147+
148+
return true;
149+
end;
150+
end;
151+
end;
152+
end;
153+
end;
154+
end;
155+
end;
156+
157+
-- Called when a chat box message has been added.
158+
function Clockwork.voices:ChatBoxMessageAdded(info)
159+
if (info.voice) then
160+
if (IsValid(info.speaker) and info.speaker:HasInitialized()) then
161+
info.speaker:EmitSound(info.voice.sound, info.voice.volume, info.voice.pitch);
162+
end;
163+
164+
if (info.voice.global) then
165+
for k, v in pairs(info.listeners) do
166+
if (v != info.speaker) then
167+
Clockwork.player:PlaySound(v, info.voice.sound);
168+
end;
169+
end;
170+
end;
171+
end;
172+
end;
173+
86174
Clockwork.plugin:Add("Voices", Clockwork.voices);

Clockwork/garrysmod/gamemodes/clockwork/framework/sh_boot.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ end;
2828

2929
Clockwork.ClockworkFolder = Clockwork.ClockworkFolder or GM.Folder;
3030
Clockwork.SchemaFolder = Clockwork.SchemaFolder or GM.Folder;
31-
Clockwork.KernelVersion = "0.94.64";
31+
Clockwork.KernelVersion = "0.94.72";
3232
Clockwork.KernelBuild = "beta"
3333
Clockwork.DeveloperVersion = true;
3434
Clockwork.Website = "http://kurozael.com";
@@ -114,7 +114,7 @@ end;
114114
Clockwork.kernel:IncludeSchema();
115115
Clockwork.plugin:Call("ClockworkSchemaLoaded");
116116

117-
MsgC(Color(0, 255, 100, 255), "[Clockwork] Schema \""..Schema:GetName().."\" ["..Schema:GetVersion().."] by "..Schema:GetAuthor().." loaded!\n");
117+
MsgC(Color(0, 255, 100, 255), "[Clockwork] Schema \""..Schema:GetName().."\" ["..Clockwork.kernel:GetSchemaGamemodeVersion().."] by "..Schema:GetAuthor().." loaded!\n");
118118

119119
--[[ The following code is loaded over-the-Cloud. --]]
120120
if (SERVER and Clockwork.LoadPostSchemaExternals) then

Clockwork/garrysmod/gamemodes/clockwork/framework/sh_kernel.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ if (SERVER) then
812812
SCHEMA_GAMEMODE_INFO["name"] = schemaData["title"] or "Undefined";
813813
SCHEMA_GAMEMODE_INFO["author"] = schemaData["author"] or "Undefined";
814814
SCHEMA_GAMEMODE_INFO["description"] = schemaData["description"] or "Undefined";
815+
SCHEMA_GAMEMODE_INFO["version"] = schemaData["version"] or "Undefined";
815816
return SCHEMA_GAMEMODE_INFO;
816817
end;
817818

@@ -820,6 +821,12 @@ if (SERVER) then
820821
local schemaInfo = self:GetSchemaGamemodeInfo();
821822
return schemaInfo["name"];
822823
end;
824+
825+
-- A function to get the schema version.
826+
function Clockwork.kernel:GetSchemaGamemodeVersion()
827+
local schemaInfo = self:GetSchemaGamemodeInfo();
828+
return schemaInfo["version"];
829+
end;
823830

824831
-- A function to find schema data in a directory.
825832
function Clockwork.kernel:FindSchemaDataInDir(directory)

0 commit comments

Comments
 (0)