Okay so this is what I’ve tried so far. I am trying to have a text to show up on the screen while I am in a certain area. Bare with me since i am new into C# development and I am trying to learn.
class Safezones : BaseScript
{
private bool inSafezone = false;
public class Safezone
{
public Vector3 Pos { get; private set; }
public float Range { get; private set; }
public Safezone(Vector3 pos, float range)
{
Pos = pos;
Range = range;
}
}
public static Safezone[] SAFEZONES { get; } =
{
new Safezone(new Vector3(3474, 3681, 34), 250f)
};
public Safezones()
{
Tick += OnTick;
}
public async Task OnTick()
{
if (API.NetworkIsSessionStarted() && !API.GetIsLoadingScreenActive())
{
Ped playerPed = Game.PlayerPed;
bool inSafezoneNow = false;
foreach (Safezone safezone in SAFEZONES)
if (World.GetDistance(playerPed.Position, safezone.Pos) < safezone.Range)
{
inSafezoneNow = true;
break;
}
if (inSafezoneNow && !inSafezone)
{
inSafezone = true;
API.NetworkSetFriendlyFireOption(false);
API.SetCurrentPedWeapon(playerPed.Handle, (uint)WeaponHash.Unarmed, true);
API.DisablePlayerFiring(playerPed.Handle, true);
API.DisableControlAction(2, 37, true);
API.DisableControlAction(0, 106, true);
API.SetTextFont(4);
API.SetTextScale(0.5f, 0.5f);
API.SetTextColour(0, 198, 0, 180);
API.SetTextOutline();
API.SetTextEntry("STRING");
API.AddTextComponentString("In SafeZone");
API.DrawText(0.43f, 0.02f);
if (API.IsDisabledControlJustPressed(2, 37) | API.IsDisabledControlJustPressed(0, 106))
{
API.SetCurrentPedWeapon(playerPed.Handle, (uint)WeaponHash.Unarmed, true);
TriggerEvent("chat:addMessage", new { color = new[] { 0, 198, 0 }, multiline = true, args = new[] { "You", "I can't do this" } });
}
}
else if (!inSafezoneNow && inSafezone)
{
inSafezone = false;
API.NetworkSetFriendlyFireOption(true);
TriggerEvent("chat:addMessage", new { color = new[] { 255, 0, 0 }, multiline = true, args = new[] { "You", "I just left the safezone" } });
}
}
await Task.FromResult(100);
}
}
}