Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Range calculated to targeted token?

1425784705
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Has anyone been able to add an automatically calulated range that can be used to apply modifiers to attack rolls?
Should be relatively simple, just figure out the range between x,y to x2,y2. <a href="https://www.mathsisfun.com/algebra/distance-2-points.html" rel="nofollow">https://www.mathsisfun.com/algebra/distance-2-points.html</a> :) Go nuts
1425827069

Edited 1425836451
This script should do what you need (the distance value can be found in the variable dist) : I've got no time to show a cleaner code, but it should do the job. call it with this macro : !range @{selected|token_id} @{target|token_id} Script : var RangeScript = RangeScript || {}; var OriginName; var DestName; var origintoken; var desttoken; on("chat:message", function (msg) { // Exit if not an api command if (msg.type != "api") return; // Get the API Chat Command msg.who = msg.who.replace(" (GM)", ""); msg.content = msg.content.replace("(GM) ", ""); var command = msg.content.split(" ", 1); if(command == "!range") { RangeScript.Process(msg); } }); RangeScript.Process = function(msg){ var Tag = msg.content.split(" "); OriginName = Tag[1]; DestName = Tag[2]; Range(OriginName,DestName,msg); }; function Range(OriginName, DestName, msg) { origintoken = findObjs({_type: "graphic", id: OriginName})[0]; //We know there is a token in the Campaign called "Guard A". desttoken = findObjs({_type: "graphic", id: DestName})[0]; //We know there is a token in the Campaign called "Guard A". var originleft=origintoken.get("left"); //left var origintop = origintoken.get("top"); //top var destleft=desttoken.get("left"); //left var desttop = desttoken.get("top"); //top var left = originleft - destleft; var top = origintop - desttop ; var dist = Math.sqrt((left*left)+(top*top)); dist = Math.floor(dist/70); }; Hope this helps:
1425836608
The Aaron
Pro
API Scripter
Scott S. said: Has anyone been able to add an automatically calulated range that can be used to apply modifiers to attack rolls? What do you mean by " can be used to apply modifiers to attack rolls? "
1425843576
Ziechael
Forum Champion
Sheet Author
API Scripter
I'm assuming like the range increment for 3.5 which incurs a -2 for every x amount of distance past it's 'maximum' effective range... therefore the OP seems to be asking for something that would calculate the distance and provide an output of the potential bonus/penalty? Thats what i took from it anyhoo?
Ziechael said: I'm assuming like the range increment for 3.5 which incurs a -2 for every x amount of distance past it's 'maximum' effective range... therefore the OP seems to be asking for something that would calculate the distance and provide an output of the potential bonus/penalty? It would be also be awesome to use to determine a target number, as well. For example, if Nancy was shooting at Bob, and Bob was 50 meters away (short range), when the dice were rolled it would compare the dice result to the short range difficultly, Later, when Nancy continued her murderous spree, she shot at Bob's sister who was 200 meters away (long range). Again, dice hit the mat and are compared to the script given distance to determine the difficulty. This would be awesome if it can be worked into targeted rolls.
1425854589
The Aaron
Pro
API Scripter
I read this as more of an automation question, as in "as part of the attack macro, choose a target and specify the range limits and the script applies the right adjustment based on the actual range."
1425936294
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Well for example a pistol in Cyberpunk 2020 has a full range of 50m the range bands are thus point blank (0-1m) to hit number is 10 Close (1/4 full range (12.5m)) to hit number is 15 Medium (1/2 full range (55m)) to hit number is 20 Long range (full range (50m)) to hit number is 25 Extreme (2 x full range (100 m)) to hit number is 30
1425936480
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
John W and I are working on automating the attack sequence for my CP2020 game.