7568
|
1 |
-- Random Weapons, example for gameplay scripts
|
|
2 |
|
|
3 |
-- Load the library for localisation ("loc" function)
|
|
4 |
loadfile(GetDataPath() .. "Scripts/Locale.lua")()
|
|
5 |
|
|
6 |
-- Load the gear tracker
|
|
7 |
loadfile(GetDataPath() .. "Scripts/Tracker.lua")()
|
|
8 |
|
|
9 |
-- List of available weapons
|
|
10 |
local weapons = { amGrenade, amClusterBomb, amBazooka, amBee, amShotgun,
|
|
11 |
amMine, amDEagle, amDynamite, amFirePunch, amWhip, amPickHammer,
|
|
12 |
amBaseballBat, amTeleport, amMortar, amCake, amSeduction,
|
|
13 |
amWatermelon, amHellishBomb, amDrill, amBallgun, amRCPlane,
|
|
14 |
amSniperRifle, amMolotov, amBirdy, amBlowTorch, amGasBomb,
|
|
15 |
amFlamethrower, amSMine, amHammer }
|
|
16 |
|
|
17 |
-- List of weapons that attack from the air
|
|
18 |
local airweapons = { amAirAttack, amMineStrike, amNapalm, amDrillStrike }
|
|
19 |
|
|
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
|
|
31 |
if ammo == nil then
|
|
32 |
ammo = weapons[GetRandom(table.maxn(weapons)) + 1]
|
|
33 |
setTeamValue(name, "ammo", ammo)
|
|
34 |
end
|
|
35 |
-- Add the ammo for the hog
|
|
36 |
AddAmmo(hog, ammo)
|
|
37 |
-- Mark as processed
|
|
38 |
setTeamValue(name, "processed", true)
|
|
39 |
end
|
|
40 |
end
|
|
41 |
|
|
42 |
-- Mark team as not processed
|
|
43 |
function reset(hog)
|
|
44 |
setTeamValue(GetHogTeamName(hog), "processed", false)
|
|
45 |
end
|
|
46 |
|
|
47 |
function onGameInit()
|
|
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")
|
|
52 |
end
|
|
53 |
|
|
54 |
function onGameStart()
|
|
55 |
-- Initialize the tracking of hogs and teams
|
|
56 |
trackTeams()
|
|
57 |
-- Add air weapons to the game if the border is not active
|
|
58 |
if MapHasBorder() == false then
|
|
59 |
for i, w in pairs(airweapons) do
|
|
60 |
table.insert(weapons, w)
|
|
61 |
end
|
|
62 |
end
|
|
63 |
end
|
|
64 |
|
|
65 |
function onAmmoStoreInit()
|
|
66 |
-- Allow skip at all times
|
|
67 |
SetAmmo(amSkip, 9, 0, 0, 0)
|
|
68 |
|
|
69 |
-- Let utilities be available through crates
|
|
70 |
SetAmmo(amParachute, 0, 1, 0, 1)
|
|
71 |
SetAmmo(amGirder, 0, 1, 0, 2)
|
|
72 |
SetAmmo(amSwitch, 0, 1, 0, 1)
|
|
73 |
SetAmmo(amLowGravity, 0, 1, 0, 1)
|
|
74 |
SetAmmo(amExtraDamage, 0, 1, 0, 1)
|
|
75 |
SetAmmo(amInvulnerable, 0, 1, 0, 1)
|
|
76 |
SetAmmo(amExtraTime, 0, 1, 0, 1)
|
|
77 |
SetAmmo(amLaserSight, 0, 1, 0, 1)
|
|
78 |
SetAmmo(amVampiric, 0, 1, 0, 1)
|
|
79 |
SetAmmo(amJetpack, 0, 1, 0, 1)
|
|
80 |
SetAmmo(amPortalGun, 0, 1, 0, 1)
|
|
81 |
SetAmmo(amResurrector, 0, 1, 0, 1)
|
|
82 |
|
|
83 |
-- Allow weapons to be used
|
|
84 |
for i, w in pairs(weapons) do
|
|
85 |
SetAmmo(w, 0, 0, 0, 1)
|
|
86 |
end
|
|
87 |
|
|
88 |
-- Allow air weapons to be used
|
|
89 |
for i, w in pairs(airweapons) do
|
|
90 |
SetAmmo(w, 0, 0, 0, 1)
|
|
91 |
end
|
|
92 |
end
|
|
93 |
|
|
94 |
function onNewTurn()
|
|
95 |
-- Give every team their weapons, so one can plan during anothers turn
|
|
96 |
runOnGears(assignAmmo)
|
|
97 |
-- Mark all teams as not processed
|
|
98 |
runOnGears(reset)
|
|
99 |
-- Set the current teams weapons to nil so they will get new after the turn has ended
|
|
100 |
setTeamValue(GetHogTeamName(CurrentHedgehog), "ammo", nil)
|
|
101 |
end
|
|
102 |
|
|
103 |
function onGearAdd(gear)
|
|
104 |
-- Catch hedgehogs for the tracker
|
|
105 |
if GetGearType(gear) == gtHedgehog then
|
|
106 |
trackGear(gear)
|
|
107 |
end
|
|
108 |
end
|
|
109 |
|
|
110 |
function onGearDelete(gear)
|
|
111 |
-- Remove hogs that are gone
|
|
112 |
trackDeletion(gear)
|
|
113 |
end
|