-
Notifications
You must be signed in to change notification settings - Fork 0
/
nadeSaver.nut
135 lines (105 loc) · 3.86 KB
/
nadeSaver.nut
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
this.TOGGLE_BUTTON <- "F5";
this.SLOT_BUTTONS <- ["F6", "F7", "F8"];
this.TYPE_HE <- "hegrenade_projectile";
this.TYPE_FLASH <- "flashbang_projectile";
this.TYPE_SMOKE <- "smokegrenade_projectile";
this.TYPE_MOLOTOV <- "molotov_projectile";
this.TYPE_DECOY <- "decoy_projectile";
this.TYPES <- [TYPE_HE, TYPE_FLASH, TYPE_SMOKE, TYPE_MOLOTOV, TYPE_DECOY];
this.currentSlot <- 0;
this.nadeSaveMode <- true;
this.savedNades <- [];
this.nadeQueue <- [];
printl(@"nadeSaver executed");
printl(@"type to start: script nadeSetup()");
function nadeSetup() {
local nadeTimer = Entities.FindByName(null, "nadeTimer");
if (!nadeTimer)
{
nadeTimer = Entities.CreateByClassname("logic_timer");
nadeTimer.__KeyValueFromFloat("refireTime", 0.05);
nadeTimer.__KeyValueFromInt("startDisabled", 0);
nadeTimer.__KeyValueFromInt("useRandomTime", 0);
EntFireByHandle(nadeTimer, "addoutput", "targetname nadeTimer", 0.0, null, null);
EntFire("nadeTimer", "addoutput", "ontimer nadeTimer,RunScriptCode,nadeThink()");
EntFire("nadeTimer", "enable");
}
SendToConsole(@"bind """ + TOGGLE_BUTTON + @""" ""script toggleNadeSaving()""");
for (local i = 0; i < SLOT_BUTTONS.len(); ++i) {
SendToConsole(@"bind """ + SLOT_BUTTONS[i] + @""" ""script queueNade(" + i + @")""");
savedNades.push(null);
}
}
function nadeThink() {
local nade = null;
foreach (type in TYPES) {
while (nade = Entities.FindByClassname(nade, type)) {
if (nadeQueue.len() > 0) {
spawnNade(nade, type);
} else if (nadeSaveMode) {
saveNade(nade, type);
}
}
}
}
function isNadeUsed(nade) {
// This is a hack, we mark used nades by giving them a random health
if (nade.GetHealth() == 1337) {
return true;
}
}
function markNadeUsed(nade) {
nade.SetHealth(1337);
}
function saveNade(nade, type) {
if (isNadeUsed(nade)) return;
markNadeUsed(nade);
local savedNade = {};
savedNade["type"] <- type;
savedNade["vel"] <- nade.GetVelocity();
savedNade["pos"] <- nade.GetCenter();
savedNade["angles"] <- nade.GetAngles();
savedNade["angularVelocity"] <- nade.GetAngularVelocity();
savedNades[currentSlot] = savedNade;
ScriptPrintMessageCenterAll("Saved grenade to " + SLOT_BUTTONS[currentSlot]);
}
function spawnNade(nade, type) {
for (local i = 0; i < nadeQueue.len(); ++i) {
local savedNade = nadeQueue[i];
if (savedNade.type != type)
continue;
if (isNadeUsed(nade)) continue;
markNadeUsed(nade);
nade.SetAbsOrigin(savedNade["pos"]);
nade.SetVelocity(savedNade["vel"]);
nade.SetAngles(savedNade["angles"].x, savedNade["angles"].y, savedNade["angles"].z);
nade.SetAngularVelocity(savedNade["angularVelocity"].x, savedNade["angularVelocity"].y, savedNade["angularVelocity"].z);
if (type == TYPE_HE || savedNade.type == TYPE_MOLOTOV) {
EntFireByHandle(nade, "InitializeSpawnFromWorld", "", 0.0, nade.GetOwner(), nade.GetOwner());
}
nadeQueue.remove(i);
return;
}
}
function toggleNadeSaving() {
foreach (type in TYPES) {
SendToConsole(@"ent_fire " + type + " kill");
}
if (nadeSaveMode) {
nadeSaveMode = false;
ScriptPrintMessageCenterAll("Grenade saving disabled");
} else {
nadeSaveMode = true;
currentSlot = (currentSlot + 1) % SLOT_BUTTONS.len();
ScriptPrintMessageCenterAll("Saving next grenade to " + SLOT_BUTTONS[currentSlot]);
}
}
function queueNade(slot) {
local savedNade = savedNades[slot];
if (savedNade == null) {
ScriptPrintMessageCenterAll("No grenade has been saved to slot " + SLOT_BUTTONS[slot]);
return;
}
SendToConsole(@"ent_create " + savedNade.type);
nadeQueue.push(savedNade);
}