Skip to content

Commit e0ab52a

Browse files
authored
Merge pull request #5 from neos7/development
Updated readme
2 parents eeefb3e + 9cbc109 commit e0ab52a

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

README.md

+41
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,47 @@ The value in milliseconds used by each client to check if its preset requires to
6363
`debug=false`
6464
Enables the debug mode, which prints some logs in the console
6565

66+
`exposeCommand=false`
67+
Enables the /vstancer command to toggle the menu
68+
69+
`exposeEvent=false`
70+
Enable the "vstancer:toggleMenu" event to toggle the menu
71+
72+
### Exports
73+
74+
Remember that exports require the resource to be called “vstancer”
75+
76+
```csharp
77+
private void SetVstancerPreset(int vehicle, float off_f, float rot_f, float off_r, float rot_r, object defaultFrontOffset = null, object defaultFrontRotation = null, object defaultRearOffset = null, object defaultRearRotation = null);
78+
private float[] GetVstancerPreset(int vehicle);
79+
```
80+
81+
**SET**
82+
83+
Note that when using the `SetVstancerPreset`, the default values are optional and the script will get them itself if you don't pass them.
84+
This is an example of how to set a vstancer preset on a vehicle:
85+
C#:
86+
```csharp
87+
Exports["vstancer"].SetVstancerPreset(vehicle,offset_f,rotation_f,offset_r,rotation_r);
88+
```
89+
Lua:
90+
```lua
91+
exports.vstancer:SetVstancerPreset(vehicle,offset_f,rotation_f,offset_r,rotation_r)
92+
```
93+
94+
**GET**
95+
96+
When using the `GetVstancerPreset` the returned array will contain the following floats in order: off_f, rot_f, off_r, rot_r, off_f_def, rot_f_def, off_r_def, rot_r_def.
97+
This is an example of how to get a vstancer preset (in case you want to store them):
98+
C#:
99+
```csharp
100+
float[] preset = Exports["vstancer"].GetVstancerPreset(vehicle);
101+
```
102+
Lua:
103+
```lua
104+
local preset = exports.vstancer:GetVstancerPreset(vehicle);
105+
```
106+
66107
[Source](https://github.com/neos7/fivem-vstancer)
67108
[Download](https://github.com/neos7/fivem-vstancer/releases)
68109
I am open to any kind of feedback. Report suggestions and bugs you find.

Vstancer.Client/Vstancer.cs

+4-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class Vstancer : BaseScript
1717
private static readonly string ScriptName = "VStancer";
1818

1919
#region CONFIG_FIEDS
20+
private static float fDecorPrecision = 0.001f;
2021
private static float editingFactor = 0.01f;
2122
private static float maxSyncDistance = 150.0f;
2223
private static float frontMaxOffset = 0.25f;
@@ -427,11 +428,7 @@ private void RemoveDecorators(int vehicle)
427428
/// <returns></returns>
428429
private float[] GetVstancerPreset(int vehicle)
429430
{
430-
VstancerPreset preset = null;
431-
if (vehicle == currentVehicle && currentPreset != null)
432-
preset = currentPreset;
433-
else preset = CreatePreset(vehicle);
434-
431+
VstancerPreset preset = (vehicle == currentVehicle && currentPreset != null) ? currentPreset : CreatePreset(vehicle);
435432
int frontCount = preset.FrontWheelsCount;
436433

437434
return new float[] {
@@ -524,7 +521,7 @@ private void UpdateFloatDecorator(int vehicle, string name, float currentValue,
524521
if (DecorExistOn(vehicle, name))
525522
{
526523
float decorValue = DecorGetFloat(vehicle, name);
527-
if (Math.Abs(currentValue - decorValue) > 0.001f)
524+
if (Math.Abs(currentValue - decorValue) > fDecorPrecision)
528525
{
529526
DecorSetFloat(vehicle, name, currentValue);
530527
if (debug)
@@ -533,7 +530,7 @@ private void UpdateFloatDecorator(int vehicle, string name, float currentValue,
533530
}
534531
else // Decorator doesn't exist, create it if required
535532
{
536-
if (Math.Abs(currentValue - defaultValue) > 0.001f)
533+
if (Math.Abs(currentValue - defaultValue) > fDecorPrecision)
537534
{
538535
DecorSetFloat(vehicle, name, currentValue);
539536
if (debug)

Vstancer.Client/VstancerPreset.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace Vstancer.Client
55
{
66
public class VstancerPreset : IEquatable<VstancerPreset>
77
{
8+
public static float Precision { get; private set; } = 0.001f;
89
public int WheelsCount { get; private set; }
910
public int FrontWheelsCount { get; private set; }
1011

@@ -150,10 +151,10 @@ public bool Equals(VstancerPreset other)
150151

151152
for (int index = 0; index < WheelsCount; index++)
152153
{
153-
if (Math.Abs(DefaultOffsetX[index] - other.DefaultOffsetX[index]) > 0.001f
154-
|| Math.Abs(DefaultRotationY[index] - other.DefaultRotationY[index]) > 0.001f
155-
|| Math.Abs(OffsetX[index] - other.OffsetX[index]) > 0.001f
156-
|| Math.Abs(RotationY[index] - other.RotationY[index]) > 0.001f)
154+
if (Math.Abs(DefaultOffsetX[index] - other.DefaultOffsetX[index]) > Precision
155+
|| Math.Abs(DefaultRotationY[index] - other.DefaultRotationY[index]) > Precision
156+
|| Math.Abs(OffsetX[index] - other.OffsetX[index]) > Precision
157+
|| Math.Abs(RotationY[index] - other.RotationY[index]) > Precision)
157158
return false;
158159
}
159160
return true;

dist/config.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ timer=1000
88
debug=false
99

1010
#Enables the /vstancer command
11-
exposeCommand=true
11+
exposeCommand=false
1212

1313
#Enable the "vstancer:toggleMenu" event
1414
exposeEvent=false

0 commit comments

Comments
 (0)