/* * Author: Needles * https://steamcommunity.com/profiles/76561198026257137/ */ ::Debug.Print("*** WEAPONS"); ::Weapons <- {}; function Weapons::GetItemDefintionIndex(weapon) { return NetProps.GetPropInt(weapon, "m_AttributeManager.m_Item.m_iItemDefinitionIndex"); } // Mostly stolen from GiveTFWeapon // https://tf2maps.net/downloads/vscript-give_tf_weapon.14897/ function Weapons::CreateWeapon(classname, itemDefinitionIndex, origin, angles) { local weapon = Entities.CreateByClassname(classname); NetProps.SetPropInt(weapon, "m_AttributeManager.m_Item.m_iItemDefinitionIndex", itemDefinitionIndex); NetProps.SetPropBool(weapon, "m_AttributeManager.m_Item.m_bInitialized", true); NetProps.SetPropBool(weapon, "m_bValidatedAttachedEntity", true); Entities.DispatchSpawn(weapon); weapon.SetOrigin(origin); weapon.SetAbsAngles(angles); return weapon; } function Weapons::FindLatestProjectile(weapon, classname) { local latestTime = null; local latestEnt = null; local ent = null; while (ent = Entities.FindByClassname(ent, classname)) { if (NetProps.GetPropEntity(ent, "m_hLauncher") != weapon) continue; ent.ValidateScriptScope(); local scope = ent.GetScriptScope(); if (!("creationTime" in scope)) { scope.creationTime <- Time(); } if (latestTime == null || scope.creationTime < latestTime) { latestTime = scope.creationTime; latestEnt = ent; } } return latestEnt; }