PDA

View Full Version : GM send modifier to player's stack



saithan
September 23rd, 2010, 04:22
This is a little manipulation i made and found it to be helpful to GMs.
This allows the GM(host) to place a modifier +# or -# up to 999 to any player connected to the host.
first you will want to edit your chat_entry.lua by locating the onDeliverMessage function then just above the return massagedata; add:


if not User.isHost() then
local test1 = string.sub(messagedata.text, 1,5);
if string.find(test1,"%a") then
--do nothing passing it to screen
else
if string.match(test1,"%^%-%d+")or string.match(test1,"%^%+%d+")then
messagedata.text = " "..messagedata.text
end
end
end



next you want to open the chatmanager.lua and locate the processWhisper function. pay attention to where the ishost condition ends (around line 146) you will see:
local msg = {};
msg.font = "msgfont";
msg.text = params;
after that add:


local test1 = string.sub(msg.text, 1,5);

if string.match(test1,"%^%-%d+")or string.match(test1,"%^%+%d+")then
msg.text = " "..msg.text
end


next you will open chat_chat.lua
look for onReceiveMessage function (if it is not there then we will need to add it.


function onReceiveMessage(messagedata)
local test1 = string.sub(messagedata.text, 1,5);
local modnum ="";
if string.find(test1,"%a") or string.find(messagedata.text,"%s") then
--do nothing passing tothe screen
else
if string.match(test1,"%^%-%d+")or string.match(test1,"%^%+%d+")then
modnum = string.sub(test1,2);
ModifierStack.setFreeAdjustment(tonumber(modnum));
return true;
end
end
end



then the GM can simply apply a modifier to a player by typing as example:
^+5
then drag it to that players portrait or enter that into the chat to globally apply that modifier to all connected players (including host).
special thanks to Oberoten and DrZuess for their invaluable help.

Oberoten
September 23rd, 2010, 10:18
If it is okay, I will add this to the Wiki.

_ obe

saithan
September 23rd, 2010, 10:42
go right ahead I hope it helps.

Oberoten
September 23rd, 2010, 11:33
It most certainly does. :)

I am very very very pleased with this. I have added it to my Ars Magica set and it is really damn useful. *grins*

- Obe

Oberoten
September 23rd, 2010, 11:46
Added it in the Scripts section :

https://oberoten.dyndns.org/fgwiki/index.php/GM-added_Modifier

- Obe

saithan
September 25th, 2010, 04:06
Ok here is a second version that is far less limiting.
you can now send any sized( 1- 10000 and up) modifier with a description (-2 darkness).
stackable for multiple conditions.

simply type: ^-2 description
ex: ^+1 higher ground
enter in chat for global (modifies everyone).
or drag to player portrait to effect only that players stack.

it is a full rewrite: so here it goes:
chat_entry.lua (onDeliverMessage function above return messagedata;)


if not User.isHost() then
local test1 = messagedata.text;


if string.match(test1,"%^%-%d+")or string.match(test1,"%^%+%d+")or string.match(test1,"[^%^%+%d+%s]|[^%^%-%d%s]|[^%^%+%d]") or string.sub(test1,1,1)=="^" then
messagedata.text = " "..messagedata.text
end

end



chatmanager.lua (proccessWhisper function at around line 151)


--check for diemod send
local test1 = string.sub(msg.text, 1,5);

if string.match(test1,"%^%-%d+")or string.match(test1,"%^%+%d+")then
msg.text = " "..msg.text
end



next: chat_chat.lua if you do not have the onrecievemessage function then add it as such



function onReceiveMessage(messagedata)
local test1 = messagedata.text;
local modnum = {};
local descriptor ="";
test1 = test1.." ";
if string.sub(test1,1,1) == " " then
--do nothing passing tothe screen
else

if string.match(test1,"^%^%-%d+")or string.match(test1,"^%^%+%d+")or string.match(test1,"[^%^%+%d+]|[^%^%-%d]|[^%^%+%d]")then
if not string.match(test1,"%s%a") then
test1 = test1.." ";

end
modnum = strsplit( "%s",test1);

for i = 2, table.getn (modnum) do
descriptor = descriptor.." " ..modnum[i];
end
modnum[1] = string.sub(modnum[1],2);
if string.find(modnum[1],"%a") or string.find(modnum[1],"%s") or string.find(modnum[1],"[_&*()^%$#@!~?.,:;`={}]")then
--pass this to the screen
else
ModifierStack.addSlot(descriptor..":",tonumber(modnum[1]));
return true;
end
end
end
end

function strsplit(delimiter, text)
local list = {}
local pos = 1
if string.find("", delimiter, 1) then
error("delimiter matches empty string!")
end
while 1 do
local first, last = string.find(text, delimiter, pos)
if first then
table.insert(list, string.sub(text, pos, first-1))
pos = last+1
else
table.insert(list, string.sub(text, pos))
break
end
end
return list
end


Take note of the added strsplit function that must be added to the chat_chat lua for this to work.

anyways I really hope this helps someone, and thanks to those on https://fg2.rpg-vault.net/

Oberoten
September 25th, 2010, 09:10
Gloriously added to Ars Magica ruleset now. It works a charm.

: 1 minor nitpick - 1 client several characters sends the modifier to all the characters even if only one is targeted. But it is a livable condition none the less since they are individually resetable :)

- Obe

saithan
September 25th, 2010, 11:03
make sure that you changed the code to the chat_entry.lua that is what prevents the players that are not host from issuing the commands.

Stitched
September 25th, 2010, 11:04
Thanks to you both (Oberoten and Saithan) for sharing the codebase and placing it on the Wiki. I had no idea code snippets for handling routine functions was being archived in the Wiki. Some really great entries there.

Thanks again!