CreateWeapon

From Multi Theft Auto: Wiki
Revision as of 12:40, 15 December 2015 by NOki (talk | contribs) (→‎Returns)
Jump to navigation Jump to search

Creates a custom weapon that can fire bullets. Do not confuse this with player held weapons.

[[{{{image}}}|link=|]] 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.

Syntax

weapon createWeapon ( string theType, float x, float y, float z )

OOP Syntax Help! I don't understand this!

Method: Weapon(...)


Required Arguments

  • theType: The weapon type which can be:
  • colt 45
  • silenced
  • deagle
  • uzi
  • mp5
  • ak-47
  • m4
  • tec-9
  • rifle
  • sniper
  • minigun

Other weapons can be used but they can't fire. Use createProjectile for projectile based weapons.

  • x: The x position to create the weapon.
  • y: The y position to create the weapon.
  • z: The z position to create the weapon.

Returns

Returns a custom weapon element, which represents a weapon floating at that position.

Requirements

Minimum server version n/a
Minimum client version 1.3.0-9.04555

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.3.0-9.04555" />

Example

This example adds a /createminigun command to create a weapon that is always firing.

function createMinigunWeapon()
    -- Create the weapon 1 meter above the player
    local x, y, z = getElementPosition(getLocalPlayer())
    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)
end
addCommandHandler("createminigun", createMinigunWeapon)

See also