Character sheet opens for anyone why?

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
User avatar
mfrizzell
Dragon
Posts: 762
Joined: Sat Feb 13, 2010 2:35 am
Location: California

Character sheet opens for anyone why?

Post by mfrizzell »

I have this line in my character sheet macro in order to keep other players from opening each others charactersheet but once opened it updates to any token selected.

Code: Select all

[h,if(!isGM() && isNPC(token) && !isOwner()):abort(0)]
Here is the whole code because I'm thinking it is probably the onChangeselection that let everyone see each others character sheet.

Code: Select all

[h:tokens = getSelectedNames()]
[h,if(listCount(tokens) != 1): abort(0)]
[h:token = listGet(tokens, 0)]
[h:go = 1]

[h,if(startsWith(token, "Lib")): abort(0)]
[h,if(!isGM() && isNPC(token) && !isOwner()):abort(0)]
[h:switchToken(token)]



[h:myGear = mlf.Gear]
[h:myGearList = json.fields(myGear)]
[h:gearTblSection=""]
[h,foreach(gearItem, myGearList),CODE:
{
  [det = json.get(myGear, gearItem)]
  [gearTblSection = strformat("%s%dx %s<br>", gearTblSection, json.get(det,"qty"), gearItem)]
}]




[frame("Character Sheet"):
{
  <html>
  <head>
  <title>ADD&D 2E Character Sheet</title>
<head><link rel='onChangeSelection' type='macro' href='[r:macroLinkText("mlf.CharacterSheet@this", "none",token)]'></link>
  </head>
  <body bgcolor='white'>
  <table border=0 width='100%'>
 <tr> 
[r:MacroLink("Main", "Main@Lib:AD&D", "none", "", currentToken())]
[r:MacroLink("Spells", "Spells@Lib:AD&D", "none", "", currentToken())]
[r:MacroLink("Gear", "Gear@Lib:AD&D", "none", "", currentToken())]
</tr>
<tr bgcolor="#808080">
<td colspan='4' align="center" ><img src='[r:getTokenImage()]'></img></td>
</tr>

  <tr bgcolor='#000000' color='white'>
  <td colspan='2'><b>[r:getName()]</b></td>
  <td colspan='2'><b>Level [R:mlf.Level] [r:mlf.Race] [r:mlf.Class]</b></td>
  </tr>
<tr bgcolor='#cccccc'>
<td  colspan='2'><b>Alignment</b>: [r:mlf.Alignment]</td>

  </tr>
  <tr bgcolor='#eeeeee'>
  <td><b>[r:MacroLink("HP/MaxHP:", "mlf.HPAdjust@Lib:AD&D", "all", "", currentToken())]</b> [r:mlf.HP] / [r:mlf.HPMAX]</td>
  <td><b>[r:MacroLink("XP:", "mlf.XPAdjust@Lib:AD&D", "all", "", currentToken())]</b> [r:mlf.XP]</td>
  <td><b>[r:MacroLink("AC:", "mlf.ACAdjust@Lib:AD&D", "all", "", currentToken())]</b> [r:mlf.ArmorClass]</td>
  </tr>
<tr bgcolor='#cccccc'>
<td><b>[r:MacroLink("STR", "mlf.STRCheck@Lib:AD&D", "all", "", currentToken())]</b>:[r:mlf.Strength]</td>
<td><b>[r:MacroLink("CON", "mlf.CONCheck@Lib:AD&D", "all", "", currentToken())]</b>:[r:mlf.Constitution]</td>
<td><b>[r:MacroLink("DEX", "mlf.DEXCheck@Lib:AD&D", "all", "", currentToken())]</b>:[r:mlf.Dexterity]</td>
<td>[MacroLink("edit","mlf.editCharacter@Lib:AD&D", "", "","selected")]</td>
  </tr>
<tr bgcolor='#eeeeee'>
<td><b>[r:MacroLink("INT", "mlf.INTCheck@Lib:AD&D", "all", "", currentToken())]</b>:[r:mlf.Intelligence]</td>
<td><b>[r:MacroLink("CHA", "mlf.CHACheck@Lib:AD&D", "all", "", currentToken())]</b>:[r:mlf.Charisma]</td>
<td><b>[r:MacroLink("WIS", "mlf.WISCheck@Lib:AD&D", "all", "", currentToken())]</b>:[r:mlf.Wisdom]</td>
  </tr>
<tr><td>[MacroLink("Level Up","mlf.LevelUp@Lib:AD&D")]</td>
      <td>[MacroLink("Level Loss","mlf.LevelDown@Lib:AD&D")]</td>
</tr>
  <tr bgcolor='#cccccc'>
   <td><b>THACO</b>: [r:mlf.THAC0]</td>

  </tr>
  <tr bgcolor='#eeeeee'>
  <td valign='top' colspan='4'>
  <b>Spell Book</b>: <br>
  [h:SpellList = json.fields(mlf.SpellBook,"json" )]
  [r:  json.toList(SpellList)]

  </td>
</tr>
  <tr bgcolor='#cccccc'>
  <td valign='top' colspan='4'>
  <b>Memorised</b>:<br>
  [h:SpellMem = json.fields(mlf.SpellsMemorised,"json" )]
  [r:  json.toList(SpellMem)]
</td>  
</tr>
  <tr>
  <td valign='top' colspan='2'>
  <b>Armor</b>: 
  [r:mlf.EquipedArmor]
  [r:if(mlf.EquippedShield==1," & Shield","")]
  </td>
  <td valign='top' colspan='2'>
  <b>Weapons M / R</b>: 
  [r: json.get(EquipedWeapon,"ItemName")] /  [r:mlf.EquippedRanged]
  </td>
</tr>
<tr>
<td valign='top' colspan='4' bgcolor='#dcdcdc'><b>Additional Gear</b></td>
</tr>
<tr>
<td colspan='4' bgcolor='#dcdcdc'>
[r:gearTblSection]
</td>
</tr>
</table>
</body>
</html>
}]
Any help would be appreciated.
Thanks
DCI/RPGA# 7208328396 Skype ID mfrizzell77
Characters:
Strabor - Dwarf Avenger 5th Level
Tikkanan - Human Warlock 2nd Level
----------------------------------------------------
"People are more violently opposed to fur than leather because it's safer to harass rich women than motorcycle gangs."

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Character sheet opens for anyone why?

Post by CoveredInFish »

You might loose the token on the onSelectionChange event.
You have only three parameters in your Wiki: macroLinkText() call but to set the token context you have to specify 4.

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Character sheet opens for anyone why?

Post by aliasmask »

Or check to see if the token selected is owned before switching.

User avatar
mfrizzell
Dragon
Posts: 762
Joined: Sat Feb 13, 2010 2:35 am
Location: California

Re: Character sheet opens for anyone why?

Post by mfrizzell »

aliasmask wrote:Or check to see if the token selected is owned before switching.
I would have thought that the if statement looking for ownership would have aborted the macro before it got to the switchtoken statement.
DCI/RPGA# 7208328396 Skype ID mfrizzell77
Characters:
Strabor - Dwarf Avenger 5th Level
Tikkanan - Human Warlock 2nd Level
----------------------------------------------------
"People are more violently opposed to fur than leather because it's safer to harass rich women than motorcycle gangs."

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Character sheet opens for anyone why?

Post by aliasmask »

mfrizzell wrote:
aliasmask wrote:Or check to see if the token selected is owned before switching.
I would have thought that the if statement looking for ownership would have aborted the macro before it got to the switchtoken statement.
I didn't look close enough to notice isOwned, but I think your logic is off on the check. In order to abort, all these conditions must be met, not GM, not Owner, not NPC, so if the token is a PC token, then it doesn't abort. I also think you should check for isOwnedByAll.

Code: Select all

[H: abort( if(isOwned() || isGM() || isNPC() || isOwnedByAll(),1,0))]
Did you want the players to see NPC tokens?

User avatar
mfrizzell
Dragon
Posts: 762
Joined: Sat Feb 13, 2010 2:35 am
Location: California

Re: Character sheet opens for anyone why?

Post by mfrizzell »

hmm, I see your right about the logic but not so sure about the conditions to check for.

Code: Select all

[H: abort( if(!isOwner() || !isGM() || isNPC() || isOwnedByAll(),1,0))]
Basically I want the DM and the owner of the token to run the macro so I put negative for isOwner and isGM but it still lets anyone run it.
DCI/RPGA# 7208328396 Skype ID mfrizzell77
Characters:
Strabor - Dwarf Avenger 5th Level
Tikkanan - Human Warlock 2nd Level
----------------------------------------------------
"People are more violently opposed to fur than leather because it's safer to harass rich women than motorcycle gangs."

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Character sheet opens for anyone why?

Post by aliasmask »

This should be what you want then. This says if you're the owner or the gm or the token is owned by all, then don't abort.

Code: Select all

[H: abort( if(isOwner() || isGM() || isOwnedByAll(),1,0))]
If you don't want it to work for NPC tokens then you can add another condition:

Code: Select all

[H: abort( if((isOwner() || isGM() || isOwnedByAll()) && !isNPC(),1,0))]

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Character sheet opens for anyone why?

Post by wolph42 »

Tip: when creating complex Boolean statements especially when using ! Make a schematic on paper of all possible outcomes and see which operand you need.

User avatar
mfrizzell
Dragon
Posts: 762
Joined: Sat Feb 13, 2010 2:35 am
Location: California

Re: Character sheet opens for anyone why?

Post by mfrizzell »

For some reason it still allows a player to look at other players character sheets. Maybe the best is to just get rid of the onChangeSelection
DCI/RPGA# 7208328396 Skype ID mfrizzell77
Characters:
Strabor - Dwarf Avenger 5th Level
Tikkanan - Human Warlock 2nd Level
----------------------------------------------------
"People are more violently opposed to fur than leather because it's safer to harass rich women than motorcycle gangs."

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Character sheet opens for anyone why?

Post by wolph42 »

Have you tried using an intermediate macro? So onchangeselection does not call itself (as I assume you have it running now) but calls eg playerscheck() that macro also makes the check and if it passes (not aborted) calls the char generator.

User avatar
mfrizzell
Dragon
Posts: 762
Joined: Sat Feb 13, 2010 2:35 am
Location: California

Re: Character sheet opens for anyone why?

Post by mfrizzell »

Hadn't thought of that. Not sure what it would look like.
DCI/RPGA# 7208328396 Skype ID mfrizzell77
Characters:
Strabor - Dwarf Avenger 5th Level
Tikkanan - Human Warlock 2nd Level
----------------------------------------------------
"People are more violently opposed to fur than leather because it's safer to harass rich women than motorcycle gangs."

Post Reply

Return to “Macros”