CreateWeapon: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (→‎Examples: No point of the section as it's already a client function)
No edit summary
Line 3: Line 3:
{{Client function}}
{{Client function}}
Creates a custom weapon that can fire bullets not related to player held weapons.
Creates a custom weapon that can fire bullets not related to player held weapons.
'''Note:''' Some weapon types do not work.
{{Tip|Some models such a minigun point in a slightly different direction to where they fire. To adjust for this, use [[setWeaponProperty]] with 'fire_rotation'. See example below.}}


==Syntax==
==Syntax==
Line 30: Line 30:
     setWeaponClipAmmo ( weapon,99999)
     setWeaponClipAmmo ( weapon,99999)
     setWeaponState ( weapon,"firing")
     setWeaponState ( weapon,"firing")
    -- Optionally adjust for model rotation (This value will be different for other weapons)
    setWeaponProperty( weapon, "fire_rotation", 0, -30, 0 );
end
end
addCommandHandler("createminigun", createMinigunWeapon)
addCommandHandler("createminigun", createMinigunWeapon)

Revision as of 04:40, 20 July 2014

Dialog-information.png This article needs checking.

Reason(s): "Some weapon types do not work."... needs investigating. Shotguns do not work because the pellet code was complex and its actually 8 very clustered pellets. All other bullet weapons should work and be synced. Exact weapons this works with needs documenting still.

Creates a custom weapon that can fire bullets not related to player held weapons.

[[{{{image}}}|link=|]] Tip: Some models such a minigun point in a slightly different direction to where they fire. To adjust for this, use setWeaponProperty with 'fire_rotation'. See example below.

Syntax

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

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 type and creates a simulated weapon 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" />

Examples

Example 1: This example create weapon and firing.

function createMinigunWeapon()
    local x, y, z = getElementPosition(getLocalPlayer())
    local weapon = createWeapon("minigun", x, y, z + 1)
    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