SetWeaponTarget: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Added OOP syntax and improved the page) |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Client function}} | {{Client function}} | ||
This function sets the target of a [[Element/Weapon|custom weapon]]. There are 3 different targeting modes, which are explained below. | |||
==Syntax== | {{Note|[[Element/Weapon|Custom weapons]] target its target (assigned by this function) with no recoil. If you want a custom weapon to take into account recoil, you will have to script it by firing at a fixed coordinates.}} | ||
<syntaxhighlight lang="lua">bool setWeaponTarget ( weapon theWeapon, element theTarget, int | |||
{{OOP|Variable is read only.|[[Element/Weapon|weapon]]:setTarget|target|getWeaponTarget}} | |||
==Syntax (target an entity)== | |||
<syntaxhighlight lang="lua">bool setWeaponTarget ( weapon theWeapon, element theTarget, int theComponent )</syntaxhighlight> | |||
===Required Arguments=== | ===Required Arguments=== | ||
* '''theWeapon:''' The weapon to set the target of. | * '''theWeapon:''' The weapon to set the target of. | ||
* '''theTarget:''' The target entity of the shot to shoot at. | * '''theTarget:''' The target entity of the shot to shoot at. | ||
* ''' | * '''theComponent:''' The component of the target to shoot at: | ||
** Vehicles: | ** Vehicles: | ||
*** 0 | *** '''0''': front left tire. | ||
*** 1 | *** '''1''': front right tire. | ||
*** 2 | *** '''2''': rear left tire. | ||
*** 3 | *** '''3''': rear right tire. | ||
*** 255 | *** '''255''': center of the car (position returned by [[getElementPosition]]). | ||
** Peds: | ** Peds only (see [[getPedBonePosition]] to know where is located each bone): | ||
*** | ***'''1:''' shoots at ''BONE_PELVIS1''. | ||
*** 255 | ***'''2:''' shoots at ''BONE_PELVIS''. | ||
***'''3:''' shoots at ''BONE_SPINE1''. | |||
***'''4:''' shoots at ''BONE_UPPERTORSO''. | |||
***'''5:''' shoots at ''BONE_NECK''. | |||
***'''6:''' shoots at ''BONE_HEAD2''. | |||
***'''7:''' shoots at ''BONE_HEAD1''. | |||
***'''8:''' shoots at ''BONE_HEAD''. | |||
***'''21:''' shoots at ''BONE_RIGHTUPPERTORSO''. | |||
***'''22:''' shoots at ''BONE_RIGHTSHOULDER''. | |||
***'''23:''' shoots at ''BONE_RIGHTELBOW''. | |||
***'''24:''' shoots at ''BONE_RIGHTWRIST''. | |||
***'''25:''' shoots at ''BONE_RIGHTHAND''. | |||
***'''26:''' shoots at ''BONE_RIGHTTHUMB''. | |||
***'''31:''' shoots at ''BONE_LEFTUPPERTORSO''. | |||
***'''32:''' shoots at ''BONE_LEFTSHOULDER''. | |||
***'''33:''' shoots at ''BONE_LEFTELBOW''. | |||
***'''34:''' shoots at ''BONE_LEFTWRIST''. | |||
***'''35:''' shoots at ''BONE_LEFTHAND''. | |||
***'''36:''' shoots at ''BONE_LEFTTHUMB''. | |||
***'''41:''' shoots at ''BONE_LEFTHIP''. | |||
***'''42:''' shoots at ''BONE_LEFTKNEE''. | |||
***'''43:''' shoots at ''BONE_LEFTANKLE''. | |||
***'''44:''' shoots at ''BONE_LEFTFOOT''. | |||
***'''51:''' shoots at ''BONE_RIGHTHIP''. | |||
***'''52:''' shoots at ''BONE_RIGHTKNEE''. | |||
***'''53:''' shoots at ''BONE_RIGHTANKLE''. | |||
***'''54:''' shoots at ''BONE_RIGHTFOOT''. | |||
*** '''255''': shoots at the center of the ped (position returned by [[getElementPosition]]). | |||
===Returns=== | ===Returns=== | ||
Returns ''true'' on success, ''false'' otherwise. | Returns ''true'' on success, ''false'' otherwise. | ||
==Syntax (target a position)== | |||
Fires the weapon at the specified position. | |||
==Syntax | |||
Fires | |||
<syntaxhighlight lang="lua">bool setWeaponTarget ( weapon theWeapon, float targetX, float targetY, float targetZ )</syntaxhighlight> | <syntaxhighlight lang="lua">bool setWeaponTarget ( weapon theWeapon, float targetX, float targetY, float targetZ )</syntaxhighlight> | ||
Line 43: | Line 67: | ||
Returns ''true'' on success, ''false'' otherwise. | Returns ''true'' on success, ''false'' otherwise. | ||
==Syntax | ==Syntax (rotational target)== | ||
Sets the weapon back to rotation based targeting. | Sets the weapon back to rotation based targeting. | ||
Line 53: | Line 77: | ||
===Returns=== | ===Returns=== | ||
Returns ''true'' on success, ''false'' otherwise. | Returns ''true'' on success, ''false'' otherwise. | ||
==Requirements== | ==Requirements== | ||
{{Requirements|n/a|1.3.0-9.04555|}} | {{Requirements|n/a|1.3.0-9.04555|}} | ||
==See | ==See also== | ||
{{Client weapon creation functions}} | {{Client weapon creation functions}} |
Revision as of 17:10, 23 December 2014
This function sets the target of a custom weapon. There are 3 different targeting modes, which are explained below.
OOP Syntax Help! I don't understand this!
- Note: Variable is read only.
- Method: weapon:setTarget(...)
- Variable: .target
- Counterpart: getWeaponTarget
Syntax (target an entity)
bool setWeaponTarget ( weapon theWeapon, element theTarget, int theComponent )
Required Arguments
- theWeapon: The weapon to set the target of.
- theTarget: The target entity of the shot to shoot at.
- theComponent: The component of the target to shoot at:
- Vehicles:
- 0: front left tire.
- 1: front right tire.
- 2: rear left tire.
- 3: rear right tire.
- 255: center of the car (position returned by getElementPosition).
- Peds only (see getPedBonePosition to know where is located each bone):
- 1: shoots at BONE_PELVIS1.
- 2: shoots at BONE_PELVIS.
- 3: shoots at BONE_SPINE1.
- 4: shoots at BONE_UPPERTORSO.
- 5: shoots at BONE_NECK.
- 6: shoots at BONE_HEAD2.
- 7: shoots at BONE_HEAD1.
- 8: shoots at BONE_HEAD.
- 21: shoots at BONE_RIGHTUPPERTORSO.
- 22: shoots at BONE_RIGHTSHOULDER.
- 23: shoots at BONE_RIGHTELBOW.
- 24: shoots at BONE_RIGHTWRIST.
- 25: shoots at BONE_RIGHTHAND.
- 26: shoots at BONE_RIGHTTHUMB.
- 31: shoots at BONE_LEFTUPPERTORSO.
- 32: shoots at BONE_LEFTSHOULDER.
- 33: shoots at BONE_LEFTELBOW.
- 34: shoots at BONE_LEFTWRIST.
- 35: shoots at BONE_LEFTHAND.
- 36: shoots at BONE_LEFTTHUMB.
- 41: shoots at BONE_LEFTHIP.
- 42: shoots at BONE_LEFTKNEE.
- 43: shoots at BONE_LEFTANKLE.
- 44: shoots at BONE_LEFTFOOT.
- 51: shoots at BONE_RIGHTHIP.
- 52: shoots at BONE_RIGHTKNEE.
- 53: shoots at BONE_RIGHTANKLE.
- 54: shoots at BONE_RIGHTFOOT.
- 255: shoots at the center of the ped (position returned by getElementPosition).
- Vehicles:
Returns
Returns true on success, false otherwise.
Syntax (target a position)
Fires the weapon at the specified position.
bool setWeaponTarget ( weapon theWeapon, float targetX, float targetY, float targetZ )
Required Arguments
- theWeapon: The weapon to set the target of.
- targetX: The target X.
- targetY: The target Y.
- targetZ: The target Z.
Returns
Returns true on success, false otherwise.
Syntax (rotational target)
Sets the weapon back to rotation based targeting.
bool bool setWeaponTarget ( weapon theWeapon, nil )
Required Arguments
- theWeapon: The weapon to clear the target of.
Returns
Returns true on success, false otherwise.
Requirements
This template will be deleted.
See also
- createWeapon
- fireWeapon
- getWeaponAmmo
- getWeaponClipAmmo
- getWeaponFiringRate
- getWeaponFlags
- getWeaponOwner
- getWeaponProperty
- getWeaponState
- getWeaponTarget
- resetWeaponFiringRate
- setWeaponAmmo
- setWeaponClipAmmo
- setWeaponFiringRate
- setWeaponFlags
- setWeaponProperty
- setWeaponState
- setWeaponTarget