If Statement that Checks for LoS

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

Post Reply
User avatar
elaxter
Kobold
Posts: 8
Joined: Thu Jul 20, 2017 7:27 pm

If Statement that Checks for LoS

Post by elaxter »

I have a macro that comes from the GURPS Framework at this link and it features a pretty slick attacking macro that brings up a list of valid targets and whatnot. It works great most of the time, but it seems that the VBL has no effect on whether a token is visible or not.

Here's the code from the macro:
Spoiler

Code: Select all

[h:selectTokens(currentToken())]
[h:currManeuver=getProperty("currManeuver")]

[h, if(json.isEmpty(currManeuver)): continueMacro=0; continueMacro=1 ]
[h:exitMsg=getName(currentToken())+" has not chosen a maneuver.  <br> On your turn, pick a maneuver, pick a weapon, and attack something."]
[s,h: assert (continueMacro,exitMsg,0)]  

<!-- Setting up weapon variables from arguments -->
[h:args=json.fromStrProp(macro.args)]
[h:attacker=json.get(args,"attacker")]
[h:weaponUsedIndex=json.get(args,"currItemIndex")]
[h:methodUsed=json.get(args,"method")]
[h:weaponUsed=json.get(inventory,weaponUsedIndex)]
[r:minReach=json.get(weaponUsed,methodUsed+"minReach")]
[r:maxReach=json.get(weaponUsed,methodUsed+"maxReach")] 

<!-- Setting up maneuver bonus variables -->
[h:currManeuverName=json.get(currManeuver,"name")]
[h:manSkillBonus=json.get(currManeuver,"offSkillBonus")]
[h:manSkillLimit=json.get(currManeuver,"offSkillLimit")]
[h:rangeBonus=json.get(currManeuver,"rangeBonus")]
[h:manDamageBonus=json.get(currManeuver,"damageBonus")]

<!-- Determining penalty from attacker's posture -->
[h:postureList=getTokenStates("json", "Postures")]
[h:posture="standing"]
[h:attackerPostureMod=0]
[foreach(p, postureList,""), h , code: { [h,if(getState(p)):posture=p;""] } ]
[h, if (posture == "crouching" || posture == "kneeling" || posture == "sitting" ) : attackerPostureMod=-2;""]
[h, if (posture == "crawling" || posture == "face_up" || posture == "prone" ) : attackerPostureMod=-4;""]

<!-- Setting up conditions to determine which tokens are possible targets -->
[h:range=json.set("{}","token",attacker,"from",minReach,"upto",maxReach+rangeBonus,"distancePerCell",0)]
[h:NPCsInRange=json.set("{}","range",range,"npc",1,"visible",1)]
[h:PCsInRange=json.set("{}","range",range,"pc",1,"visible",1)]

<!-- Setting up list of possible targets -->
[if( isPC() ), h, code : {
  [h:targetListFirst=getTokens(",",NPCsInRange)]
  [h:targetListSecond=getTokens(",",PCsInRange)]
};{
  [h:targetListFirst=getTokens(",",PCsInRange)]
  [h:targetListSecond=getTokens(",",NPCsInRange)]
}]

[h,if(targetListSecond==""):
  targetList=targetListFirst ;
  targetList=listAppend(targetListFirst,targetListSecond) ]

[if (listCount(targetList)==1),h:checkedIfOneTarget="checked";checkedIfOneTarget=""]
[if (listCount(targetList)==0),h:msg="<br><br>You do not see any tokens within melee distance.  Make sure the token you would like to target is visible on your map and is within your weapon's reach.  Then try again.";msg=""]

<!-- Setting up list of dialog box width and form action-->
[h:START_NEW_ROW=6]
[if (listCount(targetList)>START_NEW_ROW),h:
   dialogSpecs="width=470; height=620; temporary=0; input=1; noframe=0";
   dialogSpecs="width=470; height=550; temporary=0; input=1; noframe=0"]
[h:formAction=macroLinkText("evalAttack@"+getMacroLocation(),"all","",currentToken())] 

[dialog("meleeAttack", dialogSpecs): {
<html>
<head>
<link rel="stylesheet" type="text/css" href="DialogCSS@Lib:GURPS">
<title>Choose Target and Method of Attack</title>
</head>
<body>
<form name="attack"  action="[r:formAction]">
<input type="hidden" name="weaponUsedIndex" value="[r:weaponUsedIndex]">
<input type="hidden" name="methodUsed" value="[r:methodUsed]">
<h1>[r:upper(json.get(weaponUsed,"name"),1)] [r:json.get(weaponUsed,methodUsed+"descr")] at base skill [r:json.get(weaponUsed,methodUsed+"skill")]</h1>
[r:msg]

<table width="100%" cellspacing="1" cellpadding="2">
<tr>
[foreach(possTarget, targetList,""),code:{
  [token(possTarget),if(getProperty("HP")==getProperty("maxHP")),h: tokenHealth="healthy"; tokenHealth="injured"]
  [token(possTarget),if(getState("healthy")==1),h: tokenHealth="healthy"]
  [token(possTarget),if(getState("injured")==1),h: tokenHealth="injured"]
  [token(possTarget),if(getState("maimed")==1),h: tokenHealth="maimed"]
  [token(possTarget),if(getState("dying")==1),h: tokenHealth="dying"]
<!-- Start a new row of possible targets if you have an even multiple of START_NEW_ROW setting.  Wanted: XmodY.-->
   [if( roll.count/START_NEW_ROW==floor(roll.count/START_NEW_ROW)), r : "</tr><tr>";""]
  <td valign="top" align="center">
  <img src="[token(possTarget),r:getTokenImage(50)]"><br>
  <b>[token(possTarget),r:getName()]</b><br>
   [r:tokenHealth]<br>
  <input type="radio" name="targetID" value="[r:possTarget]" [r:checkedIfOneTarget]></td>
}]
</tr>
</table>

<h1>Select skill modifiers for circumstances and style of attack</h1>

<b>Maneuver Effects: [r:manSkillBonus]</b><input type="hidden" name="maneuver" value="[r:manSkillBonus]">
<br><span style=color:gray>[r:currManeuverName] - [r:json.get(currManeuver,"descr")].</span>
<br>
[h, if(getProperty("shock")==0): textColor="gray";textColor="red"]
<span style=color:[r:textColor]><b>Shock Penalty: [r:shock]</b></span><input type="hidden" name="shock" value="[r:shock]">
<br>
[h, if(posture=="standing"): textColor="gray";textColor="red"]
<span style=color:[r:textColor]><b>Posture: [r:posture]: [r:attackerPostureMod]</b></span><input type="hidden" name="attackerPostureMod" value="[r:attackerPostureMod]">

<br><br>

<table cellspacing="0" cellpadding="0">
  <tr class="oddRow">
  <th valign="middle">Other Modifiers</th>
  <td align="center"><input type="radio" name="miscMod" value="-10"></td>
  <td align="center"><input type="radio" name="miscMod" value="-9"></td>
  <td align="center"><input type="radio" name="miscMod" value="-8"></td>
  <td align="center"><input type="radio" name="miscMod" value="-7"></td>
  <td align="center"><input type="radio" name="miscMod" value="-6"></td>
  <td align="center"><input type="radio" name="miscMod" value="-5"></td> 
  <td align="center"><input type="radio" name="miscMod" value="-4"></td>
  <td align="center"><input type="radio" name="miscMod" value="-3"></td>
  <td align="center"><input type="radio" name="miscMod" value="-2"></td>
  <td align="center"><input type="radio" name="miscMod" value="-1"></td>
  <td align="center"><input type="radio" name="miscMod" value="0" checked></td>
  <td align="center"><input type="radio" name="miscMod" value="1"></td>
  <td align="center"><input type="radio" name="miscMod" value="2"></td>
  <td align="center"><input type="radio" name="miscMod" value="3"></td>
  <td align="center"><input type="radio" name="miscMod" value="4"></td>
  <td align="center"><input type="radio" name="miscMod" value="5"></td>
  <td align="center"><input type="radio" name="miscMod" value="6"></td>
  <td align="center"><input type="radio" name="miscMod" value="7"></td>
  <td align="center"><input type="radio" name="miscMod" value="8"></td>
  <td align="center"><input type="radio" name="miscMod" value="9"></td>
  <td align="center"><input type="radio" name="miscMod" value="10"></td></tr>

  <tr class="oddRow">
  <th valign="middle"> </th>
  <td align="center">-10</td>
  <td align="center"> </td>
  <td align="center">-8</td>
  <td align="center"> </td>
  <td align="center">-6</td>
  <td align="center"> </td> 
  <td align="center">-4</td>
  <td align="center"> </td>
  <td align="center">-2</td>
  <td align="center"> </td>
  <td align="center">0</td>
  <td align="center"> </td>
  <td align="center">2</td>
  <td align="center"> </td>
  <td align="center">4</td>
  <td align="center"> </td>
  <td align="center">6</td>
  <td align="center"> </td>
  <td align="center">8</td>
  <td align="center"> </td>
  <td align="center">10</td></tr> 

  <tr>
  <td colspan="22"> </td></tr>

  <tr>
  <th valign="middle" colspan="3">Other Large Modifiers</th>
  <td align="left" colspan="19"><input type="text"  name="largeMod" value="0" size="2" maxlength="3"></td>
</table>

[macro("bodyPartTable@"+ getMacroLocation()):""]

<p align="center"> <input type="submit" value="attack!">   <input type="reset" value="reset to defaults"></p></form></body></html>
}]
<!-- passes targetID, weaponUsedIndex, methodUsed, maneuver, shock, attackerPostureMod, miscMod, largeMod, targetedLocObj (region, penalty) -->
Basically I want to have some sort of If statement or similar that checks if a token is visible using the canSeeToken() function, if that's at all possible. Because I've played around with the function and it gives a "false" when asking to see a token that is obscured by the VBL. Any help would be appreciated.

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

Re: If Statement that Checks for LoS

Post by aliasmask »

I use this for my LoS targeting: http://forums.rptools.net/viewtopic.php ... 35#p249246

Basically, you want to add Wiki: canSeeToken().

User avatar
elaxter
Kobold
Posts: 8
Joined: Thu Jul 20, 2017 7:27 pm

Re: If Statement that Checks for LoS

Post by elaxter »

aliasmask wrote:I use this for my LoS targeting: http://forums.rptools.net/viewtopic.php ... 35#p249246

Basically, you want to add Wiki: canSeeToken().
I'm a complete scrub. How would I implement this, exactly?

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

Re: If Statement that Checks for LoS

Post by aliasmask »

Without rewriting too much, you could just use my function instead of getTokens().

Code: Select all

...
<!-- Setting up list of possible targets -->
[if( isPC() ), h, code : {
  [h:targetListFirst=getTokens(",",NPCsInRange)]
  [h:targetListSecond=getTokens(",",PCsInRange)]
};{
  [h:targetListFirst=getTokens(",",PCsInRange)]
  [h:targetListSecond=getTokens(",",NPCsInRange)]
}]
...
Replaced with

Code: Select all

<!-- Setting up list of possible targets -->
[if( isPC() ), h, code : {
  [h:targetListFirst=json.toList(getSeenTokens(json.set("{}","npc",1,"range",range)))]
  [h:targetListSecond=json.toList(getSeenTokens(json.set("{}","pc",1,"range",range)))]
};{
  [h:targetListFirst=json.toList(getSeenTokens(json.set("{}","pc",1,"range",range)))]
  [h:targetListSecond=json.toList(getSeenTokens(json.set("{}","npc",1,"range",range)))]
}]
You should set up the function as a UDF in your lib token in the onCampaignLoad macro.

Code: Select all

[H: defineFunction("getSeenTokens","getSeenTokens@"+getMacroLocation(),1,1)]

User avatar
elaxter
Kobold
Posts: 8
Joined: Thu Jul 20, 2017 7:27 pm

Re: If Statement that Checks for LoS

Post by elaxter »

Thanks man! You're a real help! :D

Post Reply

Return to “Macros”