PDA

View Full Version : How to store a common number that all players can change



feldrol
April 3rd, 2016, 08:00
Hi,
I have nearly finished the ruleset I have been working on during the last few weeks. There is one thing missing and I don't know where to start.
In that game the players can draw points from a common pool of points to improve their actions.
Is there a way to have this working on FG?
From what I saw up to now, from a server side (player) you cannot change databasenodes belonging to other players.
I saw the same thing thing with combattracker related nodes.
Where/how should I store a data (number) in the database so that everyone can have read/write acess to that databasenode ?

Any hint welcome :-)

damned
April 3rd, 2016, 09:50
Hi feldrol that is also my understanding... only the databasenode owner can edit the entry.... I think you will need Moon Wizard on this one!

feldrol
April 3rd, 2016, 18:32
Ok, so I'll try my first summon Moon Wizard spell :-)

Trenloe
April 4th, 2016, 00:19
You'll need some kind of interface for the players to use that doesn't directly access the database node holding the point total. e.g. like dragging a token off a stack or a number interface that they enter how many points to use then press a button. In the second example (enter a number and press a button) the code will then use OOB (out of bounds) messaging to kick off code on the GM side. Code running on the GM side can modify the database node.

A simple example is to have a look at the AFK OOB code in the CoreRPG ruleset, desktop\scripts\characterlist.lua.

Trenloe
April 4th, 2016, 01:02
You could also use the OOB message processing on the GM side to write a message to the chat window for all to see. For example, "Trenloe has used 5 luck points."

Moon Wizard
April 4th, 2016, 23:42
I would suggest something exactly along the lines that Trenloe suggested.

Use the OOB messages to have the player clients notify the host when the pool should be adjusted. I would also agree that handling all the message notifications on the GM side would be easiest as well.

Regards,
JPG

feldrol
April 6th, 2016, 12:45
Ok, thanks for the advice.
I'll try staring from the OOB example in characterlist.lua

feldrol
April 8th, 2016, 18:52
So I have something that is nearly working.
I declared my "kigroupe" number, from which every player will draw ki points in the ct_host.xml :



<sheetnumberl5r name="kigroupe">
<anchored to="headeranchor" position="insidetopright" offset="35,-30" width="20" />
<script>
function onInit()
OOBManager.registerOOBMsgHandler("kigroupe", handleKiGroupe);
end

function onValueChanged()
CHARSHEET = "charsheet";
nCT = DB.findNode("combattracker");
local tempkigroupe = DB.getValue(nCT,"kigroupe",0);
for _,v in pairs(DB.getChildren(CHARSHEET)) do
DB.setValue(v,"kigroupe","number",tempkigroupe);
end
end

function handleKiGroupe(msgOOB)
local rMessage = {font = "systemfont", text = "", secret = false};
nCT = DB.findNode("combattracker");
local tempkigroupe = DB.getValue(nCT,"kigroupe",0);
DB.setValue(nCT,"kigroupe","number",tempkigroupe-1);
rMessage.text= msgOOB.user .. " utilise un KI de groupe";
Comm.deliverChatMessage(rMessage);
end
</script>
</sheetnumberl5r>


In my charsheet_main.xml I have declared a field that updates with the value of the "kigroupe" pool:


<number_charskillfield_static name="kigroupe">
<anchored>
<to>reaction</to>
<position>insidetopleft</position>
<offset>105,90</offset>
<size>
<width>20</width>
<height>20</height>
</size>
</anchored>
<script>
function onInit()
local nkigroupe = DB.getValue(DB.findNode("combattracker"),"kigroupe",0);
self.setValue(nkigroupe);
end

</script>
<disabled/>
</number_charskillfield_static>


I have a button that fires the message handler, also in charsheet_main :


<button_actionsdown name="ki_remove">
<anchored to="reaction" position="insidetopleft" offset="135,90" width="20" height="20" />
<script>
function onInit()

end

function onValueChanged()
local msgOOB = {};
local sUser = User.getUsername();
msgOOB.type = "kigroupe";
msgOOB.user = sUser;
Comm.deliverOOBMessage(msgOOB);
end

</script>
<tooltip text= "decremente le ki de groupe" />
</button_actionsdown>


Everything works fine (my pool is decreased on the combattracker and the field on the charsheet_main is updated when I press the button) but on the client side I have the error message :
[ERROR] Unknown special message type received. (kigroupe)
So the handler fires on the host side, but also on the client side.
I tried to declare :
"OOBManager.registerOOBMsgHandler("kigroupe", handleKiGroupe);" in the onInit of the "ki_remove" button with a handleKiGroupe function in this button that does nothing, but then the host handler is not firing.

What am I doing wrong ?

Trenloe
April 9th, 2016, 03:26
This could be because the script scopes are across multiple control script blocks.

Move all of the OOB messaging to a global script package (like the example I mentioned in coreRPG).