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

[habort(isGM())]

[
htokenId = if(getSelected()=="",getPC(),getSelected())]
[
htokenNm ""]

[
hCoordinatesInUnits 0]
[
hjsonAllOffsets ""]
[
hreferenceToken listGet(tokenId0)]
[
hxOrigin getTokenX(CoordinatesInUnitsreferenceToken)]
[
hyOrigin getTokenY(CoordinatesInUnitsreferenceToken)]

[
h, foreach(in,tokenId), code: {
    [
htokenNm listAppend(tokenNm,getName(in))]
    [
hxOffset getTokenX(CoordinatesInUnitsin)]
    [
hyOffset getTokenY(CoordinatesInUnitsin)]
    [
hjsonOffset json.set("""x"xOrigin xOffset"y"yOrigin yOffset)]
    [
hjsonAllOffsets json.setjsonAllOffsetsinjsonOffset )]
}]
[
hLst ""]
[
hin  =0]
[
h, while(tbl("Mapa",in)!=tbl("Mapa",in+2)),code:{
    [
hin=in+1]
    [
hLst=listAppend(Lst,listGet(tbl("Mapa",in),3))]
}]

[
hbla=input(
"Fichas|"+tokenNm+"||Label",
"map|"+Lst+"|Destino|Radio"
)]
[
habort(bla)]
[
hmap=map+1]

[
hDest=listGet(tbl("Mapa",map),0)]
[
hx=listGet(tbl("Mapa",map),1)]
[
hy=listGet(tbl("Mapa",map),2)]


[
r,if(getCurrentMapName()==Dest),code:{
    [
h,foreach(in,tokenId),code:{
        [
hjsonOffset json.get(jsonAllOffsetsin)]
        [
hxOffset json.get(jsonOffset"x")]
        [
hyOffset json.get(jsonOffset"y")]
        [
moveToken(x-xOffsety-yOffset,0,in)]
    }]
    [
r:tokenNmmovido(s[r:Dest] [goto(x,y)]
};{
    [
h,foreach(in,tokenId),code:{
        [
hjsonOffset json.get(jsonAllOffsetsin)]
        [
hxOffset json.get(jsonOffset"x")]
        [
hyOffset json.get(jsonOffset"y")]
        [
moveTokenToMap(inDestx-xOffsety-yOffset)]
    }]
    [
r:tokenNmllevado(sal 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,"[email protected]:token","","Dest="+map+";x="+x+";y="+y)]
};{
[r:tokenNm] moved to [r:macroLink (Lugar,"[email protected]: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 "[email protected]:token" macro

Code: Select all

[h:varsFromStrProp(macro.args)]

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