Valarian
November 20th, 2007, 10:08
Another attempt by me to get to grips with the Lua scripts. Without much success so far.
I'm trying to add in a slash listener on the Chat Window that will allow players and the GM to add a language to their message. The idea is that, eventually, the option will check each player's language list and display the message text only if they have the language being spoken.
The idea is that the following slash command can be used:
/language [language] [message]
/l [language] [message]
I've modified the chatmanager.lua script with the following code, unfortunately it's not working as planned. Even at this stage.
Problem: It works fine for a single player, but I'm having problems with player to player message passing. When more than one player is connected, the message is not received by the other players and the GM gets a number of messages equal to the number of players connected. Am I able to use the commands I'm using from the player side? If not, is there a way to make the GM act as a message hub to distribute the messages? I want to do something similar to the /mood command, but with the addition of making the message text blank if the language is not spoken by the character.
Question: I'm can't find how to get hold of the character sheet entries for the players to check the languages. There doesn't seem to be anything that returns me a top-level database node for a named user. How can I reference the languagelist within the charsheet_main.xml file to loop through the available languages for each player?
Any guidance from more experienced Lua users would be appreciated. Help!
chatmanager.lua
-- IMK - Language Processing
function processLanguage(params)
local msg = {};
local sender = {};
if User.isHost() then
sender, isgm = GmIdentityManager.getCurrent();
if isgm then
msg.font = "dmfont";
else
msg.font = "npcchatfont";
end
else
sender = User.getIdentityLabel();
msg.font = "chatitalicfont";
end
if control then
local spacepos = string.find(params, " ", 1, true);
if spacepos then
local language = string.sub(params, 1, spacepos-1);
local message = string.sub(params, spacepos+1);
msg.text = message;
if sender then
for k, v in ipairs(User.getAllActiveIdentities()) do
user = User.getIdentityOwner(v);
if user then
msg.sender = sender .. " <speaks in " .. language .. ">";
control.deliverMessage(msg, user);
end
end
msg.sender = sender .. " <in " .. language .. ">";
control.addMessage(msg);
else
msg.sender = "<could not find sender>";
control.addMessage(msg);
end
else
msg.font = "systemfont";
msg.text = "Usage: /language [language] [message]";
control.addMessage(msg);
end
end
return;
end
-- End Language Processing
-- Initialization
function onInit()
registerSlashHandler("/language", processLanguage); -- IMK - Language Processing
registerSlashHandler("/whisper", processWhisper);
registerSlashHandler("/die", processDie);
end
charsheet_main.xml
<windowlist name="languagelist">
<anchored>
<to>languageframe</to>
<position>over</position>
<offset>-12,-9</offset>
<top>
<parent>languageframe</parent>
<offset>25</offset>
</top>
</anchored>
<datasource>.languagelist</datasource>
<class>charsheet_languagelistitem</class>
<allowcreate />
<script>
function onSortCompare(w1, w2)
if w1.name.getValue() == "" then
return true;
elseif w2.name.getValue() == "" then
return false;
end
return w1.name.getValue() > w2.name.getValue();
end
function onClickDown(button, x, y)
if not getNextWindow(nil) then
createWindow().name.setFocus();
return true;
end
end
</script>
</windowlist>
I'm trying to add in a slash listener on the Chat Window that will allow players and the GM to add a language to their message. The idea is that, eventually, the option will check each player's language list and display the message text only if they have the language being spoken.
The idea is that the following slash command can be used:
/language [language] [message]
/l [language] [message]
I've modified the chatmanager.lua script with the following code, unfortunately it's not working as planned. Even at this stage.
Problem: It works fine for a single player, but I'm having problems with player to player message passing. When more than one player is connected, the message is not received by the other players and the GM gets a number of messages equal to the number of players connected. Am I able to use the commands I'm using from the player side? If not, is there a way to make the GM act as a message hub to distribute the messages? I want to do something similar to the /mood command, but with the addition of making the message text blank if the language is not spoken by the character.
Question: I'm can't find how to get hold of the character sheet entries for the players to check the languages. There doesn't seem to be anything that returns me a top-level database node for a named user. How can I reference the languagelist within the charsheet_main.xml file to loop through the available languages for each player?
Any guidance from more experienced Lua users would be appreciated. Help!
chatmanager.lua
-- IMK - Language Processing
function processLanguage(params)
local msg = {};
local sender = {};
if User.isHost() then
sender, isgm = GmIdentityManager.getCurrent();
if isgm then
msg.font = "dmfont";
else
msg.font = "npcchatfont";
end
else
sender = User.getIdentityLabel();
msg.font = "chatitalicfont";
end
if control then
local spacepos = string.find(params, " ", 1, true);
if spacepos then
local language = string.sub(params, 1, spacepos-1);
local message = string.sub(params, spacepos+1);
msg.text = message;
if sender then
for k, v in ipairs(User.getAllActiveIdentities()) do
user = User.getIdentityOwner(v);
if user then
msg.sender = sender .. " <speaks in " .. language .. ">";
control.deliverMessage(msg, user);
end
end
msg.sender = sender .. " <in " .. language .. ">";
control.addMessage(msg);
else
msg.sender = "<could not find sender>";
control.addMessage(msg);
end
else
msg.font = "systemfont";
msg.text = "Usage: /language [language] [message]";
control.addMessage(msg);
end
end
return;
end
-- End Language Processing
-- Initialization
function onInit()
registerSlashHandler("/language", processLanguage); -- IMK - Language Processing
registerSlashHandler("/whisper", processWhisper);
registerSlashHandler("/die", processDie);
end
charsheet_main.xml
<windowlist name="languagelist">
<anchored>
<to>languageframe</to>
<position>over</position>
<offset>-12,-9</offset>
<top>
<parent>languageframe</parent>
<offset>25</offset>
</top>
</anchored>
<datasource>.languagelist</datasource>
<class>charsheet_languagelistitem</class>
<allowcreate />
<script>
function onSortCompare(w1, w2)
if w1.name.getValue() == "" then
return true;
elseif w2.name.getValue() == "" then
return false;
end
return w1.name.getValue() > w2.name.getValue();
end
function onClickDown(button, x, y)
if not getNextWindow(nil) then
createWindow().name.setFocus();
return true;
end
end
</script>
</windowlist>