Beam me up, Scottie

Show off your RPG maps, campaigns, and tokens. Share your gaming experiences and stories under General Discussion and save this forum for things you've created that may help others run their own games. Use the subforums when appropriate.

Moderators: dorpond, trevor, Azhrei, Gamerdude

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

Re: Beam me up, Scottie

Post 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)]
}]
 

User avatar
PinkRose
Dragon
Posts: 732
Joined: Sat Nov 15, 2008 2:28 pm
Location: The City of Roses, Oregon

Re: Beam me up, Scottie

Post by PinkRose »

Thank you so much.
As a non-coder, I sincerely appreciate it.
I am a special snowflake!

User avatar
patoace
Dragon
Posts: 313
Joined: Mon Sep 24, 2007 6:10 pm
Location: Rancagua - Chile

Re: Beam me up, Scottie

Post 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)]
}]

Post Reply

Return to “User Creations”