Last active
December 28, 2015 17:29
-
-
Save MasterEx/7536110 to your computer and use it in GitHub Desktop.
new Hedgewars mode, temporary name: Team5
This is a version for the Hedgewars 0.9.19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSTALL | |
Windows | |
Copy the two files (team5.lua and team5.cfg) to My Documents/Hedgewars/Data/Scripts/Multiplayer | |
Linux | |
Copy the two files (team5.lua and team5.cfg) to ~/.hedgewars/Data/Scripts/Multiplayer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
locked | |
locked |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--------------------- | |
-- VERSION FOR HEDGEWARS 0.9.19 | |
-- Team 5 | |
-- by Master_ex | |
--------------------- | |
-- About: | |
-- Each team has 5 hogs with the following weapons: desert eagle, bazooka, | |
-- grenade, fire punch and dynamite. | |
HedgewarsScriptLoad("/Scripts/Locale.lua") | |
local WIN_SCORE = 16 -- first to 16 wins | |
local MIN_SCORE = -8 | |
local VERSION = 192 | |
local RULES = loc("First to 16 points wins").."| |"..loc("Point list").."|".. | |
loc("Hit Ally -1 point").."|".. | |
loc("Shyryuken kill <Enemy,Ally,Same> +5,-5,0 points").."|".. | |
loc("Desert Eagle kill <Enemy,Ally,Same> +4,-4,0 points").."|".. | |
loc("Bazooka kill <Enemy,Ally,Same> +3,-3,0 points").."|".. | |
loc("Grenade kill <Enemy,Ally,Same> +2,-2,0 points").."|".. | |
loc("Dynamite kill <Enemy,Ally,Same> +1,-1,0 points") | |
local rulesShown = false | |
local gameEnded = false | |
local teams = {} | |
local hedgehogs = {} | |
local teamScheme = { | |
{name = "Shyryuken", type = amFirePunch, points = 5}, | |
{name = "Desert Eagle", type = amDEagle, points = 4}, | |
{name = "Bazooka" , type = amBazooka, points = 3}, | |
{name = "Grenade" , type = amGrenade, points = 2}, | |
{name = "Dynamite" , type = amDynamite, points = 1} | |
} | |
local weapArray = { amClusterBomb, amBazooka, amBee, amShotgun, amPickHammer, | |
amRope, amMine, amWhip, | |
amBaseballBat, amParachute, amAirAttack, amMineStrike, amBlowTorch, | |
amGirder, amTeleport, amSwitch, amMortar, amKamikaze, amCake, | |
amSeduction, amWatermelon, amHellishBomb, amNapalm, amDrill, amBallgun, | |
amRCPlane, amLowGravity, amExtraDamage, amInvulnerable, amExtraTime, | |
amLaserSight, amVampiric, amSniperRifle, amJetpack, amMolotov, amBirdy, amPortalGun, | |
amPiano, amGasBomb, amSineGun, amFlamethrower, amSMine, amHammer, | |
amResurrector, amDrillStrike, amSnowball, amTardis, amLandGun, amIceGun, amKnife } | |
local utilArray = { amRope, amLandGun, amJetpack, amGirder, amParachute, amInvulnerable } | |
---- Core Functions ---- | |
function onGameInit() | |
TurnTime = 25000 | |
SuddenDeathTurns = 1000 | |
WaterRise = 0 | |
CaseFreq = 0 | |
end | |
function onGameStart() | |
WriteLnToConsole("TEAM 5 version "..VERSION) | |
quickCheckHogNumber() | |
if not gameEnded then | |
setTeams() | |
checkHogNumber() | |
removeWeapons() | |
end | |
ShowMission(loc("Team 5 Rules"), | |
loc("shoot the right hog!"), | |
RULES, 0, 5000) | |
end | |
function onGameTick20() | |
checkForWin() | |
end | |
function onGearAdd(gear) | |
if GetGearType(gear) == gtHedgehog then | |
local hedgehog = {} | |
hedgehog.gid = gear | |
SetEffect(gear, heResurrectable, 1) | |
table.insert(hedgehogs, hedgehog) | |
end | |
end | |
function onNewTurn() | |
removeHogWeapons(CurrentHedgehog) | |
teamResetRoundDamage() | |
setScores() | |
for i=1, #utilArray do | |
AddAmmo(CurrentHedgehog, utilArray[i], 0) | |
end | |
AddAmmo(CurrentHedgehog, utilArray[1 + GetRandom(#utilArray)], 1) | |
local hog = getHog(CurrentHedgehog) | |
for i=1, #teamScheme do | |
AddAmmo(CurrentHedgehog, teams[hog.tid].teamScheme[i].type, 0) | |
if teams[hog.tid].teamScheme[i].name == GetHogName(CurrentHedgehog) then | |
AddAmmo(CurrentHedgehog, teams[hog.tid].teamScheme[i].type, 100) | |
end | |
end | |
AddAmmo(CurrentHedgehog, amSkip, 100) | |
end | |
function onGearResurrect(gear) | |
if GetGearType(gear) == gtHedgehog then | |
local shooterTeam = GetHogTeamName(CurrentHedgehog) | |
local victimTeam = GetHogTeamName(gear) | |
local points = 0 | |
local victimHog = getHog(gear) | |
local shooterHog = getHog(CurrentHedgehog) | |
for i=1, #teamScheme do | |
if GetHogName(CurrentHedgehog) == teams[shooterHog.tid].teamScheme[i].name then | |
points = teams[shooterHog.tid].teamScheme[i].points | |
break | |
end | |
end | |
-- this can be optimized with the new tid field | |
if (GetHogName(victimHog.gid) ~= GetHogName(shooterHog.gid)) or | |
(victimHog.tid == shooterHog.tid) then | |
if shooterTeam == victimTeam then | |
-- killing a comrade is pretty low | |
local p = 0 | |
if points * 2 - victimHog.roundScoreDamage >= 0 then | |
p = points * 2 - victimHog.roundScoreDamage | |
victimHog.roundScoreDamage = 0 | |
local score = teams[shooterHog.tid].score - p | |
if score < MIN_SCORE then | |
score = MIN_SCORE | |
p = MIN_SCORE - score | |
end | |
teams[shooterHog.tid].score = score | |
AddCaption(teams[shooterHog.tid].name.." "..loc("team lost").." "..p.." "..loc("points")) | |
end | |
else | |
teams[shooterHog.tid].score = teams[shooterHog.tid].score + points | |
AddCaption(teams[shooterHog.tid].name.." "..loc("team won").." "..points.." "..loc("points")) | |
end | |
end | |
end | |
end | |
function onGearDamage(gear, damage) | |
if GetGearType(gear) == gtHedgehog then | |
local victimHog = getHog(gear) | |
local shooterHog = getHog(CurrentHedgehog) | |
if victimHog.tid == shooterHog.tid then | |
-- shooting a comrade reduces score per 1 | |
if teams[shooterHog.tid].score ~= MIN_SCORE then | |
teams[shooterHog.tid].score = teams[shooterHog.tid].score - 1 | |
AddCaption(teams[shooterHog.tid].name.." "..loc("team lost 1 point")) | |
-- keep track of the damage taken in this round | |
victimHog.roundScoreDamage = victimHog.roundScoreDamage + 1 | |
end | |
end | |
end | |
end | |
---- Other Functions ---- | |
function setTeams() | |
for hog=1 , #hedgehogs do | |
local namei = 1 | |
local hedgehog = hedgehogs[hog] | |
hedgehog.team = GetHogTeamName(hedgehogs[hog].gid) | |
if teams == nil then | |
teams[1].name = hedgehog.team | |
teams[1].hogs = 1 | |
teams[1].score = 0 | |
teams[1].teamScheme = shuffle(teamScheme) | |
hedgehog.tid = 1 | |
else | |
local found = false | |
for ti=1, #teams do | |
if teams[ti].name == hedgehog.team then | |
teams[ti].hogs = teams[ti].hogs + 1 | |
namei = teams[ti].hogs | |
found = true | |
break | |
end | |
end | |
if not found then | |
local team = {} | |
team.name = hedgehog.team | |
team.hogs = 1 | |
team.score = 0 | |
team.teamScheme = shuffle(teamScheme) | |
table.insert(teams,team) | |
end | |
end | |
hedgehog.tid = #teams | |
if teams[#teams].teamScheme[namei] ~= nil then | |
SetHogName(hedgehog.gid, teams[#teams].teamScheme[namei].name) | |
end | |
end | |
end | |
function checkHogNumber() | |
for i=1, #teams do | |
if teams[i].hogs ~= 5 then | |
WriteLnToConsole("[checkHogNumber] Number of hogs is't 5. Ending game.") | |
endStats() | |
EndGame() | |
break | |
end | |
end | |
end | |
function quickCheckHogNumber() | |
if #hedgehogs / TeamsCount ~= 5 then | |
WriteLnToConsole("[quickCheckHogNumber] Number of hogs is't 5. Ending game.") | |
gameEnded = true | |
endStats() | |
EndGame() | |
end | |
end | |
function removeWeapons() | |
local hog = 0 | |
for t=1, #teams do | |
hog = hog + teams[t].hogs | |
for i=1, #weapArray do | |
AddAmmo(hedgehogs[hog].gid, weapArray[i], 0) | |
end | |
end | |
end | |
function removeHogWeapons(gear) | |
for i=1, #weapArray do | |
AddAmmo(gear, weapArray[i], 0) | |
end | |
end | |
function setScores() | |
local scoreMessage = loc("Score is")..": |" | |
for i=1, #teams do | |
scoreMessage = scoreMessage .. teams[i].name .. " [" .. teams[i].score .. "]|" | |
end | |
if rulesShown then | |
ShowMission(loc("Team5"), | |
loc("kill the right hogs first"), | |
scoreMessage, 0, 1500) | |
else | |
rulesShown = true | |
end | |
end | |
function checkForWin() | |
local winner | |
local win = false | |
for i=1, #teams do | |
if teams[i].score >= WIN_SCORE then | |
if win == false then | |
winner = i | |
win = true | |
elseif teams[winner].score < teams[i].score then | |
winner = i | |
elseif teams[winner].score == teams[i].score then | |
win = false | |
end | |
end | |
end | |
if win then | |
WriteLnToConsole("Winner is "..teams[winner].name) | |
sendWinStats(winner) | |
EndGame() | |
elseif winner ~= nil then | |
WIN_SCORE = teams[winner].score + 1 | |
end | |
end | |
function shuffle(ar) | |
local max = #ar | |
local order = {} | |
for i=1, max do | |
table.insert(order, i) | |
end | |
local newOrder = {} | |
for i=1, max do | |
table.insert(newOrder, table.remove(order, 1 + GetRandom(#order))) | |
end | |
local newAr = {} | |
for i=1, #ar do | |
newAr[i] = ar[newOrder[i]] | |
end | |
return newAr | |
end | |
function getHog(gear) | |
local hog | |
for i=1, #hedgehogs do | |
if hedgehogs[i].gid == gear then | |
hog = hedgehogs[i] | |
break | |
end | |
end | |
return hog | |
end | |
function sendWinStats(winner) | |
if not gameEnded then | |
gameEnded = true | |
table.sort(teams,compare) | |
for i=1, #teams do | |
if teams[i].score==1 then | |
else | |
end | |
end | |
end | |
end | |
function endStats() | |
end | |
function teamResetRoundDamage() | |
for i=1, #hedgehogs do | |
hedgehogs[i].roundScoreDamage = 0 | |
end | |
end | |
function compare(a,b) | |
return a.score > b.score | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment