share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua
changeset 13115 64d84011a48e
parent 13114 c3fc9157f740
child 13630 fe7d2bbf5f3f
equal deleted inserted replaced
13114:c3fc9157f740 13115:64d84011a48e
    98 local numhhs = 0 -- store number of hedgehogs
    98 local numhhs = 0 -- store number of hedgehogs
    99 local hhs = {} -- store hedgehog gears
    99 local hhs = {} -- store hedgehog gears
   100 
   100 
   101 local teamSize = {}	-- store how many hogs per team
   101 local teamSize = {}	-- store how many hogs per team
   102 local teamIndex = {} -- at what point in the hhs{} does each team begin
   102 local teamIndex = {} -- at what point in the hhs{} does each team begin
       
   103 
       
   104 local mostCapturesHogName = nil -- name of hog who holds the record of most flags captured
       
   105 local mostCapturesHogTeam = nil -- name of team who holds the record of most flags captured
       
   106 local mostCaptures = 0 -- number of most per-hog captures
       
   107 local capturesPerHog = {}
   103 
   108 
   104 -------------------
   109 -------------------
   105 -- flag variables
   110 -- flag variables
   106 -------------------
   111 -------------------
   107 
   112 
   167 
   172 
   168 		for i=1, #teamList do
   173 		for i=1, #teamList do
   169 			SendStat(siPointType, loc("point(s)"))
   174 			SendStat(siPointType, loc("point(s)"))
   170 			SendStat(siPlayerKills, tostring(teamList[i].score), teamList[i].name)
   175 			SendStat(siPlayerKills, tostring(teamList[i].score), teamList[i].name)
   171 		end
   176 		end
       
   177 
       
   178 		if mostCaptures >= 2 then
       
   179 			SendStat(siCustomAchievement, string.format(loc("%s (%s) has captured the flag %d times."), mostCapturesHogName, mostCapturesHogTeam, mostCaptures))
       
   180 		end
   172 	end
   181 	end
   173 
   182 
   174 end
   183 end
   175 
   184 
   176 function DoFlagStuff(flag, flagClan)
   185 function DoFlagStuff(flag, flagClan)
   196 		AddCaption(string.format(loc("%s has scored!"), GetHogName(CurrentHedgehog)), 0xFFFFFFFF, capgrpGameState)
   205 		AddCaption(string.format(loc("%s has scored!"), GetHogName(CurrentHedgehog)), 0xFFFFFFFF, capgrpGameState)
   197 		updateScores()
   206 		updateScores()
   198 		PlaySound(sndHomerun)
   207 		PlaySound(sndHomerun)
   199 		fThief[thiefClan] = nil -- player no longer has the enemy flag
   208 		fThief[thiefClan] = nil -- player no longer has the enemy flag
   200 		fThiefFlag[flagClan] = nil
   209 		fThiefFlag[flagClan] = nil
       
   210 
       
   211 		capturesPerHog[CurrentHedgehog] = capturesPerHog[CurrentHedgehog] + 1
       
   212 		if capturesPerHog[CurrentHedgehog] > mostCaptures then
       
   213 			mostCaptures = capturesPerHog[CurrentHedgehog]
       
   214 			mostCapturesHogName = GetHogName(CurrentHedgehog)
       
   215 			mostCapturesHogTeam = GetHogTeamName(CurrentHedgehog)
       
   216 		end
       
   217 
   201 		CheckScore(flagClan)
   218 		CheckScore(flagClan)
   202 
   219 
   203 	--if the player is returning the flag
   220 	--if the player is returning the flag
   204 	elseif (GetHogClan(CurrentHedgehog) == flagClan) and (fIsMissing[flagClan] == true) then
   221 	elseif (GetHogClan(CurrentHedgehog) == flagClan) and (fIsMissing[flagClan] == true) then
   205 
   222 
   594 
   611 
   595 function onGearAdd(gear)
   612 function onGearAdd(gear)
   596 
   613 
   597 	if GetGearType(gear) == gtHedgehog then
   614 	if GetGearType(gear) == gtHedgehog then
   598 		hhs[numhhs] = gear
   615 		hhs[numhhs] = gear
       
   616 		capturesPerHog[gear] = 0
   599 		numhhs = numhhs + 1
   617 		numhhs = numhhs + 1
   600 		SetEffect(gear, heResurrectable, 1)
   618 		SetEffect(gear, heResurrectable, 1)
   601 
   619 
   602 	elseif GetGearType(gear) == gtPiano then
   620 	elseif GetGearType(gear) == gtPiano then
   603 		for i = 0, ClansCount-1 do
   621 		for i = 0, ClansCount-1 do