Re: NightAngel's Development Thead
Okay, so I've run into a little hitch with changing the IC chat name from the physdesc to the voicedesc. It uh.. doesn't really work at all. xD
Here's my cl_plugin.lua:
Code:
local PLUGIN = PLUGIN;
local Clockwork = Clockwork;
Clockwork.config:AddToSystem("Minimum voice description length", "minimum_voicedesc", "The minimum amount of characters a player must have in their voice description.", 0, 128);
--Called when the chatbox info needs to be adjusted with the voice desc.
function PLUGIN:ChatBoxAdjustInfo(info)
local icClass = {"ic", "whisper", "yell", "radio", "radio_eavesdrop"}
for k, v in ipairs (icClass) do
if (info.class == v) then
if (info.unrecognized) then
local unrecognisedVoice, usedVoiceDesc = PLUGIN:GetUnrecognisedName(info.speaker);
if (usedVoiceDesc and string.len(unrecognisedVoice) > 24) then
unrecognisedVoice = string.sub(unrecognisedVoice, 1, 21).."...";
end;
info.name = "["..unrecognisedVoice.."]";
end;
end;
end;
end;
-- A function to get a player's unrecognised name.
function PLUGIN:GetUnrecognisedName(player)
local unrecognisedVoiceDesc = self:GetVoiceDesc(player);
local unrecognisedVoice = Clockwork.config:Get("unrecognised_name"):Get();
local usedVoiceDesc;
if (unrecognisedVoiceDesc) then
unrecognisedVoice = unrecognisedVoiceDesc;
usedVoiceDesc = true;
end;
return unrecognisedVoice, usedVoiceDesc;
end;
-- A function to get a player's voice description.
function PLUGIN:GetVoiceDesc(player)
if (!player) then
player = Clockwork.Client;
end;
local voiceDesc = player:GetSharedVar("VoiceDesc");
local team = player:Team();
if (voiceDesc == "") then
voiceDesc = Clockwork.class:Query(team, "defaultVoiceDesc", "");
end;
if (voiceDesc == "") then
voiceDesc = Clockwork.config:Get("default_voicedesc"):Get();
end;
if (!voiceDesc or voiceDesc == "") then
voiceDesc = "This character has no voice description set.";
else
voiceDesc = Clockwork.kernel:ModifyVoiceDesc(voiceDesc);
end;
return voiceDesc;
end;
My sh_plugin.lua:
Code:
local PLUGIN = PLUGIN;
Clockwork.kernel:IncludePrefixed("cl_plugin.lua");
Clockwork.kernel:IncludePrefixed("sv_plugin.lua");
-- A function to modify a voice description.
function PLUGIN:ModifyVoiceDesc(description)
if (string.len(description) <= 128) then
if (!string.find(string.sub(description, -2), "%p")) then
return description..".";
else
return description;
end;
else
return string.sub(description, 1, 125).."...";
end;
end;
And my sv_plugin.lua:
Code:
local Clockwork = Clockwork;
local PLUGIN = PLUGIN;
Clockwork.config:Add("minimum_voicedesc", 32, true);
-- Called when a player's shared variables should be set.
function PLUGIN:PlayerSetSharedVars(player, curTime)
player:SetSharedVar("VoiceDesc", player:GetCharacterData("VoiceDesc"));
end;
Basically, I just copied over how the physical description is handled, and just changed all the variables to match the new voice description. But it doesn't change the unrecognized name from the physical description into the voice description in IC chat or anything else. So uh.. help please? 
[member=5482]duck[/member]
[member=5522]Atebite[/member]
[member=5495]Polis[/member]
disisthefirsttimeI'veaskedforhelpI'msonervous