From b6ccd9872599effbc746eb3582cae1280e403c9e Mon Sep 17 00:00:00 2001 From: Jackz Date: Thu, 21 Jul 2022 22:52:36 -0500 Subject: [PATCH] Attempt to get rock throwing to work --- scripting/include/feedthetrolls/base.inc | 2 +- scripting/include/feedthetrolls/events.inc | 28 ++++++++++++- scripting/include/feedthetrolls/misc.inc | 49 ++++++++++++++++++++++ scripting/include/feedthetrolls/timers.inc | 3 +- scripting/include/feedthetrolls/trolls.inc | 23 ++++++++++ scripting/include/ftt.inc | 2 + scripting/l4d2_feedthetrolls.sp | 1 + 7 files changed, 105 insertions(+), 3 deletions(-) diff --git a/scripting/include/feedthetrolls/base.inc b/scripting/include/feedthetrolls/base.inc index d21d430..f9314df 100644 --- a/scripting/include/feedthetrolls/base.inc +++ b/scripting/include/feedthetrolls/base.inc @@ -4,7 +4,7 @@ //Allow MAX_TROLLS to be defined elsewhere #if defined MAX_TROLLS #else - #define MAX_TROLLS 41 + #define MAX_TROLLS 42 #endif enum trollModifier { diff --git a/scripting/include/feedthetrolls/events.inc b/scripting/include/feedthetrolls/events.inc index 71a8751..1bf8846 100644 --- a/scripting/include/feedthetrolls/events.inc +++ b/scripting/include/feedthetrolls/events.inc @@ -38,10 +38,36 @@ public void OnEntityCreated(int entity, const char[] classname) { SDKHook(entity, SDKHook_OnTakeDamageAlive, NerfGun_OnTakeDamage); else if(StrContains(classname, "_projectile", true) > -1 ) { RequestFrame(EntityCreateCallback, entity); - } + } /*else if(g_iRockThrows > 0 && StrEqual(classname, "tank_rock")) { + --g_iRockThrows; + SDKHook(entity, SDKHook_SpawnPost, SpawnPost); + }*/ } } +/*void SpawnPost(int entity) { + RequestFrame(SetRockVelocity, EntIndexToEntRef(entity)) +} + +void SetRockVelocity(int entity) { + entity = EntRefToEntIndex(entity); + + if(!IsValidEntity(entity)) return; + + float vel[3]; + + GetEntPropVector(entity, Prop_Send, "m_vecVelocity", vel); + + ScaleVector(vel, 0.4); + + // z_tank_throw_force + //SetEntPropVector(entity, Prop_Send, "m_vecVelocity", vel); + vel[2] += 150.0; + TeleportEntity(entity, NULL_VECTOR, NULL_VECTOR, vel); + PrintToChatAll("set rock %d vel", entity); + +}*/ + void EntityCreateCallback(int entity) { if(!HasEntProp(entity, Prop_Send, "m_hOwnerEntity") || !IsValidEntity(entity)) return; static char class[16]; diff --git a/scripting/include/feedthetrolls/misc.inc b/scripting/include/feedthetrolls/misc.inc index c55f9c7..d7f26ce 100644 --- a/scripting/include/feedthetrolls/misc.inc +++ b/scripting/include/feedthetrolls/misc.inc @@ -476,4 +476,53 @@ void StopHealingBots() { } if(hAbmAutoHard != null) hAbmAutoHard.IntValue = wasAbmAutoHard; if(hSbFixEnabled != null) hSbFixEnabled.BoolValue = wasSbFixEnabled; +} + +// Spawns a env_rock_launcher to throw at a random specified target name. +// Does not auto fire, need to call input LaunchRock +// Damage -1 will not override damage +// autoDeleteTime of <= 0.0 will persist forever. +stock int CreateRockLauncher(const float origin[3], const float ang[3], const char[] targetName, float damage = -1.0, float autoDeleteTime = 0.0) { + int launcher = CreateEntityByName("env_rock_launcher"); + if(launcher == -1) return -1; + // DispatchKeyValue(launcher, "targetname", "ftt_rock_launcher"); + DispatchKeyValue(launcher, "RockTargetName", targetName); + if(damage >= 0.0) { + DispatchKeyValueFloat(launcher, "RockDamageOverride", damage); + } + if(autoDeleteTime > 0.0) CreateTimer(autoDeleteTime, Timer_Delete, launcher); + DispatchSpawn(launcher); + TeleportEntity(launcher, origin, ang, NULL_VECTOR); + PrintToChatAll("Created rock launcher at %f %f %f at ang %f %f %f", origin[0], origin[1], origin[2], ang[0], ang[1], ang[2]); + // AcceptEntityInput(launcher, "Kill"); + return launcher; +} + +#define FTT_TARGET_NAME "ftt_target" +stock bool ThrowRockAtPosition(const float origin[3], float pos[3], float damage = -1.0) { + CreateTarget(pos, FTT_TARGET_NAME, 0.2); + GetVectorAngles(pos, pos); + int launcher = CreateRockLauncher(origin, pos, FTT_TARGET_NAME, damage, 0.0); + g_iRockThrows++; + AcceptEntityInput(launcher, "LaunchRock"); + AcceptEntityInput(launcher, "Kill"); + return true; +} +stock bool ThrowRockAtEntity(const float origin[3], int target, float damage = -1.0) { + float pos[3]; + GetEntPropVector(target, Prop_Send, "m_vecOrigin", pos); + return ThrowRockAtPosition(origin, pos, damage); +} + +int CreateTarget(const float origin[3], const char[] targetName, float duration = 0.0) { + int target = CreateEntityByName("info_target"); + DispatchKeyValue(target, "targetname", targetName); + + TeleportEntity(target, origin, NULL_VECTOR, NULL_VECTOR); + DispatchSpawn(target); + if(duration > 0.0) { + CreateTimer(duration, Timer_Delete, target); + } + PrintToServer("Created info_target at %f %f %f", origin[0], origin[1], origin[2]); + return target; } \ No newline at end of file diff --git a/scripting/include/feedthetrolls/timers.inc b/scripting/include/feedthetrolls/timers.inc index 1cd1128..e9a1d92 100644 --- a/scripting/include/feedthetrolls/timers.inc +++ b/scripting/include/feedthetrolls/timers.inc @@ -138,7 +138,8 @@ public Action Timer_KickBot(Handle timer, int client) { } public Action Timer_Delete(Handle h, int id) { - AcceptEntityInput(id, "Kill"); + if(IsValidEntity(id)) + AcceptEntityInput(id, "Kill"); return Plugin_Handled; } diff --git a/scripting/include/feedthetrolls/trolls.inc b/scripting/include/feedthetrolls/trolls.inc index bbe1495..e8b600e 100644 --- a/scripting/include/feedthetrolls/trolls.inc +++ b/scripting/include/feedthetrolls/trolls.inc @@ -146,6 +146,10 @@ void SetupTrolls() { /// CATEGORY: MISC SetCategory("Misc"); + /*index = SetupTroll("Rock Dropper", "Drops on a rock. On their head.", TrollMod_Instant); + Trolls[index].AddFlagPrompt(false); + Trolls[index].AddFlag("Drop From Above", true); + Trolls[index].AddFlag("From behind", false);*/ SetupTroll("Gun Jam", "On reload, small chance their gun gets jammed - Can't reload.", TrollMod_Constant); SetupTroll("No Shove", "Prevents a player from shoving", TrollMod_Constant); index = SetupTroll("Car Splat", "Car. splats.", TrollMod_Instant); @@ -302,6 +306,21 @@ bool ApplyAffect(int victim, const Troll troll, int activator, trollModifier mod SetEntProp(primaryWpn, Prop_Send, "m_iClip1", GetRandomInt(0, maxCap)); } } + } else if(StrEqual(troll.name, "Rock Dropper")) { + float pos[3], dropPos[3]; + GetClientEyePosition(victim, pos); + dropPos = pos; + dropPos[2] += 150.0; + TR_TraceRayFilter(pos, dropPos, MASK_SOLID, RayType_EndPoint, Filter_IgnorePlayer, victim); + if(TR_DidHit()) { + ReplyToCommand(activator, "Could not find a suitable area. Requires vertical space."); + return false; + } + PrintToServer("running: ThrowRockAtEntity at %f %f %f", dropPos[0], dropPos[1], dropPos[2]); + if(!ThrowRockAtEntity(dropPos, victim, 100.0)) { + ReplyToCommand(activator, "Rock dropper failed"); + return false; + } } else if(~modifier & TrollMod_Constant) { PrintToServer("[FTT] Warn: Possibly invalid troll, no apply action defined for \"%s\"", troll.name); #if defined DEBUG @@ -309,4 +328,8 @@ bool ApplyAffect(int victim, const Troll troll, int activator, trollModifier mod #endif } return true; +} + +bool Filter_IgnorePlayer(int entity, int contentsMask, any data) { + return entity != data; } \ No newline at end of file diff --git a/scripting/include/ftt.inc b/scripting/include/ftt.inc index 89a4269..6bc8c91 100644 --- a/scripting/include/ftt.inc +++ b/scripting/include/ftt.inc @@ -89,6 +89,8 @@ enum SpecialInternalFlags { int healTargetPlayer; float healTargetPos[3]; +int g_iRockThrows; + #define MODEL_CAR "models/props_vehicles/cara_95sedan.mdl" #include diff --git a/scripting/l4d2_feedthetrolls.sp b/scripting/l4d2_feedthetrolls.sp index c840fb1..bd34e75 100644 --- a/scripting/l4d2_feedthetrolls.sp +++ b/scripting/l4d2_feedthetrolls.sp @@ -89,6 +89,7 @@ public void OnPluginStart() { RegAdminCmd("sm_insta", Command_InstaSpecial, ADMFLAG_KICK, "Spawns a special that targets them, close to them."); RegAdminCmd("sm_stagger", Command_Stagger, ADMFLAG_KICK, "Stagger a player"); RegAdminCmd("sm_inface", Command_InstaSpecialFace, ADMFLAG_KICK, "Spawns a special that targets them, right in their face."); + // TODO: Merge as trolls RegAdminCmd("sm_bots_attack", Command_BotsAttack, ADMFLAG_CHEATS, "Instructs all bots to attack a player until they have X health."); RegAdminCmd("sm_scharge", Command_SmartCharge, ADMFLAG_CHEATS, "Auto Smart charge"); RegAdminCmd("sm_healbots", Command_HealTarget, ADMFLAG_CHEATS, "Make bots heal a player");