help request - Python script & getDamage() function

Making or wanting help making your own asset? Check in here
Post Reply
serpiko
Posts: 4
Joined: 2023-08-19 22:08

help request - Python script & getDamage() function

Post by serpiko »

Hi Community,
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
serpiko
Posts: 4
Joined: 2023-08-19 22:08

Re: help request - Python script & getDamage() function

Post by serpiko »

Hi,
is there anybody willing to help?
Considering the impressive changes Project Reality brought to the game by python scripts, I trusted that a few devs could give me at least some indications.
My script actually works for all vehicles which are already on the map when game starts (the "getDamage()" function proves to work) but, after vehicles first destruction, something must prevent "getDamage()" to retrieve vehicles hitpoints.
Isn't there a work around for it?
User avatar
M.MCC
Iranian Forces Faction Lead
Posts: 74
Joined: 2022-02-01 06:47
Location: Cheng Du

Re: help request - Python script & getDamage() function

Post by M.MCC »

Hey this sounds like a good thing. The forum is not active I think you can get help through Discord. cheers?https://discord.gg/project-reality-190090455973756928
Post Reply

Return to “PR:BF2 Community Modding”