Skip to content

Commit

Permalink
Merge pull request #1 from TomGrobbe/fresh
Browse files Browse the repository at this point in the history
Fresh
  • Loading branch information
TomGrobbe authored Feb 19, 2018
2 parents 09a50c4 + a4b908a commit 123653b
Show file tree
Hide file tree
Showing 18 changed files with 839 additions and 674 deletions.
1 change: 1 addition & 0 deletions docs/INFO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Soon™
35 changes: 24 additions & 11 deletions vMenu/CommonFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,23 @@ private async Task OnTick()
DoScreenFadeIn(200);
await Delay(200);
spectating = true;
}

// Wait until spectating is cancelled.
// Either by the user itself, or if the other player disconencts, or if the current player dies.
while (spectating && spectatePlayer != -1 && NetworkIsPlayerActive(spectatePlayer) && !IsPlayerDead(PlayerId()))
{
await Delay(0);

// Wait until spectating is cancelled.
// Either by the user itself, or if the other player disconencts, or if the current player dies.
while (spectating && spectatePlayer != -1 && NetworkIsPlayerActive(spectatePlayer) && !IsPlayerDead(PlayerId()))
{
await Delay(0);
}
DoScreenFadeOut(200);
await Delay(200);
NetworkSetInSpectatorMode(false, PlayerPedId());
DoScreenFadeIn(200);
await Delay(200);
}
DoScreenFadeOut(200);
await Delay(200);
NetworkSetInSpectatorMode(false, PlayerPedId());
DoScreenFadeIn(200);
await Delay(200);
}
#endregion

#region GetVehicle from specified player id (if not specified, return the vehicle of the current player)
/// <summary>
/// Get the vehicle from the specified player. If no player specified, then return the vehicle of the current player.
Expand Down Expand Up @@ -165,7 +167,18 @@ public async void TeleportToPlayerAsync(int playerId, bool inVehicle = false)
return;
}
}

public void KillPlayer(Player player)
{
TriggerServerEvent("vMenu:KillPlayer", player.Handle);
}

public void SummonPlayer(Player player)
{
TriggerServerEvent("vMenu:SummonPlayer", player.Handle);
}
#endregion

#region Spectate function
/// <summary>
/// Toggle spectating for the specified player Id. Leave the player ID empty (or -1) to disable spectating.
Expand Down
30 changes: 30 additions & 0 deletions vMenu/EventManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CitizenFX.Core;
using static CitizenFX.Core.Native.API;

namespace vMenuClient
{
public class EventManager : BaseScript
{
private static CommonFunctions cf = new CommonFunctions();
public EventManager()
{
EventHandlers.Add("vMenu:GoToPlayer", new Action<int>(SummonPlayer));
EventHandlers.Add("vMenu:KillMe", new Action(KillMe));
}

private void KillMe()
{
SetEntityHealth(PlayerPedId(), 0);
}

private void SummonPlayer(int targetPlayer)
{
cf.TeleportToPlayerAsync(GetPlayerFromServerId(targetPlayer));
}
}
}
91 changes: 91 additions & 0 deletions vMenu/FunctionsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CitizenFX.Core;
using static CitizenFX.Core.Native.API;
using NativeUI;

namespace vMenuClient
{
class FunctionsController : BaseScript
{
CommonFunctions cf = new CommonFunctions();
public FunctionsController()
{
Tick += OnTick;
}

private async Task OnTick()
{
// Player options. Only run player options if the player options menu has actually been created.
if (MainMenu._po != null)
{
// Manage Player God Mode
SetEntityInvincible(PlayerPedId(), MainMenu._po.PlayerGodMode);

// Manage invisibility.
SetEntityVisible(PlayerPedId(), !MainMenu._po.PlayerInvisible, false);

// Manage Stamina
if (MainMenu._po.PlayerStamina)
{
ResetPlayerStamina(PlayerId());
}

// Manage Super jump.
if (MainMenu._po.PlayerSuperJump)
{
SetSuperJumpThisFrame(PlayerId());
}

// Manage PlayerNoRagdoll
SetPedCanRagdoll(PlayerPedId(), MainMenu._po.PlayerNoRagdoll);
SetPedCanRagdollFromPlayerImpact(PlayerPedId(), MainMenu._po.PlayerNoRagdoll);

// Manage never wanted.
if (MainMenu._po.PlayerNeverWanted && GetPlayerWantedLevel(PlayerId()) > 0)
{
ClearPlayerWantedLevel(PlayerId());
}

// Manage player is ignored by everyone.
SetEveryoneIgnorePlayer(PlayerId(), MainMenu._po.PlayerIsIgnored);

// Manage player frozen.
FreezeEntityPosition(PlayerPedId(), MainMenu._po.PlayerFrozen);
}

// Vehicle options. Only run vehicle options if the vehicle options menu has actually been created.
if (MainMenu._vo != null)
{
if (DoesEntityExist(cf.GetVehicle()))
{
// Vehicle.
Vehicle vehicle = new Vehicle(cf.GetVehicle());

// God mode
var god = MainMenu._vo.VehicleGodMode;
vehicle.CanBeVisiblyDamaged = !god;
vehicle.CanEngineDegrade = !god;
vehicle.CanTiresBurst = !god;
vehicle.CanWheelsBreak = !god;
vehicle.IsAxlesStrong = god;
vehicle.IsBulletProof = god;
vehicle.IsCollisionProof = god;
vehicle.IsExplosionProof = god;
vehicle.IsFireProof = god;
vehicle.IsInvincible = god;
vehicle.IsMeleeProof = god;
}

if (MainMenu._vo.VehicleEngineAlwaysOn && DoesEntityExist(cf.GetVehicle(last: true)) && !DoesEntityExist(cf.GetVehicle(last: false)))
{
SetVehicleEngineOn(cf.GetVehicle(last: true), true, true, true);
}

}
}
}
}
114 changes: 100 additions & 14 deletions vMenu/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@
using CitizenFX.Core;
using static CitizenFX.Core.Native.API;
using NativeUI;
using vMenuClient.menus;

namespace vMenuClient
{

public class MainMenu : BaseScript
{
// Variables
public static MenuPool _mp = new MenuPool();
public static System.Drawing.PointF MenuPosition = new System.Drawing.PointF(CitizenFX.Core.UI.Screen.Resolution.Width - 465f, 45f);
private static Notification Notify = new Notification();
private static Subtitles Subtitle = new Subtitles();

private bool firstTick = true;
private bool setupComplete = false;
private bool setupComplete = true;
public static UIMenu menu;
public static PlayerOptions _po;
public static OnlinePlayers _op;
public static VehicleOptions _vo;

private BarTimerBar bt = new BarTimerBar("Opening Menu");
private bool debug = false;
public static Sprite BannerSprite { get; private set; } = new Sprite("menubanner", "menu_header", new System.Drawing.PointF(0f, 0f), new System.Drawing.SizeF(0f, 0f), 0f, UnknownColors.DarkGray);

/// <summary>
/// Constructor.
Expand All @@ -39,30 +47,108 @@ private async Task OnTick()
{
firstTick = false;
// Request the data from the server.
TriggerServerEvent("vMenu:GetSettings");
//TriggerServerEvent("vMenu:GetSettings");

// Wait until the data is received.
while (!setupComplete)
while (!setupComplete && (GetPlayerName(PlayerId()) == "**Invalid**" || GetPlayerName(PlayerId()) == "** Invalid **"))
{
await Delay(0);
}

// Create the main menu.
menu = new UIMenu(GetPlayerName(PlayerId()), "Main Menu")
{
ControlDisablingEnabled = false
};

menu.RefreshIndex();
menu = new UIMenu(GetPlayerName(PlayerId()), "Main Menu", MenuPosition);

// Add the main menu to the menu pool.
_mp.Add(menu);

menu.RefreshIndex();
menu.ScaleWithSafezone = false;


// Create all (sub)menus.
var onlinePlayersMenu = new OnlinePlayersMenu();
var playerOptionsMenu = new PlayerOptionsMenu();

// Add the online players menu.
UIMenuItem onlinePlayersBtn = new UIMenuItem("Online Players", "All currently connected players.");
menu.AddItem(onlinePlayersBtn);
_op = new OnlinePlayers();
UIMenu onlinePlayers = _op.GetMenu();
menu.BindMenuToItem(onlinePlayers, onlinePlayersBtn);
_mp.Add(onlinePlayers);
menu.UpdateScaleform();

// Add the player options menu.
UIMenuItem playerOptionsBtn = new UIMenuItem("Player Options", "Common player options can be accessed here.");
menu.AddItem(playerOptionsBtn);
_po = new PlayerOptions();
UIMenu playerOptions = _po.GetMenu();
menu.BindMenuToItem(playerOptions, playerOptionsBtn);
_mp.Add(playerOptions);

// Add the vehicle options Menu.
UIMenuItem vehicleOptionsBtn = new UIMenuItem("Vehicle Options", "Here you can change common vehicle options, as well as tune & style your vehicle.");
menu.AddItem(vehicleOptionsBtn);
_vo = new VehicleOptions();
UIMenu vehicleOptions = _vo.GetMenu();
menu.BindMenuToItem(vehicleOptions, vehicleOptionsBtn);
_mp.Add(vehicleOptions);



// Refresh everything.
_mp.RefreshIndex();
onlinePlayers.UpdateScaleform();
playerOptions.UpdateScaleform();
menu.UpdateScaleform();

// Set the banner globally.
_mp.SetBannerType(BannerSprite);
// Globally disable the native ui controls disabling.
_mp.ControlDisablingEnabled = false;
// Globally disable the "mouse edge" feature.
_mp.MouseEdgeEnabled = false;
}
// Todo: more stuff
else
{
if (Game.CurrentInputMode == InputMode.MouseAndKeyboard && Game.IsControlJustPressed(0, Control.InteractionMenu))
{
if (_mp.IsAnyMenuOpen())
{
_mp.CloseAllMenus();
}
else
{
menu.Visible = !_mp.IsAnyMenuOpen();
}

}
else if (!_mp.IsAnyMenuOpen() && Game.CurrentInputMode == InputMode.GamePad)
{
float timer = 0f;
while (Game.CurrentInputMode == InputMode.GamePad && Game.IsControlPressed(0, Control.InteractionMenu))
{
timer++;

if (debug)
{
bt.Draw(0);
float percent = (timer / 60f);
bt.Percentage = percent;
Subtitle.Success(percent.ToString(), 0, true, "Progress:");
}

if (timer > 59)
{
menu.Visible = !_mp.IsAnyMenuOpen();
break;
}

await Delay(0);
}
}

_mp.ProcessMenus();
}


}
}
Expand Down
Loading

0 comments on commit 123653b

Please sign in to comment.