Can anyone help me please

If you have searched the other User Creations subforums and an answer to your question has not been found, please post here!

Moderators: dorpond, trevor, Azhrei, Gamerdude

Post Reply
ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Can anyone help me please

Post by ralstad »

Ok,

I have tried figuring this out, how do I get a macro to give a list of possible enemy targets so a player can select which target to attack?

Next once I get this how do I get a defense number from said target?

Thanks for the help guys, this will also help with a couple of other questions but the second question will answer enough so I can figure out coding for other things.

I am creating a campaign based on the anime "Is it wrong to try to pick up girls in a dungeon".
Players won't know any of the bonus's their stats get and am trying to automate most things so they can't figure it out.

ralstad

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

Re: Can anyone help me please

Post by aliasmask »

There are several examples for targeting (here is one: http://forums.rptools.net/viewtopic.php ... 52#p257652)

To get data from a token I recommend using Wiki: switchToken() and getProperty.
I am creating a campaign based on the anime "Is it wrong to try to pick up girls in a dungeon".
Fun anime. Second season airs in April, but not sure when English sub/dub will come out to US though.

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Can anyone help me please

Post by ralstad »

Ya, I loved the anime it was fantastic.
I thought it might be fun to play a D&D type game in that world.
The only thing the characters are going to know is just like in the anime they are going to know their ranking in their stats and any special abilities they gain over time and magic but not what anything really does.
The biggest problem is none of the frameworks I have seen work anywhere with this type of game, so building from the ground up.
I did a lot of VB programming and have a good hold on that and it seems a decent amount of the coding is similar but just not quite enough to truly start coding.

I have a quick question for anyone that will answer here is the formula I use to figure the number of attack a character will have

[R: (floor(if((Agility>799),round(Agility/200),floor(Agility/200))+if((Dexterity>799),round(Dexterity/200),floor(Dexterity/200))/6)+1)]

Now to explain in this formula you take the agility and dexterity modifiers, the ifs figure this part out, and add them together then divide them by 6 and add the starting 1 attack everyone starts with but for some reason on one character I tested it on with a dexterity of 300 and an agility of 400 it is totaling it out to 3 attacks but it should only be one, rounded down of course.

Thanks

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

Re: Can anyone help me please

Post by aliasmask »

How about something like this:

Code: Select all

[H: agilityMod = if(Agility >= 800,round(Agility/200)/6,floor(Agility/200)/6)]
[H: dexterityMod = if(Dexterity >= 800,round(Dexterity/200)/6,floor(Dexterity/200)/6)]
[H: numberOfAttacks = floor(agilityMod + dexterityMod + 1)]
So, dex 300 gives 1/6, agility 400 gives 2/6 and you add 1 which is 1.5 and floors to 1. Your formula didn't 1/6th the agility.

I like to break complex formulas up on multiple lines for an easy read and if needed, convert it to a single formula if speed seems to be a factor.

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Can anyone help me please

Post by ralstad »

Thanks for the help. I took your parts and used them to correct what was wrong. I couldn't use it the way you set it up because it is on each token as a property.

I do have another question, I went to the page you suggested for targeting and used that macro but all it does is pop up a picture in the chat window and next to the token picture it gives the name of the token like it is trying to type something.

Code: Select all

<!-- getSeenTokens(options,source): json array or object 

options (strprop or json object)
   pc - 0 any token, 1 - PC only
   npc - 0 any token, 1 - NPC only
   range - upto this distance in grid units (ie feet, and not grid squares); 0 - any range
   self - 0 do not include self, 1 include self
source = source token, defaults to currentToken
   
This function will get a list of tokenIds based on the current tokens vision 
-->

[H, if(argCount()): options = lower(arg(0)); options = "{}"]
[H, if(argCount() >= 2): sourceToken = arg(1); sourceToken = currentToken()]

<!-- verify token is on current map -->
[H: sourceToken = findToken(sourceToken)]

[H: assert(! json.isEmpty(sourceToken),"<b>getSeenTokens(options,source):</b> Token not found on current map.",0)]

<!-- define options locally -->
[H: defaults = json.set("{}","pc",0,"npc",0,"range",0,"self",0)]
[H, if(json.type(options) == "UNKNOWN" && ! json.isEmpty(options)): options = json.fromStrProp(options)]
[H, if(json.isEmpty(options)): options = defaults; options = json.merge(defaults,options)]
[H: varsFromStrProp(json.toStrProp(options))]

<!-- get token ids -->
[H: conditions = "{}"]
[H, if(npc && ! pc): conditions = json.set(conditions,"npc",npc)]
[H, if(! npc && pc): conditions = json.set(conditions,"pc",pc)]
[H, if(range): conditions = json.set(conditions,"range",json.set("{}","token",sourceToken,"upto",range,"distancePerCell",1))]
[H, if(! json.isEmpty(conditions)): tokenIds = getTokens("json",conditions); tokenIds = getTokens("json")]

<!-- exclude self if set -->
[H, if(self), code: {
   [H, if(! json.isEmpty(tokenIds)): tokenIds = json.union(tokenIds,json.append("",sourceToken)); tokenIds = json.append("",sourceToken)]
};{
   [H, if(! json.isEmpty(tokenIds)): tokenIds = json.difference(tokenIds,json.append("",sourceToken)); tokenIds = "[]"]
}]

<!-- check each id for name and visible -->
[H: targets = "[]"]
[H: hasSight = hasSight()]
[H, if(! hasSight()): setHasSight(1)] <!-- this works for NPC tokens too -->
[H, foreach(tokenId,tokenIds), code: {
   [H: canSee = ! json.isEmpty(canSeeToken(tokenId))]
   [H, if(canSee): targets = json.append(targets,tokenId)]
}]
[H, if(hasSight != hasSight()): setHasSight(hasSight)]

[H: macro.return = targets] 


Is there something I need to change to make this work?

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

Re: Can anyone help me please

Post by wolph42 »

this is a function macro. That means that you can use it in your code, however in order to do that you first need to create a userdefinedfunction: "getSeenTokens" in the onCampaignLoad macro. When you've done that you can do e.g.:

Code: Select all

[h:me = getSelectedNames()]
[h:assert(listCount(me)==1,"Make sure (only) one token is selected",0)]
[h:seenTokens = getSeenTokens('["pc=0;npc=1;self=0;range=30"]')]

The NPC you can see in a vicinity of 30 is [r:seenTokens] 
untested.

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Can anyone help me please

Post by ralstad »

So I create a new macro called onCampaignLoad then put

Code: Select all

[h:me = getSelectedNames()]
[h:assert(listCount(me)==1,"Make sure (only) one token is selected",0)]
[h:seenTokens = getSeenTokens('["pc=0;npc=1;self=0;range=30"]')]
in the command box and that will allow me to use it?


ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Can anyone help me please

Post by ralstad »

I think I understand. Lets see.
Ok, I placed a token on my map called "Lib:Token" then
in the token I created 2 macros

1st being "onCampaignLoad"

Code: Select all

[defineFunction("getSeenTokens", "getSeenTokens@Lib:Token")]
2nd being "getSeenTokens"
with the code above

then i created a macro to call the "getSeenTokens" called "target" in my campaign macrosusing your code

Code: Select all

[h:me = getSelectedNames()]
[h:assert(listCount(me)==1,"Make sure (only) one token is selected",0)]
[h:seenTokens = getSeenTokens('["pc=0;npc=1;self=0;range=30"]')]

The NPC you can see in a vicinity of 30 is [r:seenTokens] 
is that correct?

ok tested what i did above and get an error of

Code: Select all

   Error in body of roll.
Statement options (if any): h
Statement Body : seenTokens = getSeenTokens('["pc=0;npc=1;self=0;range=30"]')
What am I missing?

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

Re: Can anyone help me please

Post by wolph42 »

Did you run oncampaignload once or saved and restarted the campaign?

And I think it's

getSeenTokens("pc=0;npc=1;self=0;range=30")]

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

Re: Can anyone help me please

Post by aliasmask »

I prefer

Code: Select all

[H: options = json.set("{}","pc",0,"npc",1,"self",0,"range",30)]
[H: seenTokens = getSeenTokens(options)]
json formatting uses : and not =. You should almost always use the constructor to build your json.

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Can anyone help me please

Post by ralstad »

ok, saved reloaded.

then ran the "target" macro from my campaign macros with the following code

Code: Select all

[H: options = json.set("{}","pc",0,"npc",1,"self",0,"range",30)]
[H: seenTokens = getSeenTokens(options)]
and I get.

Code: Select all

Error in body of roll.
Statement options (if any): H
Statement Body : seenTokens = getSeenTokens(options)
What am I messing up?

I am looking at the "target" macro does this call the "getSeenTokens" macro?

Code: Select all

[H: seenTokens = getSeenTokens(options)]
I don't see where it calls that macro to run is this where my problem is coming in at?

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

Re: Can anyone help me please

Post by aliasmask »

Make sure getSeenTokens has the allow players to edit unchecked (preferences of macro). Unfortunately, the default is to always have it on. That's one reason why I use RPEdit because it turns it off by default.

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Can anyone help me please

Post by ralstad »

Thanks for your guys help on the function I tried to use but couldn't get it to work right.
I found a macro that will give me what I want.
I used the targeting macro from

http://lmwcs.com/rptools/wiki/Forms_tutorial#Click-based_Target_selection

Now the question I have is changing the button in this code

Code: Select all

<input type="submit" name="btn_submit" value="Perform action">
To a button that used the image of a d20 in the default resources folder.

Post Reply

Return to “Requests for HELLLLP!”