GetProjectileTarget: Difference between revisions
Jump to navigation
Jump to search
(thePlayer is not defined) |
|||
(7 intermediate revisions by 5 users not shown) | |||
Line 7: | Line 7: | ||
element getProjectileTarget ( projectile theProjectile ) | element getProjectileTarget ( projectile theProjectile ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[projectile]]:getTarget|target}} | |||
==Required Arguments== | ===Required Arguments=== | ||
*'''theProjectile:''' The [[projectiles| projectile]] element which target you want to retrieve. | *'''theProjectile:''' The [[projectiles| projectile]] element which target you want to retrieve. | ||
==Returns== | ==Returns== | ||
Returns the element which is the projectile's target if the projectile is valid and a | Returns the [[element]] which is the projectile's target if the projectile is valid and can have a target (like a heat-seeking rocket), ''false'' otherwise. | ||
{{New feature/item|3.0141|1.4.0|6990|If the projectile is a satchel charge, returns the [[element]] at which it is glued to (or ''nil'' if it isn't glued to any).}} | |||
==Example== | ==Example== | ||
<syntaxhighlight lang="lua">function projectileCreating( | This example allows a player to send projectiles at other players. | ||
local x,y,z = getElementPosition( | |||
<syntaxhighlight lang="lua">function projectileCreating(command,targetPlayer) | |||
local x,y,z = getElementPosition(getLocalPlayer()) -- Get the position of the player | |||
local target = getPlayerFromName(targetPlayer) or nil -- Get the target, or set it to nil if no target specified | local target = getPlayerFromName(targetPlayer) or nil -- Get the target, or set it to nil if no target specified | ||
local theProjectile = createProjectile( | local theProjectile = createProjectile(getLocalPlayer(),20,x,y,z+50,1.0,target) | ||
outputChatBox("Created projectile's target: "..getProjectileTarget(theProjectile) | if (target) then | ||
outputChatBox("Created projectile's target: "..getPlayerName(getProjectileTarget(theProjectile))) | |||
else | |||
outputChatBox("Created projectile with no target") | |||
end | |||
end | end | ||
addCommandHandler("rocket",projectileCreating) -- Bind the 'rocket' command to projectileCreating function | addCommandHandler("rocket",projectileCreating) -- Bind the 'rocket' command to projectileCreating function | ||
Line 26: | Line 35: | ||
==See also== | ==See also== | ||
{{Client projectile functions}} | {{Client projectile functions}} | ||
[[ | |||
[[it:getProjectileTarget]] |
Latest revision as of 01:29, 10 September 2016
This function returns the target of the specified projectile.
Syntax
element getProjectileTarget ( projectile theProjectile )
OOP Syntax Help! I don't understand this!
- Method: projectile:getTarget(...)
- Variable: .target
Required Arguments
- theProjectile: The projectile element which target you want to retrieve.
Returns
Returns the element which is the projectile's target if the projectile is valid and can have a target (like a heat-seeking rocket), false otherwise.
If the projectile is a satchel charge, returns the element at which it is glued to (or nil if it isn't glued to any).
Example
This example allows a player to send projectiles at other players.
function projectileCreating(command,targetPlayer) local x,y,z = getElementPosition(getLocalPlayer()) -- Get the position of the player local target = getPlayerFromName(targetPlayer) or nil -- Get the target, or set it to nil if no target specified local theProjectile = createProjectile(getLocalPlayer(),20,x,y,z+50,1.0,target) if (target) then outputChatBox("Created projectile's target: "..getPlayerName(getProjectileTarget(theProjectile))) else outputChatBox("Created projectile with no target") end end addCommandHandler("rocket",projectileCreating) -- Bind the 'rocket' command to projectileCreating function