Weapon
Contains functions for configuring and customizing weapons.
Functions
equip(subject, type)
Loads the weapon on the Player or Entity to configure.
Parameters
- subject — Player or Entity to configure.
- type — WeaponType to load.
Example
Equip a grenade launcher.
function onStart()
Weapon.equip(self, WeaponType.GrenadeLauncher)
end
Result
setPrimaryColor(subject, color)
Customizes the primary color of the weapon equipped on the Player or Entity to configure.
Parameters
Example
Equip a laser beam and change the primary color to green after 2 seconds.
function onStart()
local green = Color.new(0,255,0)
Weapon.equip(self, WeaponType.LaserBeam)
Task.wait(2)
Weapon.setPrimaryColor(self, green)
end
Result
setSecondaryColor(subject, color)
Customizes the secondary color of the weapon equipped on the Player or Entity to configure.
Parameters
Example
Equip a rifle and change the secondary color to red after 2 seconds.
function onStart()
local red = Color.new(255,0,0)
Weapon.equip(self, WeaponType.Rifle)
Task.wait(2)
Weapon.setSecondaryColor(self, red)
end
Result
setBarrelSkin(subject, barrelId)
Customizes the barrel of the weapon equipped on the Player or Entity to configure.
Parameters
Example
Equip a rifle with the rail gun barrel skin after 2 seconds.
function onStart()
Weapon.equip(self, WeaponType.Rifle)
Task.wait(2)
Weapon.setBarrelSkin(self, "barrel.railgun.0")
end
Result
setBodySkin(subject, bodyId)
Customizes the body of the weapon equipped on the Player or Entity to configure.
Parameters
Example
Equip a RPG with the pistol body skin after 2 seconds.
function onStart()
Weapon.equip(self, WeaponType.RPG)
Task.wait(2)
Weapon.setBodySkin(self, "body.pistol.0")
end
Result
setGripSkin(subject, gripId)
Customizes the grip of the weapon equipped on the Player or Entity to configure.
Parameters
Example
Equip a pistol with the laser bean grip skin after 2 seconds.
function onStart()
Weapon.equip(self, WeaponType.Pistol)
Task.wait(2)
Weapon.setGripSkin(self, "grip.laserbeam.0")
end
Result
setMagazineSkin(subject, magazineId)
Customizes the magazine of the weapon equipped on the Player or Entity to configure.
Parameters
Example
Equip a RPG with the laser bean magazine skin after 2 seconds.
function onStart()
Weapon.equip(self, WeaponType.RPG)
Task.wait(2)
Weapon.setMagazineSkin(self, "magazine.laserbeam.0")
end
Result
setMuzzleSkin(subject, muzzleId)
Customizes the muzzle particle effect for the weapon equipped on the Player or Entity to configure.
Parameters
Example
Equip a rifle with the rpg muzzle skin after 2 seconds.
function onStart()
Weapon.equip(self, WeaponType.Rifle)
Task.wait(2)
Weapon.setMuzzleSkin(self, "rpg.0")
end
Result
setSightSkin(subject, sightId)
Customizes the sight of the weapon equipped on the Player or Entity to configure.
Parameters
Example
Equip a rifle with the railgun sight skin after 2 seconds.
function onStart()
Weapon.equip(self, WeaponType.Rifle)
Task.wait(2)
Weapon.setSightSkin(self, "sight.railgun.0")
end
Result
setStockSkin(subject, stockId)
Customizes the stock of the weapon equipped on the Player or Entity to configure.
Parameters
Example
Equip a pistol with the grenade launcher stock skin after 2 seconds.
function onStart()
Weapon.equip(self, WeaponType.Pistol)
Task.wait(2)
Weapon.setStockSkin(self, "stock.grenadelauncher.0")
end
Result
setProjectileColor(subject, color)
Customizes the color for the projectile of the weapon equipped on the Player or Entity to configure.
Parameters
Example
projectile color to green and after 2 seconds set it to blue.
function onStart()
Weapon.setProjectileColor(self, Color.green)
Weapon.attack()
Task.wait(2)
Weapon.setProjectileColor(self, Color.blue)
Weapon.attack()
end
Result
setSkin(subject, properties)
Customizes multiple parts of the weapon equipped on the Player or Entity to configure.
Parameters
- subject — Player or Entity to configure.
- properties — WeaponSkinConfig properties.
Example
Equip a rifle with a custom skin after 2 seconds.
function onStart()
local green = Color.new(0,255,0)
local red = Color.new(255,0,0)
local customSkin = {
primaryColor = green,
secondaryColor = red,
body = "body.pistol.0",
barrel = "barrel.railgun.0",
grip = "grip.laserbeam.0"
}
Weapon.equip(self, WeaponType.Rifle)
Task.wait(2)
Weapon.setSkin(self, customSkin)
end
Result
setReloadTime(subject, reloadTime)
Configures the time required to reload the clip on the weapon equipped on the Player or Entity to configure.
Parameters
- subject — Player or Entity to configure.
- reloadTime — Time required to reload the clip (in seconds).
- Min: 0.1
- Max: 10
Example
Attack 5 times, then wait 2 seconds and change the reload time to 0.1.
function attackEnemy()
Weapon.setAmmo(self, 3)
for i=1,5 do
Weapon.attack()
end
end
function onStart()
attackEnemy()
Weapon.setReloadTime(self, 0.1)
Task.wait(1)
attackEnemy();
end
Result
setCooldown(subject, cooldown)
Configures the minimum time it takes to shoot the weapon equipped on the Player or Entity to configure. This is useful for controlling the maximum rate for shooting the weapon.
Parameters
- subject — Player or Entity to configure.
- cooldown — Minimum time between shots (in seconds).
- Min: 0.1
- Max: 100
Example
Set weapon cooldown to 2.
function attackEnemy()
Weapon.setAmmo(self, 10)
for i=1,5 do
Weapon.attack()
end
end
function onStart()
attackEnemy()
Task.wait(1)
Weapon.setCooldown(self, 2)
attackEnemy()
end
Result
setClipSize(subject, clipSize)
Configures the clip capacity (rounds) of the weapon equipped on the Player or Entity to configure.
Parameters
- subject — Player or Entity to configure.
- clipSize — Quantity of rounds that can be fired before reloading.
- Min: 1
- Max: 999999
Example
Set clip size to 200.
function attackEnemy()
Weapon.setAmmo(self, 10)
for i=1,5 do
Weapon.attack()
end
end
function onStart()
Weapon.setClipSize(self, 3)
attackEnemy()
Task.wait(1)
Weapon.setClipSize(self, 200)
attackEnemy()
end
Result
setAmmo(subject, ammo)
Configures the quantity of ammo (rounds) remaining for the weapon equipped on the Player or Entity to configure.
Parameters
- subject — Player or Entity to configure.
- ammo — Total quantity of rounds that can be fired.
- Min: 1
- Max: 999999
Example
Set ammo to 3 and then change it to 100.
function attackEnemy()
Weapon.setAmmo(self, 10)
for i=1,5 do
Weapon.attack()
end
end
function onStart()
Weapon.equip(self, WeaponType.LaserBean)
Weapon.setAmmo(self, 5)
attackEnemy()
Task.wait(1)
Weapon.setAmmo(self, 100)
attackEnemy()
end
Result
setInfiniteAmmo(subject, infinite)
Configures whether the weapon equipped on the target Player or Entity has unlimited ammo.
Parameters
- subject — Player or Entity to configure.
- infinite — Determines whether the weapon has unlimited ammo. If
true
, the configured ammo capacity is ignored and the weapon will never run out of ammo. Otherwise, the configured ammo capcity applies.
Example
Set infinite ammo.
function attackEnemy()
for i=1,10 do
Weapon.attack()
end
end
function onStart()
Weapon.setInfiniteAmmo(self, true)
attackEnemy()
end
Result
setAutomatic(subject, automatic)
Configures whether the weapon equipped on the target Player or Entity is automatic.
Parameters
- subject — Player or Entity to configure.
- automatic — Determines whether the weapon fires automatically. If
true
, the weapon will fire repeatedly at the maximum rate, whilst the player holds down the trigger. Otherwise, the player must release the trigger before the next shot can be fired.
Example
Equip a non automatic rifle.
function attackEnemy(n)
for i=1,n do
Weapon.attack()
end
end
function onStart()
Weapon.setAutomatic(self,false)
attackEnemy(10)
Task.wait(1)
Weapon.setAutomatic(self,true)
attackEnemy(10)
end
Result
setDamage(subject, damage)
Sets the amount of damage dealt when the projectile impacts an object.
Parameters
Example
Equip a rifle with no damage, then add damage after shooting 5 times.
function attackEnemy(n)
for i=1,n do
Weapon.attack()
end
end
function onStart()
Weapon.equip(self, WeaponType.Rifle)
Weapon.setDamage(self,0)
attackEnemy(5)
Task.wait(1)
Weapon.setDamage(self,10)
attackEnemy(5)
end
Result
setDamageRadius(subject, radius)
Sets the radius of the damage zone - objects within the damage zone when the projectile impacts, will receive damage.
Parameters
Example
Set damage radius to 10.
function attackEnemy(n)
for i=1,n do
Weapon.attack()
end
end
function onStart()
attackEnemy(3)
Task.wait(2)
Weapon.setDamageRadius(self,10)
attackEnemy(3)
end
Result
setImpulse(subject, impulse)
Sets the amount of impulse to apply to objects within the damage radius.
Parameters
Example
Set impulse to 5.
function attackEnemy(n)
for i=1,n do
Weapon.attack()
end
end
function onStart()
attackEnemy(3)
Task.wait(1)
Weapon.setImpulse(self, 5)
attackEnemy(3)
end
Result
setSpeed(subject, speed)
Sets the speed of the projectile (only applies to bullet-type projectiles).
Parameters
Example
Set speed to 1 and then change it to 15.
function attackEnemy(n)
for i=1,n do
Weapon.attack()
end
end
function onStart()
Weapon.setSpeed(self, 1)
attackEnemy(3)
Task.wait(1)
Weapon.setSpeed(self, 15)
attackEnemy(3)
end
Result
setGravity(subject, gravity)
Sets the amount of gravity to apply to the projectile (only applies to bullet-type projectiles).
Parameters
Example
Set gravity to 1 (light gravity) then change it to 4.
function attackEnemy(n)
for i=1,n do
Weapon.attack()
end
end
function onStart()
Weapon.setGravity(self, 1)
attackEnemy(3)
Task.wait(1)
Weapon.setGravity(self, 4)
attackEnemy(3)
end
Result
setLifetime(subject, lifetime)
Sets the maximum time (in seconds) the projectile can exist (only applies to bullet-type projectiles).
Parameters
Example
Set projectile life time to 1 seconds, then change it to 3 seconds.
function attackEnemy(n)
for i=1,n do
Weapon.attack(Vector3.new(1,0,-6))
end
end
function onStart()
Weapon.equip(self, WeaponType.GrenadeLauncher)
Weapon.setLifetime(self, 1)
attackEnemy(3)
Task.wait(1)
Weapon.setLifetime(self, 3)
attackEnemy(3)
end
Result
setSpeedMultiplier(subject, multiplier)
Sets how much the velocity of the object shooting the projectile is added to the initial velocity of the projectile (only applies to bullet-type projectiles).
Parameters
Example
Set speed multiplier to 0.1 (this will only add 10% velocity of the object shooting the projectile).
function attackEnemy(n)
for i=1,n do
Weapon.attack()
end
end
function onStart()
Weapon.setSpeedMultiplier(self, 0.1)
attackEnemy(5)
end
setProjectileSize(subject, projectileSize)
Sets the physical size of the projectile (only applies to bullet-type projectiles).
Parameters
- subject — Player or Entity to configure.
- projectileSize — Physical size of the projectile.
- Min: 0.1
- Max: 10
Example
Equip a grenade launcher with a projectile size of 2 (twice the regular size) after shooting 3 times.
function attackEnemy(n)
for i=1,n do
Weapon.attack()
end
end
function onStart()
Weapon.equip(self, WeaponType.GrenadeLauncher)
attackEnemy(3)
Task.wait(1)
Weapon.setProjectileSize(self, 2)
attackEnemy(3)
end
Result
setRange(subject, value)
Sets the maximum range of the projectile (only applies to hitscan-type projectiles).
Parameters
Example
Set range to 3 (very short range), then increase it to 10.
function attackEnemy(n)
for i=1,n do
Weapon.attack()
end
end
function onStart()
Weapon.equip(self, WeaponType.LaserBeam)
Weapon.setRange(self, 3)
attackEnemy(5)
Task.wait(1)
Weapon.setRange(self,10)
attackEnemy(5)
end
Result
attack(subject)
Starts an attack with equipped weapons. Works only for Entity objects that can use weapons (e.g. Citizens or Robots).
Parameters
Example
Attack, wait 2 seconds, then attack again.
function onStart()
Weapon.attack()
Task.wait(2)
Weapon.attack()
end
Result
explode(damage, radius, impulse)
Explodes the Entity.
Parameters
- damage — Damage amount. Positive whole number only.
- radius — Radius of the explosion. Damage is applied to objects within this radius.
- impulse — Amount of impulse applied to objects within the radius.
- Min: 0
- Max: 100
Example
Make an explosive entity explode after 2 seconds. The explosion will deal 10 damage, will have an explosion radius of 5 and will impulse the objects withing the radius by 50.
function onStart()
Weapon.explode(10, 5, 50)
end
Result
Enums
WeaponType
- None — value = 0
- RPG — value = 1
- Rifle — value = 2
- Pistol — value = 3
- Ricochet — value = 4
- LaserBeam — value = 5
- Fist — value = 6
- GrenadeLauncher — value = 7