Mini Macro Challenges (Interest)

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Mini Macro Challenges (Interest)

Post by wolph42 »

aliasmask wrote:
Wed Jun 17, 2020 6:06 am
after changing the zoom to 1:1
i don't quite get why you would want that? also its possible that the area you wish to copy is larger than what you see onscreen.

I agree though that 'defining the area' is the biggest challenge. I usually work with upperleft and lowerright tokens to mark off an area and then do what I need to do.

In case of a very large token, yes that would be an issue but I can't see how to omit that. If its upper left is within the 'designated area' it will be copied else not.

and yes this *is* innteresting (I wonder if AM got that hint or understood it), yes only get tokens with a space in the name would be interesting but:
your saying that getting all tokens from map and then go through them is faster than using getTokens() ?? (with designated area)

User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

Re: Mini Macro Challenges (Interest)

Post by bubblobill »

I'm saying it is faster than generating the area. To use area in getTokens you need to generate a json array of json object coordinates for every cell. By the time you have generated the area to getTokens in you would already have been finished doing it another way.

Until getTokens allows you to define an area by polygon feature request it is basically unusable for any dynamic area bigger than about 8x8.

In your use case however, you have a defined construction area that will not vary nor contain extraneous tokens. You could generate and cache the area to search so it ceases to be a burden.
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Mini Macro Challenges (Interest)

Post by aliasmask »

I mention the zoom of 1:1 because of placing the reference token to select your area. If you're zoomed out really far, you may not see the token come in to existence or be able to select it. You can change the zoom afterwards though.

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Mini Macro Challenges (Interest)

Post by aliasmask »

You can't actually getTokens() based on their name, but could filter out tokens that way as with any other property of the token. That method would also have to depend on you to remember to put a space in the token name like when numbering the token. If there is some other significance to "space" in the name, then I do not get it.

I found the biggest slow down is using getTokens(), a filter and having a ton of tokens on the map (layer doesn't matter).

Another possible method, but very tricky and I'm not sure if possible is to use a combination of an overlay, some javascript and getting the viewable area. Basically, the javascript can get the screens x,y as to where you click on the overlay, then you can translate that to the viewable x,y on your screen. But like I said, tricky and complicated and I'm not complete sure if it's supported. Something I want to dabble with in the future.

User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

Re: Mini Macro Challenges (Interest)

Post by bubblobill »

Wolph wants to copy his Inn. The inn is built from tokens that have a name structure without spaces, so any copied tokens from the resource pile will have a space in their name. Is very specific and not generally applicable or useful.
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework

User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

Re: Mini Macro Challenges (Interest)

Post by bubblobill »

I liked your idea of using VBL to define the area. Then you could use something like getVisibleTokens(). I doubt that would return tokens on other layers though.
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Mini Macro Challenges (Interest)

Post by wolph42 »

Thanks for the last input...new challenge, bit more tricky to describe and yes this is (quite obviously) also related to the inn generator.
This is not so much a matter of how would you code this but more a matter of rules and algorithm...

The core question is: how do I fill the bar with random patrons.

the premise:
= I have X races (lets keep this simple and downto the core 4 races (elf, dwarf, human, halfling)
= Per race there are 2 genders
= Per race/gender I have 3 'qualities': poor, common, good (this depends on the type of Inn)
= In total there are thus 24 'class' arrays with tokens (e.g. good-female-halfling array)
= Bar is filled with 'tablegroups' these are either: 4 seat table; 6 seat table or the bar seats (2 to many)
= Currently I place patrons 'groups' per table, so for one table I do the 'random stuff'. I could first create a group and then divide them over the bar but that will be tough to do
= User can divide 100 'presence' points over all 8 race/genders (e.g. 0 points for female dwarves means: no female dwarves; 100 points for elf males means: elf male only)
= User can set a 'crowdedness' level for the bar (0=empty; 100=full). Event this crowdedness algorithm is already fairly complex. But works per seat group, e.g. most likely with a level 50 crowdedness there will be 3 people at a 6 seat table.
= Currently when I create a group to place at a table I draw tokens from ONE class array so at a table it will always be 1 race and 1 gender (and one 'quality').

the questions:
1. the most urgent question is: I want to add a 'mix factor %' eg. 0=full segregation and 100=full integration
Lets say that factor is 75% how do I mix the class arrays ALSO given the fact that there are the 'presence' points. And what does '75' even mean?? Alternatively I could also create a radio button; 'no, a bit, full' integration. Making it simpler but still the question of how?

2. can you think of a better method to do this overall, so entirely different mechanics to reach the same result.


User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Mini Macro Challenges (Interest)

Post by aliasmask »

I had some thoughts, but it was kind of complicated to write out the details. Basically, what I was thinking is you generate your pool of patrons based on the percentages then seat them one at a time based on preferences of the one going to sit and the ones already at a table, then roll randomly if there was no strong preference (50% or less). Kind of like natural decision making.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Mini Macro Challenges (Interest)

Post by wolph42 »

what I went for is:
first user gives percentages of a group being all human, elf, etc. e.g. 75% human, 10% elf, 5 dwarf etc.
initially I created an array of 100 items representing the percentages (so 75 x'human', 10 xelf, 5xdwarf), randomized the array and per group just picked the first array item. (on empty reshuffle array).

next the user gives a percentage of the 'mix' of the group. This again creates an array but this time per race:
humanArray: consists out of 75 humans and (mix% x elf) and (mix% x dwarf).
elfArray: 10 elf + mix% x human + mix% dwarf
dwarArray....
Again randomize array and when building a group simply draw tokens from it.

The thing that makes this additionally tricky is the fact that the eventual tokens are ALSO randomized, so i require a 3rd array of the actual tokens, one array per race/gender combo

And what makes it additionallly complicated is the fact that not ALL settings (fantasy,scifi,other) and not all qualities (poor, common, good) have to be present, the code then picks tokens from another setting or another quality (e.g. if there are no poor-scifi-elf tokens, then you can end up with common-fantasy-elf tokens) so this is an additional abstract layer over all the above code...

User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

New Macro Challenge

Post by bubblobill »

Here is the challenge

Whilst moving a PC detects a trap so they stop moving before setting it off.

Context: onTokenMove checks movedOverToken against a list of traps and then performs a perception check. If successful a function is called to stop movement and reveal the location of the trap.

Given: the ID of a PC(not snapped to grid), the lastPath array, and the ID of a token moved over.
Task: stop the PC along the path so that it is touching but not overlapping the moved over token.
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Mini Macro Challenges (Interest)

Post by wolph42 »

those traps are already in the BoT, e.g. this is the pit trap:
pit trap

Code: Select all

[h:'<!-----------------------------Standard Pit (trapped)---------------------------------->']
<!-- Here you enter the code to apply the effect of the pit Example is given -->
<!-- NOTE THAT ALL OUTPUT IS IGNORED, SO THE ONLY WAY TO GET SOMETHING TO THE CHAT IS BY USING BROADCAST! -->

<!-- check which event this token triggers this can be 
- movedOn 
- movedOff 
- movedOver 
- movedReturn	when you move the token AND use way points AND leave the token but end the move onto the token
-->

[h:me					= arg(0)]
[h:event				= arg(1)]
[h:padName				= arg(2)]
[h:lastPath 			= arg(3)]
[h:eventPadTriggered	= arg(4)]
[h:triggerType			= arg(5)]

<!-- assert that the trigger is a pad event -->
[h:assert(triggerType == "pad", "The GM has assigned a wrong trigger type: <i>"+triggerType+"</i> to this pad", 0)]

[h:switchToken(me)]
[h:trapped = if(event=="movedOff" || event=="movedReturn",1,0)]

[h:attackRoll = 1d20]
[h,if(attackRoll > Dexterity), CODE:{
	[h:'<!--Failed Ag Test-->']
	[h:entryPoint = json.get(eventPadTriggered, 0)]
	[h:x = json.get(entryPoint, "x")]
	[h:y = json.get(entryPoint, "y")]
	[h:iEntryPoint = json.indexOf (lastPath, entryPoint)]
	[h:lastPath = if(trapped, json.get(lastPath, 0, 0), json.get(lastPath, 0, iEntryPoint-1) )]

	[h, token(padName): setTokenImage(getTokenHandout())]
	[h: moveToken(x, y)]
	[h: txtOut = if(trapped,"You failed to climb out<br>","you've fallen into a pit<br>")]
	[h: AgTest = "Failed"]
}; {
	[h:'<!--Succeeded Ag Test-->']
	[h: txtOut = if(trapped,"You succeed to climb out<br>", "You nearly fell into a pit, but succeeded your Ag test. Rethink your next move!!<br>")]
	[h: AgTest = "Success"]

	[h:'<!-- if you move into (and not over) the pit and succeed your Ag check, you are pushed back to the edge of the pit. This means that a player cannot move into a pit voluntarily -->']
	[h, if(event == "movedOn"), CODE: {
		[entryPoint		= json.get(eventPadTriggered, 0)]
		[iEntryPoint	= json.indexOf (lastPath, entryPoint)]
		[edgePoint		=  json.get(lastPath, iEntryPoint-1)]
		[lastPath		=  json.get(lastPath, 0, iEntryPoint-1)]
		
		[x				= json.get(edgePoint, "x")]
		[y				= json.get(edgePoint, "y")]
		[moveToken(x, y)]
	}]
}]
[h:broadcast(txtOut)]
[h:macro.return = lastPath]
unless things have changed, I don't think this works with movedOverToken AND not snapped to grid. Cause snap returns ALL cell coords, while unsnapped returns only the begin and end coord (and I guess the waypoints as well).

User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

Re: Mini Macro Challenges (Interest)

Post by bubblobill »

So what you're saying is that you haven't managed to beat the challenge because you can only do snap-to-grid.
STG is easy; which is why it is not part of the chllenge.
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework


User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Mini Macro Challenges (Interest)

Post by aliasmask »

The methods to detect when tokens or other things that are moved over relies on the stamp or footprint, but registers which grid cell they're in. So, no real way to full eliminate the grid.

Post Reply

Return to “Macros”