createWeapon
Client-side
Server-side
Shared
Manual Review Required
Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.
Creates a custom weapon that can fire bullets. Do not confuse this with player held weapons.
Tip
Some weapons (such as the minigun) visually point to a slightly different direction to where they fire. To adjust this, use setWeaponProperty with 'fire_rotation'. See the example below.
OOP Syntax Help! I don't understand this!
- Constructor: Weapon(...)
Syntax
weapon createWeapon ( string theType, float x, float y, float z )Required Arguments
- theType: The weapon type which can be:
- x: MISSING_PARAM_DESC
- y: MISSING_PARAM_DESC
- z: MISSING_PARAM_DESC
Returns
- weapon: value
Returns a custom weapon element, which represents a weapon floating at that position.
Code Examples
shared
This example adds a/createminiguncommand to create a weapon that is always firing.
function createMinigunWeapon() -- Create the weapon 1 meter above the player local x, y, z = getElementPosition(localPlayer) local weapon = createWeapon("minigun", x, y, z + 1) -- Give it some ammo and fire it setWeaponClipAmmo(weapon, 99999) setWeaponState(weapon, "firing")
-- Optionally adjust for model rotation (this value will be different for other weapons) setWeaponProperty(weapon, "fire_rotation", 0, -30, 0)endaddCommandHandler("createminigun", createMinigunWeapon)