Community Forum

Reset and delete vehicle

Forum Overview >> Scripting

Created04.12.2021 16:08

Bob Bobster (Bobster82) 04.12.2021 16:08

When I 'Sell' a vehicle, the event 'onDelete' is triggered. But when u 'Reset' a vehicle, the same 'onDelete' is triggered. (after that the onLoad)

I have a copy of the vehicle list. I need to drop the vehicle that is sold, but I cant do that in 'onDelete' , as the vehicles that are reset also use that event.
I can work around it with checking my list against the game list every update.... But it would be nice if that wasnt needed ;) (perfomance wise)

What event or function or value can I use to indentify a vehicle that is sold.

I hope I made myself clear, thanks in advance

Espen K. (estyx) 05.12.2021 18:35
Event for selling vehicle: SellVehicleEvent

Bob Bobster (Bobster82) 05.12.2021 20:46
Hello Espen K.,

Thanks for replying, but I cant find that event... Can u give me some pointers?

Espen K. (estyx) 06.12.2021 01:19
I haven't tested it out but you can try something like

local function observeRunFunction(self, func)
-- if event is run on server side self.vehicle will be nil
print_r(self.vehicle, 1)
end = Utils.appendedFunction(, observeRunFunction)

You also have other options as well if you can't get this to work (these probably on work on single player)

function sellVehicleYesNoFunction(self, func, yes)
if yes then

WorkshopScreen.sellVehicleYesNo = Utils.prependedFunction(WorkshopScreen.sellVehicleYesNo, sellVehicleYesNoFunction)

You can probably also subscribe to SellVehicleEvent something like this

g_messageCenter:subscribe(SellVehicleEvent, callback, callbackTarget)

Bob Bobster (Bobster82) 06.12.2021 16:44
Thanks Espen!

This is exactly what I needed. I had my work around, but this is much cleaner (I was checking if the vehicle table exists every update loop)


Note: Log in to post. Create a new account here.