I created a script which generates some events when certain vehicles get damaged.
It consists of a timer that call a "check" on present vehicles, then the script ignores all wrecks and vehicles which did not spawn yet (vehicle.getDamage() function). Everything works fine, nevertheless after one vehicle gets destroyed an exception is raised and the script stops working properly.
I would be grateful to anybody that can put me in the right direction.
This is my last code (only for testing):
Code: Select all
VEHICLES_TEMPLATES = {
"SERP_HMMWV_1":["SERP_HMMWV_1"],
"SERP_HMMWV_2":["SERP_HMMWV_2"],
"SERP_HMMWV_3":["SERP_HMMWV_3"],
"SERP_VODNIK_1":["SERP_VODNIK_1"],
"SERP_VODNIK_2":["SERP_VODNIK_2"],
"SERP_VODNIK_3":["SERP_VODNIK_3"]
}
WRECK_HITPOINTS = 0
ALERT_HITPOINTS = 1600
import host
import bf2
def init():
# events hook
host.registerGameStatusHandler(onGameStatusChanged)
def onGameStatusChanged(status):
global CHECK_TIMER
if status == bf2.GameStatus.Playing:
try: CHECK_TIMER.destroy()
except: pass
CHECK_TIMER = None
CHECK_TIMER = bf2.Timer(CHECK_CB_VEHICLES, 2.0, 1)
CHECK_TIMER.setRecurring(8.0)
else:
if status == bf2.GameStatus.EndGame:
if CHECK_TIMER:
try: CHECK_TIMER.destroy()
except: pass
CHECK_TIMER = None
# DISPLAY TEXT MESSAGES TO ALL PLAYERS
def sendMsg(msg):
host.rcon_invoke("game.sayAll "" + str(msg) + """)
# FIND VEHICLES INCLUDED IN "VEHICLES_TEMPLATES" LIST
def CHECK_CB_VEHICLES(data):
for template in VEHICLES_TEMPLATES:
vehicles_list = list(bf2.objectManager.getObjectsOfTemplate(template))
for vehicle in vehicles_list:
vehicle_name = str(vehicle.templateName)
vehicle_position = vehicle.getPosition()
if vehicle.getIsWreck():
continue
if vehicle_position == (0.0, 0.0, 0.0):
continue
elif vehicle_position != (0.0, 0.0, 0.0):
try:
vehicle_hp = int(vehicle.getDamage())
sendMsg(" "+str(vehicle_name)+" HITPOINTS: "+str(vehicle_hp))
# HERE I'M SUPPOSED TO INCLUDE OTHER PYTHON COMMANDS/EVENTS
except:
sendMsg(" FAILED TO GET "+str(vehicle_name)+" HITPOINTS!!!!!!")
pass