GetUnitLastAttackedPiece

GetUnitLastAttackedPiece

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
9heart
Posts: 55
Joined: 16 Sep 2010, 16:14

GetUnitLastAttackedPiece

Post by 9heart »

Hi

Code: Select all

function script.HitByWeapon(x,z,weaponDef,damage)
	local hitPiece = Spring.GetUnitLastAttackedPiece(unitID) or ""
     Spring.echo(hitPiece) -- base,turret,etc
    Explode(hitPiece, SFX.EXPLODE)
give error: bad argument #1 to 'Explode' (number expected, got string)

halp
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: GetUnitLastAttackedPiece

Post by jK »

9heart wrote:or ""
is wrong

Also "(number expected, got string)" says that very specific.
9heart
Posts: 55
Joined: 16 Sep 2010, 16:14

Re: GetUnitLastAttackedPiece

Post by 9heart »

jK wrote:
9heart wrote:or ""
is wrong

Also "(number expected, got string)" says that very specific.

i see other units in mods using Explode(pieceName, type) and they are always passing a string (body, turret,etc) as argument. unless there is some trickery that convert piecename into piecenumber?
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: GetUnitLastAttackedPiece

Post by smoth »

They are not strings pieces are numbers bro.
9heart
Posts: 55
Joined: 16 Sep 2010, 16:14

Re: GetUnitLastAttackedPiece

Post by 9heart »

smoth wrote:They are not strings pieces are numbers bro.

Spring.GetUnitLastAttackedPiece
( number unitID ) -> nil | string pieceName, number gameframe

local base = piece "base"
local body = piece "body"
local turret = piece "turret"
local gun = piece "gun"
local flare = piece "flare"

someone explain how "flare" is evaluated as number?
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: GetUnitLastAttackedPiece

Post by smoth »

= piece "flare"

Returns the piece number

It is really piece("flare)
9heart
Posts: 55
Joined: 16 Sep 2010, 16:14

Re: GetUnitLastAttackedPiece

Post by 9heart »

ok thanks.
Last edited by 9heart on 07 Mar 2014, 10:58, edited 1 time in total.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: GetUnitLastAttackedPiece

Post by smoth »

Loaded question

Efficiency depends on use.

Get over using tables it is not that big deal
Post Reply

Return to “Game Development”