Skip to content

Instantly share code, notes, and snippets.

@roge
Created August 24, 2016 13:12
Show Gist options
  • Save roge/22eed0450982777bd8f2ed4da8111e12 to your computer and use it in GitHub Desktop.
Save roge/22eed0450982777bd8f2ed4da8111e12 to your computer and use it in GitHub Desktop.
Nade Training v1.0.4-beta by roge. Add file to "Counter-Strike Global Offensive/csgo/scripts/vscripts" then run `script_execute NT.nut` to run.
const NT_TIMER_ENTITY_TARGET_NAME = "NT_TimerEnt";
const NT_SCRIPT_VERSION = "1.0.4-beta";
NT_LastGrenade <- null;
NT_LastRestoredGrenade <- null;
NT_SavedGrenadePosition <- null;
NT_SavedGrenadeVelocity <- null;
NT_AwaitingSave <- false;
NT_IsPaused <- false;
function NT_Setup() {
printl("Setting up Nade Training...");
/* Destroy old timer entities. */
local entity = null;
while(entity = Entities.FindByName(entity, NT_TIMER_ENTITY_TARGET_NAME)) {
entity.Destroy();
}
/* Create new timer entity. */
local timerEnt = Entities.CreateByClassname("logic_timer");
EntFireByHandle(timerEnt, "disable", "", 0.0, null, null);
timerEnt.__KeyValueFromString("targetname", NT_TIMER_ENTITY_TARGET_NAME);
timerEnt.__KeyValueFromFloat("refiretime", 0.02);
timerEnt.__KeyValueFromInt("startdisabled", 0);
timerEnt.__KeyValueFromInt("UseRandomTime", 0);
timerEnt.ConnectOutput("ontimer", "NT_Think");
EntFireByHandle(timerEnt, "enable", "", 0.0, null, null);
/* Create aliases to script functions. This is a hacky way of registering commands */
SendToConsole("alias nt_save \"script NT_PromptSave()\"");
SendToConsole("alias nt_pause \"script NT_TogglePause()\"");
NT_DualPrintFormatted("Nade Training v" + NT_SCRIPT_VERSION + " loaded!");
NT_DualPrintFormatted("Rewritten by roge <roge@riseup.net>");
NT_DualPrintFormatted("Originally written by S0lll0s, Bidj, and Rurre");
NT_DualPrintFormatted("Use console command `nt_save` to save next grenade.");
NT_DualPrintFormatted("Use console command `nt_pause` to toggle the plugin.");
}
function NT_IsRunning() {
return Entities.FindByName(null, NT_TIMER_ENTITY_TARGET_NAME) != null;
}
function NT_TogglePause() {
if(!NT_IsRunning()) return;
NT_IsPaused = !NT_IsPaused;
NT_DualPrintFormatted(NT_IsPaused ? "Script is paused. Grenades can now be thrown freely." : "Script is no longer paused. Grenades will be saved and restored.");
NT_AwaitingSave = false;
}
function NT_PromptSave() {
if(!NT_IsRunning()) return;
if(NT_IsPaused) {
NT_DualPrintFormatted("Grenades cannot be saved while script is paused.");
return;
}
NT_AwaitingSave = true;
NT_DualPrintFormatted("Next Flashbang or HE Grenade will be saved.");
}
function NT_DualPrintFormatted(str) {
printl("[Nade Training] " + str);
ScriptPrintMessageChatAll("\x01[\x0BNade Training\x01] " + str);
}
function NT_Think() {
if(NT_IsPaused) return;
NT_HandleGrenadeClass("flashbang_projectile");
NT_HandleGrenadeClass("hegrenade_projectile");
}
function NT_HandleGrenadeClass(classname) {
local grenade = null;
while(grenade = Entities.FindByClassname(grenade, classname)) {
if(grenade == NT_LastGrenade) continue;
if(NT_AwaitingSave)
NT_SaveGrenade(grenade);
else
NT_RestoreGrenade(grenade);
NT_LastGrenade = grenade;
}
}
function NT_SaveGrenade(grenade) {
if(NT_LastRestoredGrenade != null && grenade == NT_LastRestoredGrenade) {
NT_DualPrintFormatted("Please wait for all existing grenades to detonate before saving.");
NT_DualPrintFormatted("Nothing saved.");
NT_PromptSave();
return;
}
NT_SavedGrenadePosition = grenade.GetCenter();
NT_SavedGrenadeVelocity = grenade.GetVelocity();
NT_DualPrintFormatted("Grenade saved.");
NT_AwaitingSave = false;
}
function NT_RestoreGrenade(grenade) {
if(NT_SavedGrenadePosition == null || NT_SavedGrenadeVelocity == null) return;
grenade.SetAbsOrigin(NT_SavedGrenadePosition);
grenade.SetVelocity(NT_SavedGrenadeVelocity);
NT_LastRestoredGrenade = grenade;
}
NT_Setup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment