share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua
author Wuzzy <almikes@aol.com>
Sat, 19 Nov 2016 20:22:55 +0100
changeset 11933 42e90b244e11
parent 10036 3be36d2fdca6
child 12212 2de020695c20
permissions -rw-r--r--
Racer: Dump old commented-out code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
     1
-- Random Weapons, example for gameplay scripts
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
     2
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
     3
-- Load the library for localisation ("loc" function)
8043
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 5352
diff changeset
     4
HedgewarsScriptLoad("/Scripts/Locale.lua")
4590
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
     5
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
     6
-- Load the gear tracker
8043
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 5352
diff changeset
     7
HedgewarsScriptLoad("/Scripts/Tracker.lua")
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
     8
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
     9
-- List of available weapons
4551
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    10
local weapons = { amGrenade, amClusterBomb, amBazooka, amBee, amShotgun,
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    11
            amMine, amDEagle, amDynamite, amFirePunch, amWhip, amPickHammer,
4590
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    12
            amBaseballBat, amTeleport, amMortar, amCake, amSeduction,
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    13
            amWatermelon, amHellishBomb, amDrill, amBallgun, amRCPlane,
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    14
            amSniperRifle, amMolotov, amBirdy, amBlowTorch, amGasBomb,
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    15
            amFlamethrower, amSMine, amHammer }
4551
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    16
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    17
-- List of weapons that attack from the air
4590
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    18
local airweapons = { amAirAttack, amMineStrike, amNapalm, amDrillStrike }
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    19
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    20
-- Function that assigns the team their weapon
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    21
function assignAmmo(hog)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    22
    -- Get name of the current team
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    23
    local name = GetHogTeamName(hog)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    24
    -- Get whither the team has been processed
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    25
    local processed = getTeamValue(name, "processed")
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    26
    -- If it has not, process it
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    27
    if processed == nil or not processed then
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    28
        -- Get the ammo for this hog's team
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    29
        local ammo = getTeamValue(name, "ammo")
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    30
        -- If there is no ammo, get a random one from the list and store it
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    31
        if ammo == nil then
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    32
            ammo = weapons[GetRandom(table.maxn(weapons)) + 1]
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    33
            setTeamValue(name, "ammo", ammo)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    34
        end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    35
        -- Add the ammo for the hog
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    36
        AddAmmo(hog, ammo)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    37
        -- Mark as processed
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    38
        setTeamValue(name, "processed", true)
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    39
    end
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    40
end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    41
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    42
-- Mark team as not processed
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    43
function reset(hog)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    44
    setTeamValue(GetHogTeamName(hog), "processed", false)
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    45
end
4551
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    46
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    47
function onGameInit()
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    48
    -- Limit flags that can be set, but allow game schemes to be used
10036
3be36d2fdca6 use new API for changing GameFlags
sheepluva
parents: 8043
diff changeset
    49
    DisableGameFlags(gfInfAttack)
3be36d2fdca6 use new API for changing GameFlags
sheepluva
parents: 8043
diff changeset
    50
    EnableGameFlags(gfResetWeps)
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    51
    -- Set a custom game goal that will show together with the scheme ones
4893
353781305c07 make Random Weapons and No Jumping use the new custom goal function
Henek
parents: 4590
diff changeset
    52
    Goals = loc("Each turn you get one random weapon")
4551
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    53
end
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    54
4590
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    55
function onGameStart()
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    56
    -- Initialize the tracking of hogs and teams
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    57
    trackTeams()
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    58
    -- Add air weapons to the game if the border is not active
4590
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    59
    if MapHasBorder() == false then
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    60
        for i, w in pairs(airweapons) do
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    61
            table.insert(weapons, w)
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    62
        end
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    63
    end
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    64
end
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    65
4551
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    66
function onAmmoStoreInit()
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    67
    -- Allow skip at all times
4551
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    68
    SetAmmo(amSkip, 9, 0, 0, 0)
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    69
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    70
    -- Let utilities be available through crates
4551
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    71
    SetAmmo(amParachute, 0, 1, 0, 1)
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    72
    SetAmmo(amGirder, 0, 1, 0, 2)
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    73
    SetAmmo(amSwitch, 0, 1, 0, 1)
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    74
    SetAmmo(amLowGravity, 0, 1, 0, 1)
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    75
    SetAmmo(amExtraDamage, 0, 1, 0, 1)
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    76
    SetAmmo(amInvulnerable, 0, 1, 0, 1)
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    77
    SetAmmo(amExtraTime, 0, 1, 0, 1)
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    78
    SetAmmo(amLaserSight, 0, 1, 0, 1)
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    79
    SetAmmo(amVampiric, 0, 1, 0, 1)
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    80
    SetAmmo(amJetpack, 0, 1, 0, 1)
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    81
    SetAmmo(amPortalGun, 0, 1, 0, 1)
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    82
    SetAmmo(amResurrector, 0, 1, 0, 1)
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    83
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    84
    -- Allow weapons to be used
4551
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    85
    for i, w in pairs(weapons) do
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    86
        SetAmmo(w, 0, 0, 0, 1)
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    87
    end
4590
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    88
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    89
    -- Allow air weapons to be used
4590
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    90
    for i, w in pairs(airweapons) do
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    91
        SetAmmo(w, 0, 0, 0, 1)
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4551
diff changeset
    92
    end
4551
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    93
end
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    94
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
    95
function onNewTurn()
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
    96
    -- Give every team their weapons, so one can plan during anothers turn
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    97
    runOnGears(assignAmmo)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    98
    -- Mark all teams as not processed
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5138
diff changeset
    99
    runOnGears(reset)
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
   100
    -- Set the current teams weapons to nil so they will get new after the turn has ended
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
   101
    setTeamValue(GetHogTeamName(CurrentHedgehog), "ammo", nil)
4551
05c32ee166b6 added replacement of "_" to " " in gameplay scripts
Henek
parents:
diff changeset
   102
end
5138
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
   103
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
   104
function onGearAdd(gear)
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
   105
    -- Catch hedgehogs for the tracker
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
   106
    if GetGearType(gear) == gtHedgehog then
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
   107
        trackGear(gear)
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
   108
    end
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
   109
end
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
   110
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
   111
function onGearDelete(gear)
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
   112
    -- Remove hogs that are gone
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
   113
    trackDeletion(gear)
f991f87969ff now Random Weapons will show the weapon you will get during the other players turns
Henek
parents: 4893
diff changeset
   114
end