RPTools.net

Discussion and Support

Skip to content

It is currently Fri Feb 23, 2018 5:34 pm 






Reply to topic  [ 3 posts ] 

Previous topic | Next topic 

  Print view

Author Message
 Offline
Dragon
 
Joined: Mon Aug 03, 2015 5:30 pm
Posts: 252
 Post subject: Player who called a macro?
PostPosted: Tue Jan 16, 2018 7:35 pm 
Is there a way for a campaign macro to determine which player called it?

(I did look through the wiki, so if it's obvious, feel free to mock me for being blind and stupid.)


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 8012
Location: Bay Area
 Post subject: Re: Player who called a macro?
PostPosted: Tue Jan 16, 2018 9:26 pm 
I use a custom output (broadcast) that looks like the normal output except I put the player name in the tooltip over token image. Here is the basic macro:

Code:
@@ @output.basic
@PROPS@ fontColor=yellow ; autoExecute=true ; fontSize=11pt ; sortBy=3 ; color=blue ; playerEditable=false ; applyToSelected=false ; group=Core ; tooltip= ; minWidth=94 ;
<!-- output.basic(chatText,targets,token): output to chat

   This function will post html text in a similar fashion as the normal output but the players name appears as a tooltip to the
      impersonated token. By default, onCampaignLoad functions block all output and this function will post output to chat.
-->

[H: chatText = arg(0)]
[H, if(argCount() >= 2): targets = arg(1); targets = "all"]
[H, if(argCount() >= 3): token = arg(2); token = currentToken()]

<!-- validate token is on current map -->
[H: tokenId = findToken(token)]
[H, if(! json.isEmpty(tokenId)), code: {
   [H: tokenName = getName(tokenId)]
   [H: tokenImage = getImage(tokenId)]
};{}]

[H: targetNames = getPlayerGroups(targets,tokenId)]

<!-- if original targets parameter is blank then output is to all, but if blank after getting groups, then no output -->
[H, if(! json.isEmpty(chatText) && ! json.isEmpty(targetNames)), code: {
   [H: playerName = replace(getPlayerName(),'"',"&quot;")]
   [H, if(json.isEmpty(tokenId)), code: {
      [H: output = strformat('
         <table cellpadding="0">
            <tr>
               <td style="margin-right: 5px;font-weight:700;" valign="top">%{playerName}:</td>
               <td valign="top"><span>%{chatText}</span></td>
            </tr>
         </table>')]
   };{
      [H: output = strformat('
         <table cellpadding="0">
            <tr>
               <td width="40" style="padding-right: 5px" valign="top"><img src="%{tokenImage}-40" alt="%{playerName}" /></td>
               <td style="margin-right: 5px;font-weight:700;" valign="top">%{tokenName}:</td>
               <td valign="top"><span>%{chatText}</span></td>
            </tr>
         </table>')]
   }]
   [H: broadcast(output,targetNames,"json")]
};{}]

!!
@@ @getPlayerGroups
@PROPS@ fontColor=black ; autoExecute=true ; fontSize=11pt ; sortBy=21 ; color=white ; playerEditable=false ; applyToSelected=false ; group=Core ; tooltip= ; minWidth=94 ;
<!-- getPlayerGroups(targets,tokenId): playerNames
   targets - (default to all) A list or json of player names and/or groups who will see chatText.
      * all - all players (keywords are case sensitive)
      * owner - anyone who owns the token. token must be valid and on current map
      * other - anyone who doesn't own token. token must be valid and on current map
      * gm - only gm players
      * -gm - anyone but the gm
      * self - only displayed to self
      * -self - display to all other players
      (Note: when posting multiple versions of the same output, using owner and other is most common)
   tokenId - tokenId of token to impersonate.
   playerNames - Return players names based on target groups.
-->

[H, if(argCount() >= 1): targets = arg(0); targets = "all"]
[H, if(argCount() >= 2): tokenId = arg(1); tokenId = ""]

<!-- validate token is on current map -->
[H: tokenId = findToken(tokenId)]

<!-- parse list of targets in to list of players names -->
[H, if(json.type(targets) == "UNKNOWN"): targets = json.fromList(targets)]

[H: players.all = getAllPlayerNames("json")]
[H: players.gm = json.get(getInfo("server"),"gm")]
[H: players.self = json.append("",getPlayerName())]
[H, if(json.isEmpty(tokenId)), code: {
   [H: players.owner = json.union(players.gm,players.self)]
   [H: players.other = json.difference(players.all,players.owner)]
};{
   [H, if(isOwnedByAll(tokenId)), code: {
      [H: players.owner = players.all]
      [H: players.other = "[]"]
   };{
      [H: players.owner = getOwners("json",tokenId)]
      [H: players.other = json.difference(players.all,players.owner)]
   }]
}]

<!-- get player names based on groups -->
[H: targetNames = "[]"]
[H, if(json.isEmpty(targets)), code: {
   [H: targetNames = players.all]
};{
   [H, if(json.contains(targets,"all")): targetNames = json.union(targetNames,players.all)]
   [H, if(json.contains(targets,"gm")): targetNames = json.union(targetNames,players.gm)]
   [H, if(json.contains(targets,"self")): targetNames = json.union(targetNames,players.self)]
   [H, if(json.contains(targets,"owner")): targetNames = json.union(targetNames,players.owner)]
   [H, if(json.contains(targets,"other")): targetNames = json.union(targetNames,players.other)]
   [H, if(json.contains(targets,"-gm")): targetNames = json.difference(targetNames,players.gm)]
   [H, if(json.contains(targets,"-self")): targetNames = json.difference(targetNames,player.self)]
   [H: targets = json.difference(targets,json.append("","all","gm","self","owner","other","-gm","-self"))]
   [H, if(! json.isEmpty(targets)): targetNames = json.intersection(players.all,json.union(targetNames,targets))]
}]

[H: macro.return = targetNames]

!!


This is the main formatting though:
Code:
      [H: output = strformat('
         <table cellpadding="0">
            <tr>
               <td width="40" style="padding-right: 5px" valign="top"><img src="%{tokenImage}-40" alt="%{playerName}" /></td>
               <td style="margin-right: 5px;font-weight:700;" valign="top">%{tokenName}:</td>
               <td valign="top"><span>%{chatText}</span></td>
            </tr>
         </table>')]

_________________
Downloads:


Top
 Profile  
 
 Offline
Dragon
 
Joined: Mon Aug 03, 2015 5:30 pm
Posts: 252
 Post subject: Re: Player who called a macro?
PostPosted: Tue Jan 16, 2018 10:06 pm 
All I was really looking for was getPlayerName(), but I got that out of it.

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 3 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 1 guest





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman