I made several tests and GetLifetime() always return 0 when a Vehicle spawned in by CE (Events.xml) making them stay forever with a unlimited lifetime.
GetEconomyProfile().GetLifetime()
returns the correct lifetime which is set in types.xml
GetLifetime()
returns 0 (only when spawned by events.xml) and that's the issue.
When spawning in via Admin Tools, both return the correct and set lifetime of the types.xml.
Methods i used including prints:
For CE spawned Vehicles:
override void EEOnCECreate() { super.EEOnCECreate(); if ( GetGame().IsServer() ) { Print( "Vehicle " + this + " pos= " + this.GetPosition() + " CE Lifetime default: " + GetEconomyProfile().GetLifetime() ); Print( "Vehicle " + this + " pos= " + this.GetPosition() + " CE Lifetime remaining: " + GetLifetime() ); this.SetLifetime( GetEconomyProfile().GetLifetime() ); Print( "Vehicle " + this + " pos= " + this.GetPosition() + " CE Lifetime default: " + GetEconomyProfile().GetLifetime() ); Print( "Vehicle " + this + " pos= " + this.GetPosition() + " CE Lifetime remaining: " + GetLifetime() ); } }
And here the Print:
SCRIPT : Vehicle Truck_01_Covered<204971b0> pos= <4131.822266, 182.380753, 13122.184570> CE Lifetime default: 1.2096e+06 SCRIPT : Vehicle Truck_01_Covered<204971b0> pos= <4131.822266, 182.380753, 13122.184570> CE Lifetime remaining: 0 SCRIPT : Vehicle Truck_01_Covered<204971b0> pos= <4131.822266, 182.380753, 13122.184570> CE Lifetime default: 1.2096e+06 SCRIPT : Vehicle Truck_01_Covered<204971b0> pos= <4131.822266, 182.380753, 13122.184570> CE Lifetime remaining: 1.2096e+06 SCRIPT : Vehicle Sedan_02_Grey<204a11f0> pos= <14139.214844, 2.756193, 13050.478516> CE Lifetime default: 1.2096e+06 SCRIPT : Vehicle Sedan_02_Grey<204a11f0> pos= <14139.214844, 2.756193, 13050.478516> CE Lifetime remaining: 0 SCRIPT : Vehicle Sedan_02_Grey<204a11f0> pos= <14139.214844, 2.756193, 13050.478516> CE Lifetime default: 1.2096e+06 SCRIPT : Vehicle Sedan_02_Grey<204a11f0> pos= <14139.214844, 2.756193, 13050.478516> CE Lifetime remaining: 1.2096e+06 SCRIPT : Vehicle OffroadHatchback<2046f0b0> pos= <11683.120117, 75.346802, 6677.020508> CE Lifetime default: 1.2096e+06 SCRIPT : Vehicle OffroadHatchback<2046f0b0> pos= <11683.120117, 75.346802, 6677.020508> CE Lifetime remaining: 0 SCRIPT : Vehicle OffroadHatchback<2046f0b0> pos= <11683.120117, 75.346802, 6677.020508> CE Lifetime default: 1.2096e+06 SCRIPT : Vehicle OffroadHatchback<2046f0b0> pos= <11683.120117, 75.346802, 6677.020508> CE Lifetime remaining: 1.2096e+06 SCRIPT : Vehicle Old_Bike<1ed15ff0> pos= <10279.299805, 6.318300, 2184.189941> CE Lifetime default: 1800 SCRIPT : Vehicle Old_Bike<1ed15ff0> pos= <10279.299805, 6.318300, 2184.189941> CE Lifetime remaining: 0 SCRIPT : Vehicle Old_Bike<1ed15ff0> pos= <10279.299805, 6.318300, 2184.189941> CE Lifetime default: 1800 SCRIPT : Vehicle Old_Bike<1ed15ff0> pos= <10279.299805, 6.318300, 2184.189941> CE Lifetime remaining: 1800
For Admin Tool spawned Vehicle:
override void EEInit() { super.EEInit(); if ( GetGame().IsServer() ) { Print( "Vehicle " + this + " pos= " + this.GetPosition() + " CE Lifetime default: " + GetEconomyProfile().GetLifetime() ); Print( "Vehicle " + this + " pos= " + this.GetPosition() + " CE Lifetime remaining: " + GetLifetime() ); } }
And here the Print:
SCRIPT : Vehicle Truck_01_Covered<274701e0> pos= <13215.186523, 2.053945, 7390.652832> CE Lifetime default: 1.2096e+06 SCRIPT : Vehicle Truck_01_Covered<274701e0> pos= <13215.186523, 2.053945, 7390.652832> CE Lifetime remaining: 2.06057e+06