Page MenuHomeFeedback Tracker

Feature Request: Get CEItemProfile without having to spawn the item
New, UrgentPublic

Description

The problem with the CEItemProfile class is, that you can only get it when you spawn the item.
An issue I have been running into quite often is, when I want to print all items refreshed via the TerritoryFlag, I have to check their lifetime and spawn all possible items to get the CEItemProfile via the GetEconomyProfile() method, which is quite a big overhead and can also cause issues with modded items doing stuff automatically when spawned. It would be really useful to get these two functions added to the CEApi class:

class CEApi
{
	proto native TStringArray GetAllItemsInTypes(); // Would save the time searching through the config.cpp CfgVehicles class by just returning all items being added to the types.xml
	proto native CEItemProfile GetItemProfile(string itemname); // Returns the same Item Profile as you would get when spawning the item and calling the GetEconomyProfile() method
	// Rest of the functions
}

Also there are a few other things this will be useful for example some Admin tools support reading the types.xml and changing it, but these methods mostly rely on parsing the XML manually.

This is the code I currently use to get the Lifetime of an Object:

int GetItemLifetime(string itemname) {
	Object obj = GetGame().CreateObjectEx(itemname, vector.Zero, ECE_LOCAL);
	if (!obj)
		return 0;
	EntityAI ent = EntityAI.Cast(obj);
	if (!ent) {
		GetGame().ObjectDelete(obj);
		return 0;
	}
	CEItemProfile profile = ent.GetEconomyProfile();
	if (!profile) {
		GetGame().ObjectDelete(obj);
		return -1;
	}
	int lifetime = profile.GetLifetime();
	GetGame().ObjectDelete(obj);
	return lifetime;
}

Details

Severity
Feature
Resolution
Open
Reproducibility
Always
Operating System
Windows 7
Category
General

Event Timeline

LBmaster created this task.Nov 14 2023, 2:31 PM