跳至正文
版本:最新版 - a1.156.0 ⚖️

道具发射器

这段示例代码修改了武器,使其发射道具而不是普通子弹

This snippet uses the AR4 weapon from the default-weapons Package. Add it to the packages_requirements of your Package.toml, so it's loaded before your Package:

Package.toml
[script]
# ...
packages_requirements = [
"default-weapons",
]
Server/Index.lua
-- Spawns a Weapon from default-weapons package, close to the map origin
local my_weap = AR4(Vector(200, 0, 100), Rotator())
my_weap:SetDamage(0)

my_weap:Subscribe("Fire", function(weapon, shooter)
local control_rotation = shooter:GetControlRotation()
local forward_vector = control_rotation:GetForwardVector()
local spawn_location = shooter:GetLocation() + Vector(0, 0, 40) + forward_vector * Vector(200)

-- CollisionType.StaticOnly makes the teapots only collide with the world, so they don't hit the shooter
local prop = Prop(spawn_location, control_rotation, "nanos-world::SM_TeaPot_Interior", CollisionType.StaticOnly)
prop:AddImpulse(forward_vector * Vector(10000), true)

-- Cleans it up after 10 seconds
prop:SetLifeSpan(10)
end)