|
1 -- Random Weapons, example for gameplay scripts |
|
2 |
|
3 -- Load the library for localisation ("loc" function) |
1 loadfile(GetDataPath() .. "Scripts/Locale.lua")() |
4 loadfile(GetDataPath() .. "Scripts/Locale.lua")() |
2 |
5 |
|
6 -- Load the gear tracker |
|
7 loadfile(GetDataPath() .. "Scripts/Tracker.lua")() |
|
8 |
|
9 -- List of available weapons |
3 local weapons = { amGrenade, amClusterBomb, amBazooka, amBee, amShotgun, |
10 local weapons = { amGrenade, amClusterBomb, amBazooka, amBee, amShotgun, |
4 amMine, amDEagle, amDynamite, amFirePunch, amWhip, amPickHammer, |
11 amMine, amDEagle, amDynamite, amFirePunch, amWhip, amPickHammer, |
5 amBaseballBat, amTeleport, amMortar, amCake, amSeduction, |
12 amBaseballBat, amTeleport, amMortar, amCake, amSeduction, |
6 amWatermelon, amHellishBomb, amDrill, amBallgun, amRCPlane, |
13 amWatermelon, amHellishBomb, amDrill, amBallgun, amRCPlane, |
7 amSniperRifle, amMolotov, amBirdy, amBlowTorch, amGasBomb, |
14 amSniperRifle, amMolotov, amBirdy, amBlowTorch, amGasBomb, |
8 amFlamethrower, amSMine, amHammer, amSnowball, amTardis, amStructure } |
15 amFlamethrower, amSMine, amHammer } |
9 |
16 |
|
17 -- List of weapons that attack from the air |
10 local airweapons = { amAirAttack, amMineStrike, amNapalm, amDrillStrike } |
18 local airweapons = { amAirAttack, amMineStrike, amNapalm, amDrillStrike } |
11 |
19 |
|
20 -- Function that assigns the team their weapon |
|
21 -- Due to the fact that the gameplay uses reset weapons and no inf attack there is no point in limiting the ammo count |
|
22 function assignWeapon(hog) |
|
23 -- Get the ammo for this hog's team |
|
24 local ammo = getTeamValue(GetHogTeamName(hog), "ammo") |
|
25 -- If there is no ammo, get a random one from the list and store it |
|
26 if ammo == nil then |
|
27 ammo = weapons[GetRandom(table.maxn(weapons)) + 1] |
|
28 setTeamValue(GetHogTeamName(hog), "ammo", ammo) |
|
29 end |
|
30 -- Add the ammo for the hog |
|
31 AddAmmo(hog, ammo) |
|
32 end |
12 |
33 |
13 function onGameInit() |
34 function onGameInit() |
|
35 -- Limit flags that can be set, but allow game schemes to be used |
14 GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack + gfPerHogAmmo)) |
36 GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack + gfPerHogAmmo)) |
|
37 -- Set a custom game goal that will show together with the scheme ones |
15 Goals = loc("Each turn you get one random weapon") |
38 Goals = loc("Each turn you get one random weapon") |
16 end |
39 end |
17 |
40 |
18 function onGameStart() |
41 function onGameStart() |
|
42 -- Initialize the tracking of hogs and teams |
|
43 trackTeams() |
|
44 -- Add air weapons to the game if the border is not active |
19 if MapHasBorder() == false then |
45 if MapHasBorder() == false then |
20 for i, w in pairs(airweapons) do |
46 for i, w in pairs(airweapons) do |
21 table.insert(weapons, w) |
47 table.insert(weapons, w) |
22 end |
48 end |
23 end |
49 end |
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) |
|
25 end |
50 end |
26 |
51 |
27 function onAmmoStoreInit() |
52 function onAmmoStoreInit() |
|
53 -- Allow skip at all times |
28 SetAmmo(amSkip, 9, 0, 0, 0) |
54 SetAmmo(amSkip, 9, 0, 0, 0) |
29 |
55 |
|
56 -- Let utilities be available through crates |
30 SetAmmo(amParachute, 0, 1, 0, 1) |
57 SetAmmo(amParachute, 0, 1, 0, 1) |
31 SetAmmo(amGirder, 0, 1, 0, 2) |
58 SetAmmo(amGirder, 0, 1, 0, 2) |
32 SetAmmo(amSwitch, 0, 1, 0, 1) |
59 SetAmmo(amSwitch, 0, 1, 0, 1) |
33 SetAmmo(amLowGravity, 0, 1, 0, 1) |
60 SetAmmo(amLowGravity, 0, 1, 0, 1) |
34 SetAmmo(amExtraDamage, 0, 1, 0, 1) |
61 SetAmmo(amExtraDamage, 0, 1, 0, 1) |
38 SetAmmo(amVampiric, 0, 1, 0, 1) |
65 SetAmmo(amVampiric, 0, 1, 0, 1) |
39 SetAmmo(amJetpack, 0, 1, 0, 1) |
66 SetAmmo(amJetpack, 0, 1, 0, 1) |
40 SetAmmo(amPortalGun, 0, 1, 0, 1) |
67 SetAmmo(amPortalGun, 0, 1, 0, 1) |
41 SetAmmo(amResurrector, 0, 1, 0, 1) |
68 SetAmmo(amResurrector, 0, 1, 0, 1) |
42 |
69 |
|
70 -- Allow weapons to be used |
43 for i, w in pairs(weapons) do |
71 for i, w in pairs(weapons) do |
44 SetAmmo(w, 0, 0, 0, 1) |
72 SetAmmo(w, 0, 0, 0, 1) |
45 end |
73 end |
46 |
74 |
|
75 -- Allow air weapons to be used |
47 for i, w in pairs(airweapons) do |
76 for i, w in pairs(airweapons) do |
48 SetAmmo(w, 0, 0, 0, 1) |
77 SetAmmo(w, 0, 0, 0, 1) |
49 end |
78 end |
50 end |
79 end |
51 |
80 |
52 function onNewTurn() |
81 function onNewTurn() |
53 AddAmmo(CurrentHedgehog, weapons[GetRandom(table.maxn(weapons)) + 1]) |
82 -- Give every team their weapons, so one can plan during anothers turn |
|
83 runOnGears(assignWeapon) |
|
84 -- Set the current teams weapons to nil so they will get new after the turn has ended |
|
85 setTeamValue(GetHogTeamName(CurrentHedgehog), "ammo", nil) |
54 end |
86 end |
|
87 |
|
88 function onGearAdd(gear) |
|
89 -- Catch hedgehogs for the tracker |
|
90 if GetGearType(gear) == gtHedgehog then |
|
91 trackGear(gear) |
|
92 end |
|
93 end |
|
94 |
|
95 function onGearDelete(gear) |
|
96 -- Remove hogs that are gone |
|
97 trackDeletion(gear) |
|
98 end |