import bge
def main():
cont = bge.logic.getCurrentController()
own = cont.owner
sensDamage = cont.sensors['CollisionDamage']
actuHit = cont.actuators['Hit']
if sensDamage.positive:
actuHit.value = sensDamage.hitObject['Damager']
cont.activate(actuHit)
else:
cont.deactivate(actuHit)
main()
this is used to calculate the damage done to a character in the game.
The problem is it only counts 1 object that is hit.
How do I get the property “Damager” from the list of objects, the sum them
Also, because the property actuator uses strings the properties are strings too
I tried this but it doesn’t work:
import bge
def main():
cont = bge.logic.getCurrentController()
own = cont.owner
sensDamage = cont.sensors['CollisionDamage']
if sensDamage.positive:
total = 0
n = 0
for sensDamageList[n] != []:
total = total + sensDamage.hitObjectList[n]['Damager']
n = n + 1
own["Health"] = own["Health"] + total
main()
Any help would be great!