Skip to content

Commit

Permalink
Fix "IsPersistent" and "MarkAsNoLongerNeeded()" using the wrong nativ…
Browse files Browse the repository at this point in the history
…es (#907)
  • Loading branch information
drunderscore authored and crosire committed Jan 26, 2020
1 parent 8720671 commit cac50e5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions source/scripting_v2/GTA/Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,17 @@ public int LodDistance
public bool IsPersistent
{
get => Function.Call<bool>(Hash.IS_ENTITY_A_MISSION_ENTITY, Handle);
set => Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, Handle, value, !value);
set
{
if (value)
{
Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, Handle, true, true);
}
else
{
MarkAsNoLongerNeeded();
}
}
}

public bool FreezePosition
Expand Down Expand Up @@ -579,7 +589,6 @@ public void ApplyForceRelative(Vector3 direction, Vector3 rotation, ForceType fo
public void MarkAsNoLongerNeeded()
{
int handle = Handle;
Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, handle, false, true);
unsafe
{
Function.Call(Hash.SET_ENTITY_AS_NO_LONGER_NEEDED, &handle);
Expand Down
13 changes: 11 additions & 2 deletions source/scripting_v3/GTA/Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,17 @@ public int LodDistance
public bool IsPersistent
{
get => Function.Call<bool>(Hash.IS_ENTITY_A_MISSION_ENTITY, Handle);
set => Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, Handle, value, !value);
set
{
if (value)
{
Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, Handle, true, true);
}
else
{
MarkAsNoLongerNeeded();
}
}
}

/// <summary>
Expand Down Expand Up @@ -1197,7 +1207,6 @@ public void ApplyForceRelative(Vector3 direction, Vector3 rotation = default, Fo
public void MarkAsNoLongerNeeded()
{
int handle = Handle;
Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, handle, false, true);
unsafe
{
Function.Call(Hash.SET_ENTITY_AS_NO_LONGER_NEEDED, &handle);
Expand Down

0 comments on commit cac50e5

Please sign in to comment.