[spoiler=||| CODE |||]
Code: Select all
@@ @oneClickLink
<!-- oneClickLink(clickText,macroLinkText,targetIds): link
clickText - Text the Player can click
macroLinkText - String generated by macroLinkText function. This is link that is run once.
targetIds - A list of tokenIds. This runs link on each tokenId changing "Impersonated" in macro link to token id before running.
Note: the created macroLinkText should NOT have a target parameter specified unless you want
all the users clicking link to run off the same token. Probably will get odd results if you do.
Generates a link to another link that only allows it to be run once. Must either have list of targets
or allow user to select tokens. If no tokens are specified then link wont execute.
Warning: if creator generates many links at once, like in a loop, there may be a link id conflict -->
[H: clickText = arg(0)]
[H: clickLinkText = arg(1)]
[H, if(argCount() >= 3): targetIds = arg(2); targetIds = ""]
[H: lastId = getProperty("oneClick.lastId")]
[H: linkId = "t"+json.get(getInfo("client"),"timeInMs")]
[H, while(lastId == linkId): linkId = "t"+json.get(getInfo("client"),"timeInMs")]
[H: setProperty("oneClick.lastId",linkId)]
[H: args = json.append(clickLinkText,targetIds,linkId)]
[H: macro.return = macroLink(clickText,"[email protected]"+getMacroLocation(),"none",args)]
!!
@@ @oneClick
<!-- oneClick(link,targetIds,linkId): execLink
link - macroLinkText to be run
targetIds - list of token ids to run link against. Impersonated is replaced with Id in link.
linkId - unique link id that can only be run once in every 20 links run.
This function is called from a generated link where the creator can specify a list of target tokens or use the
clickers selected tokens to run a macro only once per token and only for owned tokens. -->
[H: link = arg(0)]
[H: targetIds = arg(1)]
[H: linkId = arg(2)]
[H: maxHistoryLength = 100]
[H: pruneLength = 50]
<!-- token selection method: target list or selected -->
[H, if(json.isEmpty(targetIds)): tokenIds = getSelected("json"); tokenIds = targetIds]
<!-- if list is not json, then convert to json -->
[H, if(! json.isEmpty(tokenIds) && json.type(tokenIds) == "UNKNOWN"): tokenIds = json.fromList(tokenIds)]
<!-- loop through each token checking and setting its history to allow only 1 click. Execute if valid. -->
[H, foreach(tokenId,tokenIds), code: {
[H: switchToken(tokenId)]
[H: history = getProperty("oneClick.history")]
[H, if(json.isEmpty(history)): history = "[]"]
[H: isOwner = if(isOwner() || isGM(),1,0)]
[H: repeat = json.contains(history,linkId)]
[H, if(! repeat && isOwner), code: {
[H: history = json.append(history,linkId)]
[H, if(json.length(history) >= maxHistoryLength): history = json.get(history,pruneLength,json.length(history)-1)]
[H: setProperty("oneClick.history",history)]
[H: link = replace(link,"Impersonated",tokenId,1)]
[H: execLink(link,1)]
};{
[H: am.play.output(strformat('<b><span style="color:red">OneClick:</span> This link has already been clicked for this token. (%{token.name})</b>'))]
}]
}]
!!
oneClickLink(clickText,macroLinkText,targetIds): link
- clickText - Text the Player can click
- macroLinkText - String generated by macroLinkText function. This is link that is run once.
- targetIds - A list of tokenIds. This runs link on each tokenId changing "Impersonated" in macro link to token id before running.
Note: the created macroLinkText should NOT have a target parameter specified unless you want all the users clicking link to run off the same token. Probably will get odd results if you do.
Also, turn off autoexec on oneClick macro otherwise it will auto run on client computers, but not on client who generated and posted link to chat.
Generates a link to another link that only allows it to be run once. Must either have list of targets or allow user to select tokens. If no tokens are specified then link wont execute.
Example usage:
Code: Select all
[H: linkText = "click me"]
[H: args = json.append("","param 1","param 2")]
[H: macroLinkText = macroLinkText("[email protected]:token","all",args)]
[R: oneClickLink(linkText,macroLinkText)]
This creates a link in chat that says "click me" that runs "macroName" on lib token lib:token. This link can only be clicked once for each selected token. If no token is selected, then nothing happens.
edit: Updated to prevent link id duplication.
keywords: amsave tidbits