How To Create A Kill Streak System

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
Gogie
Modeling Master
Modeling Master
Posts: 708
Joined: Fri Mar 31, 2006 11:02 pm
Projects :: Tinkering away with LEGO
Location: alberta, canada

How To Create A Kill Streak System

Post by Gogie »

so because i've been working on a gamemode base on EA's battlefront I needed to create a new kill streak system where if the player scores a certain amount of kills (3) the players trait levels up. What I want to know is if there is an easier way to go about it... It would seem the default reward system is hardcoded so I feel like LUA will be involved in faking a new system but is there an easier way to write this?

what I have so far works but it is long (walker assault gamemode is already 3500 lines of code due to starcards/powerups/gamemode/traits so im trying to shorten it in anyway I can)

so far I have this as working code:

first I created a set of variables to hold the number of the players kills (each variable was made individually to store each players kill count, a single number would globally raise the kill count and I wanted it individually) so for team 1s players I made the following:
Hidden/Spoiler:
[code]local k_c_1_0 = 0
local k_c_1_1 = 0
local k_c_1_2 = 0
local k_c_1_3 = 0
local k_c_1_4 = 0
local k_c_1_5 = 0
local k_c_1_6 = 0
local k_c_1_7 = 0
local k_c_1_8 = 0
local k_c_1_9 = 0
local k_c_1_10 = 0
local k_c_1_11 = 0
local k_c_1_12 = 0
local k_c_1_13 = 0
local k_c_1_14 = 0
local k_c_1_15 = 0
local k_c_1_16 = 0
local k_c_1_17 = 0
local k_c_1_18 = 0
local k_c_1_19 = 0
local k_c_1_20 = 0
local k_c_1_21 = 0
local k_c_1_22 = 0
local k_c_1_23 = 0
local k_c_1_24 = 0
local k_c_1_25 = 0
local k_c_1_26 = 0
local k_c_1_27 = 0
local k_c_1_28 = 0
local k_c_1_29 = 0
local k_c_1_30 = 0
local k_c_1_31 = 0
local k_c_1_32 = 0[/code]
next I made 2 functions with a series of if statements to get the correct kill count from the correct variable however since an upvalue of if statements can only have a maximum of 32 variables I broke it into 2 functions with a set of 20 linked variables each.
Hidden/Spoiler:
[code]function GetPlayerKillCount1Team(killerID, team)

if killerID < 0 or killerID > 19 then return end
if team ~= 1 then return end

if killerID == 0 and team == 1 then
kc = k_c_1_0
elseif killerID == 1 and team == 1 then
kc = k_c_1_1
elseif killerID == 2 and team == 1 then
kc = k_c_1_2
elseif killerID == 3 and team == 1 then
kc = k_c_1_3
elseif killerID == 4 and team == 1 then
kc = k_c_1_4
elseif killerID == 5 and team == 1 then
kc = k_c_1_5
elseif killerID == 6 and team == 1 then
kc = k_c_1_6
elseif killerID == 7 and team == 1 then
kc = k_c_1_7
elseif killerID == 8 and team == 1 then
kc = k_c_1_8
elseif killerID == 9 and team == 1 then
kc = k_c_1_9
elseif killerID == 10 and team == 1 then
kc = k_c_1_10
elseif killerID == 11 and team == 1 then
kc = k_c_1_11
elseif killerID == 12 and team == 1 then
kc = k_c_1_12
elseif killerID == 13 and team == 1 then
kc = k_c_1_13
elseif killerID == 14 and team == 1 then
kc = k_c_1_14
elseif killerID == 15 and team == 1 then
kc = k_c_1_15
elseif killerID == 16 and team == 1 then
kc = k_c_1_16
elseif killerID == 17 and team == 1 then
kc = k_c_1_17
elseif killerID == 18 and team == 1 then
kc = k_c_1_18
elseif killerID == 19 and team == 1 then
kc = k_c_1_19
end
return kc

function GetPlayerKillCount2Team(killerID, team)

if killerID < 20 or killerID > 32 then return end
if team ~= 1 then return end


if killerID == 20 and team == 1 then
kc = k_c_1_20
elseif killerID == 21 and team == 1 then
kc = k_c_1_21
elseif killerID == 22 and team == 1 then
kc = k_c_1_22
elseif killerID == 23 and team == 1 then
kc = k_c_1_23
elseif killerID == 24 and team == 1 then
kc = k_c_1_24
elseif killerID == 25 and team == 1 then
kc = k_c_1_25
elseif killerID == 26 and team == 1 then
kc = k_c_1_26
elseif killerID == 27 and team == 1 then
kc = k_c_1_27
elseif killerID == 28 and team == 1 then
kc = k_c_1_28
elseif killerID == 29 and team == 1 then
kc = k_c_1_29
elseif killerID == 30 and team == 1 then
kc = k_c_1_30
elseif killerID == 31 and team == 1 then
kc = k_c_1_31
elseif killerID == 32 and team == 1 then
kc = k_c_1_32

end
return kc
end
end[/code]
next I created a function to set the players kill count and assign it to the units variable again having to break that into two functions to accomidate the size of the teams.
Hidden/Spoiler:
[code]function SetKillCount1(killer, team, streak)
if killer < 0 or killer > 19 then return end
if team ~= 1 then return end

if killer == 0 and team == 1 then
k_c_1_0 = k_c_1_0 + streak
elseif killer == 1 and team == 1 then
k_c_1_1 = k_c_1_1 + streak
elseif killer == 2 and team == 1 then
k_c_1_2 = k_c_1_2 + streak
elseif killer == 3 and team == 1 then
k_c_1_3 = k_c_1_3 + streak
elseif killer == 4 and team == 1 then
k_c_1_4 = k_c_1_4 + streak
elseif killer == 5 and team == 1 then
k_c_1_5 = k_c_1_5 + streak
elseif killer == 6 and team == 1 then
k_c_1_6 = k_c_1_6 + streak
elseif killer == 7 and team == 1 then
k_c_1_7 = k_c_1_7 + streak
elseif killer == 8 and team == 1 then
k_c_1_8 = k_c_1_8 + streak
elseif killer == 9 and team == 1 then
k_c_1_9 = k_c_1_9 + streak
elseif killer == 10 and team == 1 then
k_c_1_10 = k_c_1_10 + streak
elseif killer == 11 and team == 1 then
k_c_1_11 = k_c_1_11 + streak
elseif killer == 12 and team == 1 then
k_c_1_12 = k_c_1_12 + streak
elseif killer == 13 and team == 1 then
k_c_1_13 = k_c_1_13 + streak
elseif killer == 14 and team == 1 then
k_c_1_14 = k_c_1_14 + streak
elseif killer == 15 and team == 1 then
k_c_1_15 = k_c_1_15 + streak
elseif killer == 16 and team == 1 then
k_c_1_16 = k_c_1_16 + streak
elseif killer == 17 and team == 1 then
k_c_1_17 = k_c_1_17 + streak
elseif killer == 18 and team == 1 then
k_c_1_18 = k_c_1_18 + streak
elseif killer == 19 and team == 1 then
k_c_1_19 = k_c_1_19 + streak
end
end
function SetKillCount2(killer, team, streak)
if killer < 19 or killer > 32 then return end
if team ~= 1 then return end

if killer == 20 and team == 1 then
k_c_1_20 = k_c_1_20 + streak
elseif killer == 21 and team == 1 then
k_c_1_21 = k_c_1_21 + streak
elseif killer == 22 and team == 1 then
k_c_1_22 = k_c_1_22 + streak
elseif killer == 23 and team == 1 then
k_c_1_23 = k_c_1_23 + streak
elseif killer == 24 and team == 1 then
k_c_1_24 = k_c_1_24 + streak
elseif killer == 25 and team == 1 then
k_c_1_25 = k_c_1_25 + streak
elseif killer == 26 and team == 1 then
k_c_1_26 = k_c_1_26 + streak
elseif killer == 27 and team == 1 then
k_c_1_27 = k_c_1_27 + streak
elseif killer == 28 and team == 1 then
k_c_1_28 = k_c_1_28 + streak
elseif killer == 29 and team == 1 then
k_c_1_29 = k_c_1_29 + streak
elseif killer == 30 and team == 1 then
k_c_1_30 = k_c_1_30 + streak
elseif killer == 31 and team == 1 then
k_c_1_31 = k_c_1_31 + streak
elseif killer == 32 and team == 1 then
k_c_1_32 = k_c_1_32 + streak

end
end[/code]
finally I used the OnCharacterDeath() function to change the variables and add the streak number and if the players kill count raises above 3 it changes the train (in this case player unit 0 = rebel survivalist so we want to add a faster health regen, ignore the show message thats for my personal debugging).
Hidden/Spoiler:
[code]OnCharacterDeath(
function(player, killer)
local cTeam = GetCharacterTeam(killer)
local pTeam = GetCharacterTeam(player)
if cTeam == pTeam then return end
local killerID = GetCharacterClass(killer)
local killeru = GetCharacterUnit(killer)
if killerID == 0 then
if cTeam == 1 and killer < 19 and killer > 0 or killer == 0 then
SetKillCount1(killer, cTeam, 1)
local kCount = GetPlayerKillCount1Team(killer, cTeam)
if kCount < 3 then
ShowMessageText("level.BRS.db.kc1", 1)
elseif kCount < 6 and kCount > 2 then
ShowMessageText("level.BRS.db.kc1", 1)
SetProperty(killeru, "AddHealth", 15)
elseif kCount < 9 and kCount > 5 then
ShowMessageText("level.BRS.db.kc2", 1)
SetProperty(killeru, "AddHealth", 20)
elseif kCount == 9 or kCount > 9 then
ShowMessageText("level.BRS.db.kc3", 1)
SetProperty(killeru, "AddHealth", 30)

end

elseif cTeam == 1 and killer > 19 and killer < 33 then
SetKillCount2(killer, cTeam, 1)
local kCount = GetPlayerKillCount1Team(killer, cTeam)
if kCount < 3 then
ShowMessageText("level.BRS.db.kc1", 1)
elseif kCount < 6 and kCount > 2 then
ShowMessageText("level.BRS.db.kc1", 1)
SetProperty(killeru, "AddHealth", 15)
elseif kCount < 9 and kCount > 5 then
ShowMessageText("level.BRS.db.kc2", 1)
SetProperty(killeru, "AddHealth", 20)
elseif kCount == 9 or kCount > 9 then
ShowMessageText("level.BRS.db.kc3", 1)
SetProperty(killeru, "AddHealth", 30)
end
end
end
end

)[/code]
it is fully functional and I mean it works just fine but If there is a way to shorten it all it would make things... well... a lot less of a scrolling adventure.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: How To Create A Kill Streak System

Post by Marth8880 »

Nice! You could simplify those if-statements significantly though by storing the kill-counts in a table:

Code: Select all

-- Container template for storing units' data
unitObj= { team = 0, kills = 0 }

-- Construct our kill-counts table
killCounts = {}

for unit = 0, unit <= 19 do
    -- Initialize data into our new unit's container
    local newUnit = unitObj
    newUnit.team = 1
    newUnit.kills = 0

    -- Insert the container into our kill-counts table (using unit+1 since Lua indexes from 1 instead of 0)
    killCounts[unit+1] = newUnit
end

function GetPlayerKillCount(killerID)
    if killerID < 0 or killerID > 19 then return end
    if team > 2 then return end

    -- Return the killer's kill count and team ID
    return killCounts[killerID+1].kills, killCounts[killerID+1].team
end
Not positive that this won't have errors since I typed it on my phone but yeah.
Post Reply