Page 2 of 2

Re: Beam me up, Scottie

Posted: Mon Jan 04, 2010 5:28 am
by CoveredInFish
Nah ... wasnt the last one. Thanks to PinkRose to finding it for me.

I made an error in calculating the new position that caused the formation to appear mirrored. This is now fixed...

Code: Select all

[h: abort(isGM())]

[h: tokenId = if(getSelected()=="",getPC(),getSelected())]
[h: tokenNm = ""]

[h: CoordinatesInUnits = 0]
[h: jsonAllOffsets = ""]
[h: referenceToken = listGet(tokenId, 0)]
[h: xOrigin = getTokenX(CoordinatesInUnits, referenceToken)]
[h: yOrigin = getTokenY(CoordinatesInUnits, referenceToken)]

[h, foreach(in,tokenId), code: {
    [h: tokenNm = listAppend(tokenNm,getName(in))]
    [h: xOffset = getTokenX(CoordinatesInUnits, in)]
    [h: yOffset = getTokenY(CoordinatesInUnits, in)]
    [h: jsonOffset = json.set("", "x", xOrigin - xOffset, "y", yOrigin - yOffset)]
    [h: jsonAllOffsets = json.set( jsonAllOffsets, in, jsonOffset )]
}]
[h: Lst = ""]
[h: in  =0]
[h, while(tbl("Mapa",in)!=tbl("Mapa",in+2)),code:{
    [h: in=in+1]
    [h: Lst=listAppend(Lst,listGet(tbl("Mapa",in),3))]
}]

[h: bla=input(
"Fichas|"+tokenNm+"||Label",
"map|"+Lst+"|Destino|Radio"
)]
[h: abort(bla)]
[h: map=map+1]

[h: Dest=listGet(tbl("Mapa",map),0)]
[h: x=listGet(tbl("Mapa",map),1)]
[h: y=listGet(tbl("Mapa",map),2)]


[r,if(getCurrentMapName()==Dest),code:{
    [h,foreach(in,tokenId),code:{
        [h: jsonOffset = json.get(jsonAllOffsets, in)]
        [h: xOffset = json.get(jsonOffset, "x")]
        [h: yOffset = json.get(jsonOffset, "y")]
        [moveToken(x-xOffset, y-yOffset,0,in)]
    }]
    [r:tokenNm] movido(s) a [r:Dest] [goto(x,y)]
};{
    [h,foreach(in,tokenId),code:{
        [h: jsonOffset = json.get(jsonAllOffsets, in)]
        [h: xOffset = json.get(jsonOffset, "x")]
        [h: yOffset = json.get(jsonOffset, "y")]
        [moveTokenToMap(in, Dest, x-xOffset, y-yOffset)]
    }]
    [r:tokenNm] llevado(s) al mapa [r:setCurrentMap(Dest)] [goto(x,y)]
}]
 

Re: Beam me up, Scottie

Posted: Mon Jan 04, 2010 6:28 am
by PinkRose
Thank you so much.
As a non-coder, I sincerely appreciate it.

Re: Beam me up, Scottie

Posted: Tue Aug 31, 2010 10:24 am
by patoace
I guess by now most people are using Lindsay's excellent tool for moving tokens between maps, but for documentation purposes I left here the code I'm currently using, based on the macro in the original post.

You don't need a specifically formated table anymore, the macro considers every token in the destination map hidden layer an available drop point. If it doesn't find any token in the hidden layer, it defaults to the 0,0 coordinates. This way, the only preparation needed is to put a token in that layer. It also moves tokens inside a map.

To "install", just drop this code in a campaign macro.

Code: Select all

<!--
Aborts if the user isn't the GM
[abort(isGM())]

If there are tokens selected, apply to them, else all PC are affected
[tokenId=if(getSelected()=="",getPC(),getSelected())]
[tokenNm=if(getSelected()=="",getPCNames(),getSelectedNames())]
[Desde=getCurrentMapName()]

Ask for the destination map
[abort(input(
"Fichas|"+tokenNm+"|Tokens|Label",
"map|"+listSort(getVisibleMapNames(),"a")+"|Destination|Radio|value=string"
))]

If the destination isn't the current map, send the token there (at 0,0).
[if(Desde!=map),code:{
	[setCurrentMap(map)]
	[foreach(in,tokenId):moveTokenFromMap(in,Desde,0,0,0)]
	[cambio=1]
	};{
	[cambio=0]
}]

Builds the list of available destinations (tokens in the hidden layer)
[marca=""]
[foreach(in,getTokenNames()):marca=if(getLayer(in)=="GM",listAppend(marca,in),marca)]

Ask for one destination
[if(marca!=""),code:{
[abort(input(
"Lugar|"+marca+"|Place|List|Value=string"
))]
[x=getTokenX(0,Lugar)]
[y=getTokenY(0,Lugar)]
[goto(Lugar)]
};{
[Lugar="mapa"]
[x=0]
[y=0]
}]

Move tokens to the selected destination
[foreach(in,tokenId),code:{
	[moveToken(x,y,0,in)][x=x+1]
	}]
-->

<!--Send output to chat -->
[if(cambio),code:{
[r:tokenNm] taken to map [r:macroLink (map,"Mover@Lib:token","","Dest="+map+";x="+x+";y="+y)]
};{
[r:tokenNm] moved to [r:macroLink (Lugar,"Mover@Lib:token","","Dest="+map+";x="+x+";y="+y)]
}]
The macro is for the use of the GM only, but it send a link for the player to click and be sent to where the token is.

This is the code for the "Mover@Lib:token" macro

Code: Select all

[h:varsFromStrProp(macro.args)]

[h,if(getCurrentMapName()==Dest),code:{
[goto(x,y)]
};{
[setCurrentMap(Dest)] [goto(x,y)]
}]