1
-- Random Weapons, example for gameplay scripts
3
-- Load the library for localisation ("loc" function)
1
4
loadfile(GetDataPath() .. "Scripts/Locale.lua")()
6
-- Load the gear tracker
7
loadfile(GetDataPath() .. "Scripts/Tracker.lua")()
9
-- List of available weapons
3
10
local weapons = { amGrenade, amClusterBomb, amBazooka, amBee, amShotgun,
4
11
amMine, amDEagle, amDynamite, amFirePunch, amWhip, amPickHammer,
5
12
amBaseballBat, amTeleport, amMortar, amCake, amSeduction,
6
13
amWatermelon, amHellishBomb, amDrill, amBallgun, amRCPlane,
7
14
amSniperRifle, amMolotov, amBirdy, amBlowTorch, amGasBomb,
8
amFlamethrower, amSMine, amHammer, amSnowball }
15
amFlamethrower, amSMine, amHammer }
17
-- List of weapons that attack from the air
10
18
local airweapons = { amAirAttack, amMineStrike, amNapalm, amDrillStrike }
20
-- Function that assigns the team their weapon
21
function assignAmmo(hog)
22
-- Get name of the current team
23
local name = GetHogTeamName(hog)
24
-- Get whither the team has been processed
25
local processed = getTeamValue(name, "processed")
26
-- If it has not, process it
27
if processed == nil or not processed then
28
-- Get the ammo for this hog's team
29
local ammo = getTeamValue(name, "ammo")
30
-- If there is no ammo, get a random one from the list and store it
32
ammo = weapons[GetRandom(table.maxn(weapons)) + 1]
33
setTeamValue(name, "ammo", ammo)
35
-- Add the ammo for the hog
38
setTeamValue(name, "processed", true)
42
-- Mark team as not processed
44
setTeamValue(GetHogTeamName(hog), "processed", false)
13
47
function onGameInit()
14
GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack + gfPerHogAmmo))
48
-- Limit flags that can be set, but allow game schemes to be used
49
GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack))
50
-- Set a custom game goal that will show together with the scheme ones
51
Goals = loc("Each turn you get one random weapon")
17
54
function onGameStart()
55
-- Initialize the tracking of hogs and teams
57
-- Add air weapons to the game if the border is not active
18
58
if MapHasBorder() == false then
19
59
for i, w in pairs(airweapons) do
20
60
table.insert(weapons, w)
24
ShowMission(loc("Random Weapons"), loc("A game of luck"), loc("There has been a mix-up with your gear and now you|have to utilize whatever is coming your way!"), -amSkip, 0)
27
65
function onAmmoStoreInit()
66
-- Allow skip at all times
28
67
SetAmmo(amSkip, 9, 0, 0, 0)
69
-- Let utilities be available through crates
30
70
SetAmmo(amParachute, 0, 1, 0, 1)
31
71
SetAmmo(amGirder, 0, 1, 0, 2)
32
72
SetAmmo(amSwitch, 0, 1, 0, 1)
40
80
SetAmmo(amPortalGun, 0, 1, 0, 1)
41
81
SetAmmo(amResurrector, 0, 1, 0, 1)
83
-- Allow weapons to be used
43
84
for i, w in pairs(weapons) do
44
85
SetAmmo(w, 0, 0, 0, 1)
88
-- Allow air weapons to be used
47
89
for i, w in pairs(airweapons) do
48
90
SetAmmo(w, 0, 0, 0, 1)
52
94
function onNewTurn()
53
AddAmmo(CurrentHedgehog, weapons[GetRandom(table.maxn(weapons)) + 1])
95
-- Give every team their weapons, so one can plan during anothers turn
96
runOnGears(assignAmmo)
97
-- Mark all teams as not processed
99
-- Set the current teams weapons to nil so they will get new after the turn has ended
100
setTeamValue(GetHogTeamName(CurrentHedgehog), "ammo", nil)
103
function onGearAdd(gear)
104
-- Catch hedgehogs for the tracker
105
if GetGearType(gear) == gtHedgehog then
110
function onGearDelete(gear)
111
-- Remove hogs that are gone