CreateWeapon: Difference between revisions
Jump to navigation
Jump to search
m (→Examples: No point of the section as it's already a client function) |
Fernando187 (talk | contribs) (Remove obsolete Requirements section) |
||
(5 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{Needs_Checking|"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.}} | __NOTOC__<!--{{Needs_Checking|"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.}}--> | ||
{{Client function}} | {{Client function}} | ||
Creates a custom weapon that can fire bullets not | Creates a [[Element/Weapon|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.}} | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">weapon createWeapon ( string theType, float x, float y, float z )</syntaxhighlight> | <syntaxhighlight lang="lua">weapon createWeapon ( string theType, float x, float y, float z )</syntaxhighlight> | ||
{{OOP||[[Element/Weapon|Weapon]]}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
Line 17: | Line 17: | ||
===Returns=== | ===Returns=== | ||
Returns a custom weapon | Returns a [[Element/Weapon|custom weapon]] element, which represents a weapon floating at that position. | ||
== | ==Example== | ||
This example adds a ''/createminigun'' command to create a weapon that is always firing. | |||
''' | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function createMinigunWeapon() | function createMinigunWeapon() | ||
local x, y, z = getElementPosition( | -- Create the weapon 1 meter above the player | ||
local x, y, z = getElementPosition(localPlayer) | |||
local weapon = createWeapon("minigun", x, y, z + 1) | local weapon = createWeapon("minigun", x, y, z + 1) | ||
setWeaponClipAmmo ( weapon,99999) | -- Give it some ammo and fire it | ||
setWeaponState ( weapon,"firing") | 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 | end | ||
addCommandHandler("createminigun", createMinigunWeapon) | addCommandHandler("createminigun", createMinigunWeapon) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See | ==See also== | ||
{{Client weapon creation functions}} | {{Client weapon creation functions}} | ||
[[ru:createWeapon]] | [[ru:createWeapon]] |
Latest revision as of 17:07, 7 November 2024
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. |
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.
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(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) end addCommandHandler("createminigun", createMinigunWeapon)