merge target practice patch by Wuzzy
authorsheepluva
Thu, 28 Apr 2016 21:28:22 +0200
changeset 11773 b58dd09ea950
parent 11771 abcdb7bc2620 (current diff)
parent 11772 c21278c4218d (diff)
child 11774 8b17caab10ec
merge target practice patch by Wuzzy
--- a/share/hedgewars/Data/Scripts/TargetPractice.lua	Thu Apr 28 21:15:08 2016 +0200
+++ b/share/hedgewars/Data/Scripts/TargetPractice.lua	Thu Apr 28 21:28:22 2016 +0200
@@ -150,12 +150,7 @@
 	end
 
 	_G.onNewTurn = function()
-		-- TODO: Remove the else branch when 0.9.21 has been released
-		if SetWeapon ~= nil then
-			SetWeapon(params.ammoType)
-		else
-			ParseCommand("/setweap "..string.char(params.ammoType))
-		end
+		SetWeapon(params.ammoType)
 	end
 
 	_G.spawnTarget = function()
@@ -165,6 +160,8 @@
 		y = targets[scored+1].y
 
 		SetGearPosition(gear, x, y)
+
+		return gear
 	end
 
 	_G.onGameTick20 = function()
@@ -229,6 +226,18 @@
 		end
 	end
 
+	_G.onGearDelete = function(gear)
+		if GetGearType(gear) == gtTarget and band(GetState(gear), gstDrowning) ~= 0 then
+			AddCaption(loc("You lost your target, try again!", 0xFFFFFFFF, capgrpGameState))
+			local newTarget = spawnTarget()
+			local x, y = GetGearPosition(newTarget)
+			local success = PlaceSprite(x, y + 24, sprAmGirder, 0, 0xFFFFFFFF, false, false, false)
+			if not success then
+				WriteLnToConsole("ERROR: Failed to spawn girder under respawned target!")
+			end
+		end
+	end
+
 	_G.generateStats = function()
 		local accuracy = (scored/shots)*100
 		local end_score_targets = scored * math.ceil(6000/#targets)
@@ -254,7 +263,7 @@
 			end
 			end_score_overall = end_score_targets
 		end
+		SendStat(siPointType, loc("point(s)"))
 		SendStat(siPlayerKills, tostring(end_score_overall), loc(params.teamName))
-		SendStat(siPointType, loc("points"))
 	end
 end