Skip to content

Instantly share code, notes, and snippets.

@alexguirre
Last active July 14, 2017 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexguirre/c4634a3c38903fb7a57200f8e268f047 to your computer and use it in GitHub Desktop.
Save alexguirre/c4634a3c38903fb7a57200f8e268f047 to your computer and use it in GitHub Desktop.
// System
using System.Drawing;
// RPH
using Rage;
using Rage.Native;
internal class LoopedParticle : IHandleable
{
public string AssetName { get; }
public string ParticleName { get; }
public PoolHandle Handle { get; }
public LoopedParticle(string assetName, string particleName, Ped ped, PedBoneId bone, Vector3 offset, Rotator rotation, float scale)
{
AssetName = assetName;
ParticleName = particleName;
LoadAsset();
Handle = NativeFunction.Natives.StartParticleFxLoopedOnPedBone<uint>(particleName,
ped,
offset.X, offset.Y, offset.Z,
rotation.Pitch, rotation.Roll, rotation.Yaw,
ped.GetBoneIndex(bone),
scale,
false, false , false);
}
public LoopedParticle(string assetName, string particleName, Entity entity, Vector3 offset, Rotator rotation, float scale)
{
AssetName = assetName;
ParticleName = particleName;
LoadAsset();
Handle = NativeFunction.Natives.StartParticleFxLoopedOnEntity<uint>(particleName,
entity,
offset.X, offset.Y, offset.Z,
rotation.Pitch, rotation.Roll, rotation.Yaw,
scale,
false, false, false);
}
public LoopedParticle(string assetName, string particleName, Entity entity, int boneIndex, Vector3 offset, Rotator rotation, float scale)
{
AssetName = assetName;
ParticleName = particleName;
LoadAsset();
Handle = NativeFunction.Natives.xC6EB449E33977F0B<uint>(particleName,
entity,
offset.X, offset.Y, offset.Z,
rotation.Pitch, rotation.Roll, rotation.Yaw,
boneIndex,
scale,
false, false, false); // _START_PARTICLE_FX_LOOPED_ON_ENTITY_BONE
}
public LoopedParticle(string assetName, string particleName, Entity entity, string boneName, Vector3 offset, Rotator rotation, float scale)
: this(assetName, particleName, entity, entity.GetBoneIndex(boneName), offset, rotation, scale)
{
}
public LoopedParticle(string assetName, string particleName, Vector3 position, Rotator rotation, float scale)
{
AssetName = assetName;
ParticleName = particleName;
LoadAsset();
Handle = NativeFunction.Natives.StartParticleFxLoopedAtCoord<uint>(particleName,
position.X, position.Y, position.Z,
rotation.Pitch, rotation.Roll, rotation.Yaw,
scale,
false, false, false, false);
}
private void LoadAsset()
{
NativeFunction.Natives.RequestNamedPtfxAsset(AssetName);
int waitCounter = 10;
while (!NativeFunction.Natives.HasNamedPtfxAssetLoaded<bool>(AssetName) && waitCounter > 0)
{
GameFiber.Sleep(10);
waitCounter--;
}
NativeFunction.Natives.x6C38AF3693A69A91(AssetName); // _SET_PTFX_ASSET_NEXT_CALL
}
public void SetOffsets(Vector3 offset, Rotator rotation)
{
NativeFunction.Natives.SetParticleFxLoopedOffsets(Handle.Value,
offset.X, offset.Y, offset.Z,
rotation.Pitch, rotation.Roll, rotation.Yaw);
}
public void SetColor(Color color)
{
NativeFunction.Natives.SetParticleFxLoopedColour(Handle.Value, color.R / 255f, color.G / 255f, color.B / 255f, false);
NativeFunction.Natives.SetParticleFxLoopedAlpha(Handle.Value, color.A / 255f);
}
public void SetScale(float scale)
{
NativeFunction.Natives.SetParticleFxLoopedScale(Handle.Value, scale);
}
public void SetRange(float range)
{
NativeFunction.Natives.xDCB194B85EF7B541(Handle.Value, range); // _SET_PARTICLE_FX_LOOPED_RANGE
}
public bool IsValid()
{
return NativeFunction.Natives.DoesParticleFxLoopedExist<bool>(Handle.Value);
}
public void Stop()
{
NativeFunction.Natives.StopParticleFxLooped(Handle.Value, false);
}
public bool Equals(IHandleable other)
{
if (other == null || !(other is LoopedParticle))
return false;
return this.Handle == ((LoopedParticle)other).Handle;
}
public static implicit operator bool(LoopedParticle value)
{
return value.Exists();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment