diff --git a/code/components/citizen-server-impl/src/state/ServerGameState_Scripting.cpp b/code/components/citizen-server-impl/src/state/ServerGameState_Scripting.cpp index bb64bc2953..11f9302d14 100644 --- a/code/components/citizen-server-impl/src/state/ServerGameState_Scripting.cpp +++ b/code/components/citizen-server-impl/src/state/ServerGameState_Scripting.cpp @@ -1931,6 +1931,48 @@ static void Init() return train ? train->direction : false; })); + fx::ScriptEngine::RegisterNativeHandler("GET_TRAIN_CONFIG_INDEX", makeEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity) + { + auto train = entity->syncTree->GetTrainState(); + + return train ? train->trainConfigIndex : -1; + })); + + fx::ScriptEngine::RegisterNativeHandler("GET_TRAIN_DISTANCE_FROM_ENGINE", makeEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity) + { + auto train = entity->syncTree->GetTrainState(); + + return train ? train->distanceFromEngine : 0.0f; + })); + + fx::ScriptEngine::RegisterNativeHandler("IS_MISSION_TRAIN", makeEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity) + { + auto train = entity->syncTree->GetTrainState(); + + return train ? train->isMissionTrain : false; + })); + + fx::ScriptEngine::RegisterNativeHandler("DOES_TRAIN_HAVE_PASSENGER_CARRIAGES", makeEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity) + { + auto train = entity->syncTree->GetTrainState(); + + return train ? train->hasPassengerCarriages : false; + })); + + fx::ScriptEngine::RegisterNativeHandler("IS_TRAIN_RENDERED_DERAILED", makeEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity) + { + auto train = entity->syncTree->GetTrainState(); + + return train ? train->renderDerailed : false; + })); + + fx::ScriptEngine::RegisterNativeHandler("DOES_TRAIN_FORCE_DOORS_OPEN", makeEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity) + { + auto train = entity->syncTree->GetTrainState(); + + return train ? train->forceDoorsOpen : false; + })); + fx::ScriptEngine::RegisterNativeHandler("GET_PLAYER_FAKE_WANTED_LEVEL", MakePlayerEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity) { auto pn = entity->syncTree->GetPlayerWantedAndLOS(); diff --git a/ext/native-decls/DoesTrainForceDoorsOpen.md b/ext/native-decls/DoesTrainForceDoorsOpen.md new file mode 100644 index 0000000000..946f8fcc4d --- /dev/null +++ b/ext/native-decls/DoesTrainForceDoorsOpen.md @@ -0,0 +1,20 @@ +--- +ns: CFX +apiset: server +game: gta5 +--- +## DOES_TRAIN_FORCE_DOORS_OPEN + +```c +bool DOES_TRAIN_FORCE_DOORS_OPEN(Vehicle train); +``` + +Returns whether this train forces its doors open while a player is inside it. + +This reads the flag as it is synchronised for the given train. The client-side `SET_TRAINS_FORCE_DOORS_OPEN` sets this for all trains at once. + +## Parameters +* **train**: The train handle + +## Return value +Returns true if the train forces its doors open. diff --git a/ext/native-decls/DoesTrainHavePassengerCarriages.md b/ext/native-decls/DoesTrainHavePassengerCarriages.md new file mode 100644 index 0000000000..83440cc6c4 --- /dev/null +++ b/ext/native-decls/DoesTrainHavePassengerCarriages.md @@ -0,0 +1,18 @@ +--- +ns: CFX +apiset: server +game: gta5 +--- +## DOES_TRAIN_HAVE_PASSENGER_CARRIAGES + +```c +bool DOES_TRAIN_HAVE_PASSENGER_CARRIAGES(Vehicle train); +``` + +Returns whether the train has carriages that peds can ride in. + +## Parameters +* **train**: The train handle + +## Return value +Returns true if the train has passenger carriages. diff --git a/ext/native-decls/GetTrainConfigIndex.md b/ext/native-decls/GetTrainConfigIndex.md new file mode 100644 index 0000000000..14d2951782 --- /dev/null +++ b/ext/native-decls/GetTrainConfigIndex.md @@ -0,0 +1,18 @@ +--- +ns: CFX +apiset: server +game: gta5 +--- +## GET_TRAIN_CONFIG_INDEX + +```c +int GET_TRAIN_CONFIG_INDEX(Vehicle train); +``` + +Gets the index of the train configuration this train was created from, as defined in `traintracks.xml`. + +## Parameters +* **train**: The train handle + +## Return value +The train's config index, or -1 if the entity is not a train. diff --git a/ext/native-decls/GetTrainDistanceFromEngine.md b/ext/native-decls/GetTrainDistanceFromEngine.md new file mode 100644 index 0000000000..d556d55170 --- /dev/null +++ b/ext/native-decls/GetTrainDistanceFromEngine.md @@ -0,0 +1,18 @@ +--- +ns: CFX +apiset: server +game: gta5 +--- +## GET_TRAIN_DISTANCE_FROM_ENGINE + +```c +float GET_TRAIN_DISTANCE_FROM_ENGINE(Vehicle train); +``` + +Gets how far along the chain this carriage sits, measured from the engine carriage. Returns 0.0 for the engine itself. + +## Parameters +* **train**: The train handle + +## Return value +The distance from the engine carriage, or 0.0 if the entity is not a train. diff --git a/ext/native-decls/IsMissionTrain.md b/ext/native-decls/IsMissionTrain.md new file mode 100644 index 0000000000..ef31a1ada6 --- /dev/null +++ b/ext/native-decls/IsMissionTrain.md @@ -0,0 +1,18 @@ +--- +ns: CFX +apiset: server +game: gta5 +--- +## IS_MISSION_TRAIN + +```c +bool IS_MISSION_TRAIN(Vehicle train); +``` + +Returns whether the train was created by a script rather than by the ambient train population. + +## Parameters +* **train**: The train handle + +## Return value +Returns true if the train is a mission train. diff --git a/ext/native-decls/IsTrainRenderedDerailed.md b/ext/native-decls/IsTrainRenderedDerailed.md new file mode 100644 index 0000000000..f80f8eef6d --- /dev/null +++ b/ext/native-decls/IsTrainRenderedDerailed.md @@ -0,0 +1,18 @@ +--- +ns: CFX +apiset: server +game: gta5 +--- +## IS_TRAIN_RENDERED_DERAILED + +```c +bool IS_TRAIN_RENDERED_DERAILED(Vehicle train); +``` + +Returns whether the train is being rendered as derailed, as set by `SET_RENDER_TRAIN_AS_DERAILED`. + +## Parameters +* **train**: The train handle + +## Return value +Returns true if the train is rendered derailed.