This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- @param classname string The weapon classname (e.g., "weapon_m4a1_silencer")
-- @param origin Vector (Optional) Spawn position
-- @param angles QAngle (Optional) Spawn rotation
-- @return handle The created entity handle, or nil if failed.
---
function WeaponFactory.Create(classname, origin, angles)
-- 1. Try Native Creation (Standard CS2 Behavior)
local ent = Entities:CreateByClassname(classname)
if IsValidEntity(ent) then
if origin then ent:SetAbsOrigin(origin) end
if angles then ent:SetAbsAngles(angles) end
return ent
end
-- 2. Fallback / Legacy Handling
-- If native creation failed, it might be a custom item or a legacy quirky item.
-- Note: Writing NetProps like m_iItemDefinitionIndex is not natively supported
-- in pure VScript without external tools/plugins.
print("WeaponFactory: Failed to create weapon natively: " .. classname)
return nil
end
---
-- Finds weapon entities by classname.
-- @param classname string The weapon classname to find.
-- @return table A list of handles found.
---
function WeaponFactory.FindAll(classname)
-- In CS2, we rely on the engine's tracking.
-- Legacy "cant_find" logic is generally obsolete as entities are correctly registered.
local found_weapons = Entities:FindAllByClassname(classname)
-- If no weapons found, and it's a known "legacy quirk" name, we could search parents,
-- but without the ability to read low-level NetProps reliably in all contexts,
-- returning the empty list is safer than returning incorrect parents.
return found_weapons
end
---
-- Finds the first weapon entity by classname.
-- @param classname string
-- @return handle|nil
---
function WeaponFactory.Find(classname)
local results = WeaponFactory.FindAll(classname)
if #results > 0 then
return results[1]
end
return nil
end
return WeaponFactory
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrate Source.Python CS:GO Entity Logic to Source 2 VScript #1
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Migrate Source.Python CS:GO Entity Logic to Source 2 VScript #1
Filter by extension
Viewed files
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing