-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMod.cs
115 lines (96 loc) · 3.2 KB
/
Mod.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using GTA;
using GTA.Math;
using GTA.UI;
using LemonUI;
using LemonUI.Menus;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace SHVDNModTemplate
{
public sealed class Mod : Script
{
private readonly ScriptSettings config = ScriptSettings.Load("scripts\\ModSettings.ini");
private readonly List<Vehicle> vehicles = new List<Vehicle>();
private readonly ObjectPool pool = new ObjectPool();
private readonly NativeMenu menu = new NativeMenu("Mod", "Menu");
private readonly NativeItem item = new NativeItem("Spawn car", "Spawn a car", "A really fast one");
private void ClearPools()
{
foreach (var v in vehicles)
{
v.MarkAsNoLongerNeeded();
}
}
private void ItemActivated(object sender, EventArgs e)
{
var v = World.CreateVehicle(VehicleHash.Adder, World.GetNextPositionOnStreet(Game.Player.Character.Position));
vehicles.Add(v);
menu.Visible = false;
}
private void CreateMenu()
{
item.Activated += ItemActivated;
menu.Add(item);
pool.Add(menu);
}
private void Setup()
{
CreateMenu();
var modName = config.GetValue("Config", "ModName", "Mod");
var showHelp = config.GetValue("Config", "ShowHelp", true);
if (showHelp) Notification.Show($"Mod loaded: {modName}");
GTA.UI.Screen.ShowHelpText("Press ~INPUT_CONTEXT~ to open a menu.", 10);
}
public Mod()
{
Setup();
SetupPlayer();
Tick += OnTick;
KeyDown += OnKeyDown;
Aborted += OnAbort;
}
public void OnTick(object sender, EventArgs e)
{
// The main mod loop. Menus, input and mod logic are processed here
pool.Process();
if (Game.IsControlJustPressed(GTA.Control.Context))
{
menu.Visible = true;
}
MainLoop();
}
private static void SetupPlayer()
{
Game.Player.IsInvincible = true;
}
private static void ResetPlayer()
{
Game.Player.IsInvincible = false;
}
private static void MainLoop()
{
World.DrawMarker(MarkerType.VerticalCylinder, new Vector3(1, 1, 1), Vector3.Zero, Vector3.Zero, new Vector3(1, 1, 1), Color.Yellow);
}
public void OnKeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.T:
if (!Game.IsWaypointActive) return;
Game.Player.Character.Position = (World.WaypointPosition + Vector3.WorldUp * 3);
break;
case Keys.P:
Notification.Show(Game.Player.Character.Position.ToString());
break;
}
}
private void OnAbort(object sender, EventArgs e)
{
// Don't forget to clean up after exit or failure
ResetPlayer();
ClearPools();
}
}
}