Hi, I was playing around with burning ices, and I want a better way to capture control points.
You can command scouts.
What I want to do:
Make the scout defend the nearest point that hasn’t been captured.
Actual Outcome:
The scout finds the nearest unoccupied point, but unfortunately, when the scout captures the point, the captured point joins my team, and then the scout runs off, and now the point uncaptured, so he just runs back and forth.
Here is my code.
I am at wits end for what to do.
def commandScout():
es = hero.findByType("goliath", hero.findEnemies())
friends = hero.findFriends()
e = hero.findNearest(es)
points = hero.getControlPoints()
targets = []
if e:
for point in points:
if point.team <> e.team and point.team <> hero.team:
targets.append(point)
for friend in friends:
if friend.type == 'scout':
target = friend.findNearest(targets)
if target:
hero.command(friend, "defend", target.pos)
Tried using a while loop to make the scout defend, but it’s an infinite loop.
def commandScout():
es = hero.findByType("goliath", hero.findEnemies())
friends = hero.findFriends()
e = hero.findNearest(es)
points = hero.getControlPoints()
targets = []
if e:
for point in points:
if point.team <> e.team and point.team <> hero.team:
targets.append(point)
for friend in friends:
if friend.type == 'scout':
target = friend.findNearest(targets)
while friend.health > 0 and target:
hero.command(friend, "defend", target.pos)
I also tried checking the amount of people next to a point, but I get an error.
def commandScout():
es = hero.findByType("goliath", hero.findEnemies())
friends = hero.findFriends()
e = hero.findNearest(es)
points = hero.getControlPoints()
defenders = []
targets = []
if e:
for point in points:
if point.team <> e.team:
targets.append(point)
for target in targets:
for friend in friends:
if friend.distanceTo(target) < 11:
defenders.append(friend)
for friend in friends:
if friend.type == 'scout':
target = friend.findNearest(targets)
if target and len(defenders) <= 1:
hero.command(friend, "defend", target.pos)
Line 132:
ArgumentError:
Find the distance to a target unit.
Also tried hardcoding it.
def commandSoldier():
es = hero.findByType("goliath", hero.findEnemies())
friends = hero.findFriends()
e = hero.findNearest(es)
points = hero.getControlPoints()
targets = []
if e:
for point in points:
if point.team <> hero.team:
targets.append(point)
for friend in friends:
if friend.type == 'scout' or friend.type == 'a-soldier':
target = friend.findNearest(targets)
if target:
if target.team == 'humans':
hero.command(friend, "defend", target.pos)
elif target:
hero.command(friend, "defend", target.pos)
Please help me!!!