All pastes #2017073 Raw Edit

knorkes explode-pieces thing

public lua v1 · immutable
#2017073 ·published 2010-12-12 05:06 UTC
rendered paste body
local pieces = {}--center pieces & aiming pieceslocal base = piece "base"local arm_r = piece "arm_r"local arm_l = piece "arm_l"local flare = piece "flare1"--other pieceslocal head = piece "head"local leg_r = piece "leg_r"local leg_l = piece "leg_l"local belly1 = piece "belly1" table.insert (pieces, belly1)local belly2 = piece "belly2" table.insert (pieces, belly2)local belly3 = piece "belly3" table.insert (pieces, belly3)local belly4 = piece "belly4" table.insert (pieces, belly4)local belly5 = piece "belly5" table.insert (pieces, belly5)local belly6 = piece "belly6" table.insert (pieces, belly6)local belly7 = piece "belly7" table.insert (pieces, belly7)local belly8 = piece "belly8" table.insert (pieces, belly8)local unblownpieces = pieceslocal unitDef = UnitDefs[Spring.GetUnitDefID(unitID)]local maxhealth = unitDef.healthlocal maxpieces = table.getn (pieces)local blowstepdamage = 10--maxhealth / maxpieceslocal blowdamage = 0local blownpieces = {}--signalslocal SIG_AIM = 2local SIG_WALK = 1local walking = false--local orc_machinegun_flash = SFX.CEG--local orc_machinegun_muzzle = SFX.CEG + 1local walkspeed = 30------react to enemy fire-----function script.HitByWeapon (x, z, weaponDefID, damage)	blowdamage = blowdamage + damage	if (blowdamage < blowstepdamage) then return end	blowdamage = 0		if (table.getn(unblownpieces) > 0) then		local exploID = math.random(table.getn(unblownpieces))		local explo = unblownpieces [exploID]		if (explo) then			--Spring.UnitScript.Explode (explo, SFX.SHATTER)			Spring.UnitScript.Explode (explo, SFX.EXPLODE)			Spring.UnitScript.Hide (explo)						table.remove (unblownpieces, exploID)			table.insert (blownpieces, explo)					end	endend--------------------------------AllowUnitBuildStep() --> "builderID, builderTeam, unitID, unitDefID, part" --end-------WALKING-----local function walk()	Signal(SIG_WALK)	SetSignalMask(SIG_WALK)			while (walking) do		Move (leg_r, z_axis, -5, walkspeed)		Move (leg_l, z_axis, 5, walkspeed)		Turn(arm_l, x_axis, math.rad(40), math.rad(80))		Turn(arm_r, x_axis, -math.rad(25), math.rad(40))		WaitForMove (leg_r, z_axis)		WaitForMove (leg_l, z_axis)		Sleep (20)		Move (leg_r, z_axis, 5, walkspeed)		Move (leg_l, z_axis, -5, walkspeed)		Turn(arm_l, x_axis, -math.rad(40), math.rad(80))		Turn(arm_r, x_axis, math.rad(25), math.rad(40))		WaitForMove (leg_r, z_axis)		WaitForMove (leg_l, z_axis)		Sleep (20)	endendlocal function stopwalk ()endfunction script.StartMoving()		walking = true	StartThread(walk)endfunction script.StopMoving()	walking = false	Signal(SIG_WALK)end-------------------------function script.Create()	--Spin(head, y_axis, 5)	--Spin(arm_r, x_axis, 5)endlocal function RestoreAfterDelay(unitID)	Sleep(1500)		Turn(arm_r, x_axis, 0, math.rad(50))	Turn(arm_l, x_axis, 0, math.rad(100))	Turn(base, y_axis, 0, math.rad(180))	Move (leg_r, z_axis, 0, walkspeed)	Move (leg_l, z_axis, 0, walkspeed)endfunction script.QueryWeapon1() return flare endfunction script.AimFromWeapon1() return base endfunction script.AimWeapon1( heading, pitch )	Signal(SIG_AIM)	SetSignalMask(SIG_AIM)		Turn(base, y_axis, heading, math.rad(360))		--if (math.deg(pitch) < 0) then pitch = 0 end		Turn(arm_r, x_axis, -pitch-math.rad(90), math.rad(180))		WaitForTurn(base, y_axis)		WaitForTurn(arm_r, x_axis)	StartThread(RestoreAfterDelay)	return trueendfunction script.FireWeapon1()--	EmitSfx(flare, orc_machinegun_flash)--	EmitSfx(flare, orc_machinegun_muzzle)	       	Sleep(30)endfunction script.EndBurst1 ( )	--Turn(arm_l, x_axis, 360, math.rad(720))endfunction script.Killed(recentDamage, maxHealth)	Sleep(30)end