Community Forum

Player onEnter

Forum Overview >> Scripting

Created03.01.2021 02:37

Leigh Mike (LesiuApple) 03.01.2021 02:37
Hello. How I can trigger player state enter vehicle by done some function. Viz something like

self.isDone = true end;
if self.isDone then
(and here to get player state in vehicle)

I need it cause fillUnit etc. shows when player in the vehicle and I can't use normaly enterable cause it has to be called when some operations is done and player has to be on foot. Actually, I just need to show the data as in the situation when the player is in the vehicle.

Bilbo Beutlin (BBeutlin) 03.01.2021 21:12
There are some mods around which display vehicles statistics, also on ModHub. Use these as examples.

There is no simple solution. At first you have to scan vehicles around for the nearest. Then you cannot simply define a vehicle as 'entered' without causing problems.
Best is you setup a custom display without manipulating any vehicle status.

Leigh Mike (LesiuApple) 03.01.2021 21:48
I get it, it remains for me to make a new display. Thanks

Leigh Mike (LesiuApple) 08.01.2021 15:29
Hi, I created a new simple display, and a new question arose. Namely, after adding it to the specialization, e.g. trailer, everything works fine when it is attached, but how can I get it drawn when my specialization of the device can't be attached or entered by player. Can I somehow call functions from my specialization in canDraw so that the display is drawn when the player performs a given action? Greetings

Bilbo Beutlin (BBeutlin) 08.01.2021 16:09
You could add (register) an event listener like
SpecializationUtil.registerEventListener(vehicleType, "onEventXYZ", mySpec);

See default specs how to setup the stuff.

Leigh Mike (LesiuApple) 08.01.2021 16:36
I am not sure if I understand correctly, and I do not see anything similar in the documentation. Is it something like that?

myMod = {}

myMod.MOD_NAME = g_currentModName
myMod.MOD_DIR = g_currentModDirectory

local myMod_mt = Class(myMod, VehicleHUDExtension)
VehicleHUDExtension.registerHUDExtension(mySpec, myMod)

function, uiScale, uiTextColor, uiTextSize)
local self =, vehicle, uiScale, uiTextColor, uiTextSize)
self.mySpec = vehicle.spec_mySpec


return self

function myMod:canDraw()
local vehicle = self.vehicle
local spec = vehicle.spec_mySpec

SpecializationUtil.registerEventListener(vehicleType, "onEventXYZ", mySpec)

-- code from upper function --
if ... then
return true
-- end of code from upper function --


Bilbo Beutlin (BBeutlin) 08.01.2021 17:04
No - it is something like here:

For a specializations this gets initialized and refreshed automatically.
In general scripts you must do that manually.

Leigh Mike (LesiuApple) 08.01.2021 17:22
I know how add it to the specialization, and is it work same to the custom extension?

Bilbo Beutlin (BBeutlin) 08.01.2021 17:37
Of course "SpecializationUtil.registerEventListener()" works in specializations only.
So you can either write your code as spec or you must use the global event table (just can't remember the name).

An easier solution is perhaps to use prepended/appendedFunction to a suitable vehicle function. This may execute standalone code or give message to a control program.

Leigh Mike (LesiuApple) 08.01.2021 21:46
Does VehicleHUDExtension sometimes not only work for vehicles that can be entered or attached? Because even when I copied the whole function and paste it to machine specialization which could be attached and I set it to draw when e.g. spec.isShouldDraw = true (I just gave if spec.isShouldDraw ... end;) Everything worked perfectly, but when I gave it to my specialization which cannot be attached or entered, nothing is displayed ...: /

Bilbo Beutlin (BBeutlin) 09.01.2021 09:23
I don't know about "VehicleHUDExtension" - so I can't say anything about the code. Ask the author.

Leigh Mike (LesiuApple) 09.01.2021 20:15
This will be a problem I guess because author is probably someone from Giants Software. Do you know someone who was doing something with it?

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