Can someone combine two macros for me?

Talk about whatever topic you'd like, RPG related or not. (But please discuss things related to our software in the Tools section, below.)

Moderators: dorpond, trevor, Azhrei

Underableedingsun
Kobold
Posts: 16
Joined: Fri Mar 02, 2012 4:20 am

Can someone combine two macros for me?

Post by Underableedingsun »

This is way above my skill level, but I'm thinking these two tokens can be combined to work flawlessly together. This is for the Fallout PNP game, The first one posted targets someone and takes their armor and cover penalties into consideration. The 2nd one automatically does the damage and reduces damage for DR and DT.

The first one:

Code: Select all

[code][h:Lselect=if(Lmod=="Great Light",0,if(Lmod=="Good Light",1,if(Lmod=="Average Light",2,if(Lmod=="Bad Light",3,if(Lmod=="Dim Light",4,if(Lmod=="No Light",5,if(Lmod=="Light Rain",6,if(Lmod=="Medium Rain",6,if(Lmod=="Heavy Rain",7,if(Lmod=="Storm",8,0))))))))))]
[h:Vrange=(Prange+Per)*3]

[H: visTokens = "[]" ]
[H: visTokenIDs = getVisibleTokens("json") ]
[H, FOREACH( i, vistokenIDs ): visTokens = json.append( visTokens, json.set( "{}", "name", getName(i), "id", i, "range", getDistance(i) ) ) ]
[H: visTokens = json.sort( visTokens, "ascend", "range", "name" ) ]
[H: visTokenNames = "[]" ]
[H, FOREACH( i, visTokens ), CODE: {
   [ visTokenRange = json.get( i, "range" ) ]
   [ visTokenNames = json.append( visTokenNames, "(" + if( visTokenRange <= Vrange, "<font color=red>", "" ) + visTokenRange + " hexes" + if( visTokenRange <= Vrange, "</font>", "" ) + ") " + json.get( i, "name" ) ) ]
}]

[H: visTokenNameList = "Not Specified" ]
[H, FOREACH( i, visTokenNames, "" ): visTokenNameList = listAppend(visTokenNameList, "<html>" + replace( i, ",", "_" ) +  "</html>" ) ]



[H: input(
"tTarget1 | " + visTokenNameList + " |Target|LIST|",
"hitbonus|0|To Hit Mod",
"CoverMod|0|Cover Mod",
"TargetMod|Torso,Legs,Arms,Groin,Head,Eyes|Aimed Shot|LIST|SELECT=0 VALUE=STRING",
"LMod|Great Light,Good Light,Adverage Light,Bad Light,Dim Light,No Light,Light Rain,Medium Rain,Heavy Rain,Storm,Blizzard|Lighting/Weather|LIST|SELECT="+Lselect+" VALUE=STRING",
"Threshold|0|Damage Threshold",
"Resistance|0|Damage Resistance")]




[H, IF( tTarget1 == 0 ): target1ID = ""; target1ID = json.get( json.get( visTokens, tTarget1-1 ), "id" ) ]
[H, IF( tTarget1 == 0 ): target1Name = ""; target1Name = json.get( json.get( visTokens, tTarget1-1 ), "name" ) ]

[H: targString = "" ]
[H: targString = if( target1Name == "", "", "<b>Target: </b>" + target1Name ) ]
[H: targString = targString + if( target1Name == "", "", "<br>" ) ]

<table border="0"><tr bgcolor="#000000"><table width="100%"><tr><td style="padding:0px 5px;">
<span style="color:#33FF00"><b>
{targString}
</font></td></tr></table></tr><tr><td>

[h:TargetAC=getProperty("AC",target1ID)]
[h:Distance=getDistance(target1ID)]

[h:Skill=Pskill]

<table border="0"><tr bgcolor="#000000"><table width="100%"><tr><td style="padding:0px 5px;">
<span style="color:#33FF00"><b>
{PrimaryWeapon}
</b></font></td><td style="padding:0px 5px;" align=right><span style="color:#33FF00">
{Skill}:{Base=Eval(Skill)}
</font></td></tr></table></tr><tr><td>
<B>Distance: </b>[t:D=Distance] Hexes

[H:Rangemod=(3*(D-(PER+PRange)))]
[H:R=if(Rangemod<0,"0",Rangemod)]
<br>
[h:L=if(Lmod=="Great Light",0,if(Lmod=="Good Light",10,if(Lmod=="Average Light",20,if(Lmod=="Bad Light",50,if(Lmod=="Dim Light",80,if(Lmod=="No Light",200,if(Lmod=="Light Rain",30,if(Lmod=="Medium Rain",40,if(Lmod=="Heavy Rain",60,if(Lmod=="Storm",80,0))))))))))]
[h:A=TargetAC]
[h:C=CoverMod]
[h:S=if(TargetMod=="Torso",0,if(TargetMod=="Legs",10,if(TargetMod=="Arms",15,if(TargetMod=="Groin",15,if(TargetMod=="Head",20,if(TargetMod=="Eyes",30,0))))))]
[h:ACC=if(TargetMod=="Torso",0,if(TargetMod=="Legs",20,if(TargetMod=="Arms",10,if(TargetMod=="Groin",20,if(TargetMod=="Head",25,if(TargetMod=="Eyes",30,0))))))]


<B>Hit Chance: </b>[T:tohit=Base-R-L-A-C-S+hitbonus]



<br>
<b>Attack Roll:  [t:Roll=1d100] [t:if(Roll<=tohit,", Hit",", Miss - 1 To Weapon Condition")]<b>[t:if(Roll<=(CC+ACC),", Critical!","")]</b>
<br>
[h:Dice=PammoDMG]
[h:Bonus=PDamage]
[h:Roll=Dice+"+"+Bonus]
[h:DMG=Eval(Roll)]
[h:T=Threshold]
[h:R=Resistance]
<b>Damage; </b>[t:Round((Dmg-T)-((DMG-T)*(R*0.01)))]
<br>
<small><i>Remaining Ammo:[t:PRounds=PRounds-1]
[t:Ammocheck= if(Prounds<=0,"Out of Ammo!","")]
[/code]


The 2nd one:

Code: Select all

[h:status = input(
"InitDamage|0|How much damage did you take?",
"DRChange|0|Any modifiers to DR?", 
"DTChange|0|Any modifiers to DT?",
"Defenses|Normal,Laser,Fire,Plasma,Explosive,Electricity|What's the damage type?|RADIO|SELECT=0")]
[h:abort(status)]
<!--
[if(Defenses ==5), CODE:
 {
  [Damage= floor(InitDamage*(min(100, (100-(ER+DRChange)))/100))]
 };
{""}
]
[if(Defenses ==4), CODE:
 {
  [Damage = floor((InitDamage-max(0, (EDT+DTChange)))*(min(100, (100-(EDR+DRChange)))/100))]
 };
{""}
]
[if(Defenses ==3), CODE:
 {
  [Damage = floor((InitDamage-max(0, (PDT+DTChange)))*(min(100, (100-(PDR+DRChange)))/100))]
 };
{""}
]
[if(Defenses==2), CODE:
 {
  [Damage= floor((InitDamage-max(0, (FDT+DTChange)))*(min(100, (100-(FDR+DRChange)))/100))]
 };
{""}
]
[if(Defenses==1), CODE:
 {
  [Damage= floor((InitDamage-max(0, (LDT+DTChange)))*(min(100, (100-(LDR+DRChange)))/100))]
 };
{""}
]
[if(Defenses==0), CODE:
 {
  [Damage= floor((InitDamage-max(0, (NDT+DTChange)))*(min(100, (100-(NDR+DRChange)))/100))]
 };
 {""}
]

[if(Damage <0), CODE:
   {
    [FinalDamage=0]
   };
   {[FinalDamage=Damage]}
]
-->

{FinalDamage} points of damage are taken


[h: dmgOrHealing = 0]
 
[if(dmgOrHealing == 0),CODE:
{
    [h:HP = HP - FinalDamage]
    [h:bar.Health = HP / MaxHP]
    [r:token.name] loses [r:FinalDamage] hit points.
};
{
    [h:diff = MaxHP - HP]
    [h:HP = min(HP+FinalDamage, MaxHP)]
    [h:bar.Health = HP / MaxHP]
    [r:token.name] is healed and gains  [r:min(diff,FinalDamage)] hit points. 
};]

{token.name}'s HP is {HP}. <br>
<!--
[Condition = ""]
[if(HP <=0), CODE: { [if(HP<0), CODE: { [Condition = if(HP> (-1*Endurance), token.name + " is unconscious!", token.name + " is dead!")] };
 {  [Condition = token.name +" is staggered!"] } ]};
{ [Condition = ""]}]
[IsUnconscious = if(HP > -1*Endurance && HP < 0, 1, 0)]
[IsDead = if(HP <= -1*Endurance, 1, 0)]
[state.Unconscious = IsUnconscious]
[state.Dead = IsDead]
-->
{Condition}[/color]
If you can thanks, and if you try and can't thanks as well.
Last edited by Underableedingsun on Tue Feb 12, 2013 4:53 pm, edited 2 times in total.

meshon
Cave Troll
Posts: 75
Joined: Fri Mar 26, 2010 10:54 am
Location: AB, Canada

Re: Can someone combine two macros for me?

Post by meshon »

Hi, I was just thinking that if you uploaded a .cmpgn file it would be easier to work on and test. Also I think you can use a

Code: Select all

Code Tag
to separate your macro code out which makes it a bit easier to read.

At first glance I would suggest using a [dialog:] instead of your inputs, since the input that starts the second macro probably interrupts the flow. Also it looks like the second mcro's input is run by the target of the attack?

Anyway, there's some good tutorials for using forms and dialogs to get information. It's not too hard to figure out; if I can manage it you probably can too!

Here is the link to a tutorial:
Forms tutorial and check out Click-based target selection.


But if you post the .cmpgn file I wouldn't mind trying it out.

cheers,
Meshon

Edit: I managed to use my first wiki link(!) but couldn't quite get the article to link properly.
Last edited by meshon on Mon Feb 11, 2013 7:26 pm, edited 1 time in total.

Underableedingsun
Kobold
Posts: 16
Joined: Fri Mar 02, 2012 4:20 am

Re: Can someone combine two macros for me?

Post by Underableedingsun »

Ya, honestly, these were both programmed by 2 different people for me. I did add the electricity damage to the damage one, but even that was pretty tough for me, and I was basically only copying work. My program fu is pretty weak.

Anyway, heres the campaign file. Thanks.
Attachments
Fallout2.1.cmpgn
(1.28 MiB) Downloaded 85 times

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

Re: Can someone combine two macros for me?

Post by wolph42 »

It would still help a lot if you put the tags in your first post!

And what the hell do you mean with :
The first one posted automatically targets someone and takes armor and cover penalties into light.

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Can someone combine two macros for me?

Post by aliasmask »

meshon wrote:Edit: I managed to use my first wiki link(!) but couldn't quite get the article to link properly.
There are 3 wiki related buttons, wfunc, wiki and wroll. wfunc is for any of the functions that appear on the function page. wroll are for any of the roll options that appear on the Roll Option page. Those actual pages are category pages and don't have a button for them. The wiki pages have .../wiki/Page_Name format and the wiki button will work for those, but don't put in the _ from the name. So, Forms Tutorial doesn't work because the name is case sensative, but Forms tutorial does.

Literal text:

Code: Select all

[wiki]Forms tutorial[/wiki]

meshon
Cave Troll
Posts: 75
Joined: Fri Mar 26, 2010 10:54 am
Location: AB, Canada

Re: Can someone combine two macros for me?

Post by meshon »

Just to be clear, the names of the macros that you've posted above are (from the campaign file):
1. Cyd's working
2. DT & DR -0 Edit 3

Is that correct?

Also the value for Lmod doesn't seem to be defined. I will take a good look tonight or tomorrow.

cheers,
Meshon

Underableedingsun
Kobold
Posts: 16
Joined: Fri Mar 02, 2012 4:20 am

Re: Can someone combine two macros for me?

Post by Underableedingsun »

Sorry, it should say this:

The first one posted targets someone and takes their armor and cover penalties into consideration.

Sorry, this is probably stupid but, what are tags?

Underableedingsun
Kobold
Posts: 16
Joined: Fri Mar 02, 2012 4:20 am

Re: Can someone combine two macros for me?

Post by Underableedingsun »

Ya, Primary weapon macro, which should be the same as Cyd's working.

meshon
Cave Troll
Posts: 75
Joined: Fri Mar 26, 2010 10:54 am
Location: AB, Canada

Re: Can someone combine two macros for me?

Post by meshon »

aliasmask wrote:There are 3 wiki related buttons, wfunc, wiki and wroll. wfunc is for any of the functions that appear on the function page. wroll are for any of the roll options that appear on the Roll Option page. Those actual pages are category pages and don't have a button for them. The wiki pages have .../wiki/Page_Name format and the wiki button will work for those, but don't put in the _ from the name. So, Forms Tutorial doesn't work because the name is case sensative, but Forms tutorial does.

Literal text:

Code: Select all

[wiki]Forms tutorial[/wiki]
Thank you so much!

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Can someone combine two macros for me?

Post by aliasmask »

Btw, select all your "code" and then click the "Code" button in the editor. This will surround your code in the proper formatting, including spacing.

Code: Select all

[code]Your code in here...
[/code]
You can also use =php to add a little color to the code. Sometimes though, there may be a certain combination of characters (never discovered which) that will not display it when using =php and all your code will disappear. Don't panic. Just hit the back button to the editor and remove the =php.

Code: Select all

[code=php]Your fancy code in here...
 [/code]

meshon
Cave Troll
Posts: 75
Joined: Fri Mar 26, 2010 10:54 am
Location: AB, Canada

Re: Can someone combine two macros for me?

Post by meshon »

Well, I keep coming up against undefined variables which prevent me from running the macros so I can't really tell how they're supposed to operate. It is probably just that I'm unfamiliar with the game.

I would recommend starting from scratch with your attack macro, mainly because you will learn a whole lot about making macros that way and be in a good position to add more features to your set up. I would recommend this forum post for figuring out how to get the targeting working:
http://www.forums.rptools.net/viewtopic ... 20&t=15998
I used Cif's code from there and played around until I (more or less) understood it. Just searching these forums answers most of the questions I ever have.

cheers,
Meshon

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Can someone combine two macros for me?

Post by aliasmask »

Code is a hot mess, but I've seen worse. I'll take a shot at what you want it to do sometime tomorrow. But did you want to do something like this: http://forums.rptools.net/viewtopic.php ... 82#p224182

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

Re: Can someone combine two macros for me?

Post by wolph42 »

aliasmask wrote:Code is a hot mess,
you can say that again
aliasmask wrote: but I've seen worse.
should I take that as an insult :mrgreen:

@OP: I 'tagged' the first macro so you can see what 'tags' are. And we means 'code' tags not 'color' tags.
Usually we also add manually =php to the code tag so:[c o d e=php][/c o d e] but when the code is too long that won't work and the actual code dissapears!! (which appears to be the case with the first macro)
Anyway there you have it. You can edit the macro to check it out.

tip: if you see something fancy in someone's post and want to know how they did it: click the 'quote' button of the post and you can check it out.

and for the fun off it I rewrote the 2nd macro to a more condensed version:

Code: Select all

[h:abort(input(
    "InitDamage|0|How much damage did you take?",
    "DRChange|0|Any modifiers to DR?", 
    "DTChange|0|Any modifiers to DT?",
    "Defenses|Normal,Laser,Fire,Plasma,Explosive,Electricity|What's the damage type?|RADIO|SELECT=0"
))]


[h:mod1            = eval(listGet("NDT, LDT, FDT, PDT, EDT, -DTChange", Defenses))]
[h:mod2            = eval(listGet("NDR, LDR, FDR, PDR, EDR, ER", Defenses))]
[FinalDamage    = max(0, floor(    (InitDamage-max(0, (mod1+DTChange)))    *    (min(100, (100-(mod2+DRChange)))/100)    ))]

[h:txtOutput    = FinalDamage + " points of damage are taken"]

[h:HP            = HP - FinalDamage]
[h:bar.Health    = HP / MaxHP]
[h:txtOutput    = txtOutput + token.name + " loses " + FinalDamage + " hit points. " + "Current HP: " + HP + "<br>"]

[h,if(HP < 0):
    txtOutput = txtOutput + if(HP > (-1*Endurance), token.name + " is unconscious!", token.name + " is dead!")
;
    txtOutput = txtOutput + token.name + " is staggered!"
]

[h:state.Unconscious    = if(HP  > -1 * Endurance && HP < 0, 1, 0)]
[h:state.Dead            = if(HP <= -1 * Endurance, 1, 0)]

[r:txtOutput]

 
Untested! (might contain a few typos)

the most condensation took place with the IF(defenses) statements. This should have been a [switch:] but as it depends on numbers from 0 to 5 its ideal to use listGet instead. For that 2 things were needed:
1. all 6 lines had to be 'the same' , that is: bla blab(mod1) bla blab bla(mod2), all the lines fit that bill except defenses==5, so that line had to be rewritten in such a manner that it follows the same structure but the first part also should alway result in 'initDamage', so the result has to be initDamage - 0, which means that 'something+DTChange' had to be 0 and the only thing that fits that is -DTChange+DTChange.

edit: as CIF nicely commented, a list returns a 'value' not a 'variable' containing that value. The value returned in this case is the *name* of the variable, e.g. "NDT" to turn that into the *value* that the variable NDT contains you need to evaluate it so :
[h:NDT = 5]
[r:eval("NDT")]
will return 5.
of course
[r:NDT] will also return 5. As that is the value that the variable NDT contains.

Now that all the lines are the same you only have 6 modifiers that differ per defense type. By adding them to a list and grabbing the right one you can fix that. And this is done with listGet:
e.g.
listGet("a,b,c", 0) will grab the 0th item from the list "a,b,c", which is the first, which is 'a'
listGet("a,b,c", 2) will thus result in 'c'.

From this you can also immediately see that the values NDT, RDT, etc, need to be comming from somewhere (as was asked in an earlier post). If these are not defined or retrieved then obviously it will lead to errors.

I hope this makes sense.

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

Re: Can someone combine two macros for me?

Post by CoveredInFish »

Is this a typo or a clever, undocumented trick of some sort I dont know of yet?

Code: Select all

[h:mod1            = listGet(NDT, LDT, FDT, PDT, EDT, -DTChange, Defenses)]
AFAIK listGet takes 2 or 3 parameters. So I assume you want a list "NDT, LDT, ..." .. but then you'd be missing an eval() to turn those strings into values .. or I dont get whats going on here :?: :mrgreen:

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

Re: Can someone combine two macros for me?

Post by wolph42 »

CoveredInFish wrote:Is this a typo or a clever, undocumented trick of some sort I dont know of yet?
this falls nicely into the 'typo' category... you're entirely right it should be

Code: Select all

[h:mod1            = eval(listGet("NDT, LDT, FDT, PDT, EDT, -DTChange", Defenses))]

Post Reply

Return to “General Discussion”