Page 1 of 1

Hunger Games Scripting

Posted: Tue Feb 04, 2014 8:18 pm
by LRKfm946
Hey everyone, I'm currently working on making a map that will be used for playing online battlefront Hunger Games. I've played several rounds with friends and it works fine but I'd like things to be a bit more automated. I want to make a mission script that will do all the timing/lua commands for me so that I'll be able to play this map on a PC dedi server without having to use fake console.Here's what I want it to do:

1. Wait until all humans that are spawned in/alive are in a region in the center of the map (there will be no bots.)
2. Once they all stay in the region for 10 seconds, they will be frozen in place for a few moments while a few messages pop up.
3. There will be a countdown, after which there will be a 30 second period where everyone runs out from the center and goes wherever, but they're not allowed to shoot or follow other people.
4. After the 30 seconds, the Games begin. At this point I usually use the Fake console command Enemies Teams 1<>1 2<>2 3<>3 so that teams wont matter and nobody can spawn back in after they've already been eliminated.
5. Once there is only 1 person remaining alive, the round is over, everything is reset, and the mission starts over from step 1.


I'm still a beginner at lua scripting, but I'm familiar with programming in general, and I've skimmed through the mission scripts for Repsharpshooter's Battle Arena 2.0. If you have any ideas or recommendations as to what functions to use where, please do contribute!



EDIT 3/12/14: Here's where I'm at right now: With the lua, I've got most of my objectives working, but it crashes in MP. A wierd quirk is that with my first objective (GoTo), if I complete it as CIS, it will complete the objective and go to the next one, but if I complete it as Republic, it will complete the objective then I get mission victory and the game ends. I also need to get my shield powerups working. My lua is posted below.
Sounds: The sides are missing a lot of sounds, including blaster pistol shot, walking, weapon change sounds for some weapons. Environmental sounds won't work either. I DID get the main global amb to work one time, but the next time I munged, it went away.

Thanks,
Kfm

Re: Hunger Games Scripting

Posted: Wed Feb 05, 2014 2:18 am
by Noobasaurus
For your scripting, I'd recommend looking through the stock scripts. This way, you can get an idea of all the functions and how they work. If you need to find any specific ones, they're all listed here.

And of course, if something goes wrong with the script, you can post the problem here.

Re: Hunger Games Scripting

Posted: Thu Feb 20, 2014 1:43 pm
by LRKfm946
Does anyone have a solution to the health/ammo droid issue?

Re: Hunger Games Scripting

Posted: Sun Feb 23, 2014 9:44 am
by MileHighGuy
You should make the droids into automated turrets that fire health and and ammo.

Re: Hunger Games Scripting

Posted: Sun Feb 23, 2014 3:18 pm
by LRKfm946
I like that idea, and I could totally do it. I just need to figure out how to get the changes to work ingame. I modified the droids' odfs but the changes didn't show up. I'm assuming it's some Lua code that I have to add in to the mission scripts but I don't know what the code is.

I'm also thinking of using the method Repsharpshooter used in Battle Arena 2.0 wave mode where the health/ammo packs would periodically spawn at path nodes. It'll be harder, but probably more effective and more realistic because you'd have to search for the packs as opposed to just going to the droids.

Re: Hunger Games Scripting

Posted: Thu Feb 27, 2014 2:18 pm
by [RDH]Zerted
1+2+3) It might be easier to have an impassable wall all around the center of the map. Then when you want the game to begin, the wall moves down under the ground and/or disappears.
3) Setting all teams to be friends of each other will prevent units from hurting each other if team damage is off.
4) The code from that command is:

Code: Select all

SetTeamAsEnemy(1, 1)
SetTeamAsEnemy(2, 2)
SetTeamAsEnemy(3, 3)
What you want to do is all possible.

Re: Hunger Games Scripting

Posted: Fri Feb 28, 2014 3:49 am
by LRKfm946
That's a great idea, unfortunately ZE doesn't work on my computer so I can't edit worlds. This means I'm stuck with using maps that have already been made and making a new mission script for them. Therefore adding any objects, regions, etc. wont be possible.

I do like the idea of turning friendly fire off and making all teams friends though, it's much more effective at controlling players before the match starts. The other alternative would be locking weapons until the games start. Is there a function for that? Another huge thing I wanted to do was deplete the ammo from every weapon at the beginning of each round. Is it possible to make units spawn without ammo?

I'm also thinking efore a round starts, teleport all players to some position or region in the middle of the map (if that's possible) and hold them there. What are the functions that affect player position?

Re: Hunger Games Scripting

Posted: Fri Feb 28, 2014 3:12 pm
by Locutus
LRKfm946 wrote:I'm also thinking of using the method Repsharpshooter used in Battle Arena 2.0 wave mode where the health/ammo packs would periodically spawn at path nodes. It'll be harder, but probably more effective and more realistic because you'd have to search for the packs as opposed to just going to the droids.
I never tried spawning ammo packs but I believe you could do it like this:

Code: Select all

 --get the path point
Ammo1Spawn = GetPathPoint("YourPath", 0) --GetPathPoint(Pathname, node)

--spawn powerup
CreateEntity("com_item_powerup_dual", Ammo1Spawn, "ammo1") --CreateEntity(class, node, name)
LRKfm946 wrote:The other alternative would be locking weapons until the games start. Is there a function for that?
Technically, you could change a players weapon by using SetProperty to give him weapons that do no damage (like a fusion cutter) but this will crash the game for all clients in MP... Maybe SetClassProperty works in MP, I never tested that.
LRKfm946 wrote:I'm also thinking efore a round starts, teleport all players to some position or region in the middle of the map (if that's possible) and hold them there. What are the functions that affect player position?
http://www.gametoast.com/viewtopic.php?p=199663#p199663

Re: Hunger Games Scripting

Posted: Fri Feb 28, 2014 7:38 pm
by LRKfm946
Thanks for that sample code! I've successfully coded the ammo packs spawning. A few issues:

1. I want to make it so that the packs that spawn at cps WILL refill ammo for the engi's dispenser, but packs dispensed by the engi will NOT. Is this possible?

2. I was able to get changes to droids/packs in game but now all of the fake console commands are gone except ToggleQosDisplay. In the Lua before ScriptPostLoad() I have:

Code: Select all

ReadDataFile("common.lvl")
ReadDataFile("dc:common.lvl")
ReadDataFile("core.lvl")
ReadDataFile("dc:core.lvl")
Is there a fix?


Another feature I'd like to add is that if a person camps for too long, they will start to lose health at a very slow rate, and they'll stop losing health if they go on the move. Is this possible?
Locutus wrote:
LRKfm946 wrote:I'm also thinking efore a round starts, teleport all players to some position or region in the middle of the map (if that's possible) and hold them there. What are the functions that affect player position?
http://www.gametoast.com/viewtopic.php?p=199663#p199663
Is there a way to teleport players to a position on the map instead of a region or node?

Re: Hunger Games Scripting

Posted: Sat Mar 01, 2014 10:16 am
by Locutus
1. Sry, I don't know, never looked into that.

2. That's because your custom core level overwrites the regular one I think. What do you need the core.lvl for?

3. Yes, you can also teleport players to a matrix location:

Code: Select all

--find an object that's close to the position you want the player to teleport to
local object1Location = GetEntityMatrix("name_of_your_prop_in_ZE")

--create a new matrix to which the player is supposed to be teleported
local destination1Matrix = CreateMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, object1Location)
See here for information on how to get the correct offset values.


Edit: Stumbled upon this, you might try it to spawn units with less/no ammo: viewtopic.php?f=27&t=23708&p=406957#p407030

Re: Hunger Games Scripting

Posted: Thu Mar 06, 2014 1:34 am
by LRKfm946
I've made pretty good progress on the map. I go home from campus on some weekends, so I can use my old computer that runs ZE. I started making the world, but it'll take a while.
As for everything else:

1. Since I'm only slightly modifying the stock sides, I made a custom side containing all units from each faction that I'm actually using, modifying some parameters, and inheriting the rest from the stock units as ClassParents.
I got it all working, including localization, but since I'm using 1.3 sides, all of the custom weapon models have floating HUD icons :S I looked through some threads about fixing it but all the threads were about icons made by the modder themself, not loaded from stock sides. Any ideas?
EDIT: FIXED!!!


2. Sound issues: I added a global soundstream and some thunder, but niether have sound. Again, all of the sound threads seemed to be about adding custom sounds or fixing shipped sounds from sides, not world sounds. EDIT: Foliage collision sounds are also missing.
There are some other random sounds missing though, including footsteps on land in CW, footsteps on land and water in GCW, some weapon change sounds, objective update/complete sounds, among others. How can I round up all the missing sounds and get them back in? Do I have to pick them out one by one?

3. LUA issues: I'm having trouble with teleporting powerups to a players position when they spawn. Here's my code:

Code: Select all

antipower = function( player )

	print("Getting player position:")
	local unit = GetCharacterUnit( player )
	local unitLocation = GetEntityMatrix( unit )
	--get the player's spawn position
	--local player_pos = GetEntityMatrix(player)
	print("Player position: ")
	print(unitLocation)
	CreateEntity("com_item_powerup_antiarmor", sammo_spawn4, "antiarmor")
	CreateEntity("com_item_powerup_antiammo", sammo_spawn4, "antiammo")
	SetEntityMatrix("antiarmor", unitLocation)
	SetEntityMatrix("antiammo", unitLocation)

end 
When I spawn, the powerups are spawned at their spawn node, but they don't get teleported to me.
Is there a way to get the node that a player spawned at, on player spawn?

4. Here's a biggie: I've added "armor" to all units (technically they're shields, but without any visual effects). The armor will start at zero (once I get the player/powerup spawning issue fixed) and there will be armor "powerups" throughout the map. I can't get the powerups to work. I know it's possible (http://www.gametoast.com/viewtopic.php? ... 2&p=501080). Mav or Marth, could ya help me out? :P


I'm also concerned about MP compatibility issues. Given that this entire project is meant specifically to be played online, I can't have any issues whatsoever. Are there certain things I should stay away from in my mission script? And how exactly do mission scripts work online?

Re: Hunger Games Scripting

Posted: Fri Mar 07, 2014 12:59 pm
by Locutus
3. Ever tried to spawn the powerups directly at the player location?
CreateEntity("com_item_powerup_antiammo", unitLocation, "antiammo")

4. Zerted does that in his holocron mode, go check it out.

(5.) Math.random can cause issues if you're not Zerted.
In general, MP is less stable then SP so avoid hitting engine limits. SetProperty() on player units is likely to crash as well as tempering with weapons via lua. pilotetype="vehicleself" will always crash MP. There are a few things that work while others crash, simplest thing is to try it out.

Re: Hunger Games Scripting

Posted: Thu Mar 13, 2014 7:32 pm
by LRKfm946
Okay so I fixed the floating HUD icons by deleting everything in ingame.req except what I modified. I fixed the server crashing issue; for some reason it doesn't like loading sound from the addon folder. I had to take out all of the dc:sound lines in my lua, then it worked. That fixed some of the missing sounds but these ones are still missing:
Hidden/Spoiler:
--UNITS--

Detpack weapon switch
Detpack throw
grenade throw
grenade bounce
recon droid (all)
bothan - all except incinerator fire sound
wookie - all except ordinance water sounds and grenade land explosion
rep commando pistal ordinance hit
rep defense buff weapon switch
rep defense buff activate
imp officer - all except ordinance water sounds and rage sound
dark trooper - all except ordinance water sounds and grenade land explosion
wrist blaster reload

--WORLD--
Kamino lightning
I was thinking of making the other two superpowerups be invisibility and adrenaline (speed boost, etc.). I messed around in the lua with SetProperty trying several different properties, but nothing worked. Has anyone tried anything like this?

Currently my biggest issue is that when I run the map on a dedicated server, for some reason I'm unable to jump. (Click here for a video) It's pretty bizzarre and I have no idea why it's happening. It doesn't happen in single player. The client's game think's it's possible to jump, but the server doesn't, even though they have the exact same files. I copy the HGS folder to the server addon after each munge. This doesn't happen with any other map on the server. I'm using server manager 1.1, with v1.3 common, shell, and ingame.lvls and bryant's v1.4 patched exe.

The other biggest problem is that with my first objective (GoTo), if I complete it as CIS, it will complete the objective and go to the next one, but if I complete it as Republic, it will complete the objective then I get mission victory and the game ends. I want it to treat both teams the same, since it's a free for all game mode. How can I set this up?

Here's my lua:
Hidden/Spoiler:
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

-- load the gametype script
ScriptCB_DoFile("setup_teams")
ScriptCB_DoFile("Objective")
ScriptCB_DoFile("ObjectiveTDM")
ScriptCB_DoFile("ObjectiveConquest")
ScriptCB_DoFile("ObjectiveAssault")
ScriptCB_DoFile("ObjectiveGoto")
ScriptCB_DoFile("MultiObjectiveContainer")

debug_on = true

players_alive = {}



---------------------------------------------------------------------------
-- ScriptPostLoad
---------------------------------------------------------------------------
function ScriptPostLoad()


SetTeamAsFriend(1, 2)
SetTeamAsFriend(2, 1)
AllowAISpawn(1, false)
AllowAISpawn(2, false)
SetClassProperty("com_bldg_controlzone", "NeutralizeTime", 999999)
SetClassProperty("com_bldg_controlzone", "CaptureTime", 999999)
SetClassProperty("com_bldg_major_controlzone", "NeutralizeTime", 999999)
SetClassProperty("com_bldg_major_controlzone", "CaptureTime", 999999)

onfirstspawn = OnCharacterSpawn(
function(player)
if IsCharacterHuman(player) then
ReleaseCharacterSpawn(onfirstspawn)
antipower(player)
StartObjectives ()
objectiveSequence.delayNextSetTime = 0.5
end
end
)

--==============================--
-----***PRE-GAME OBJECTIVE***-----
--==============================--

GoToStart = ObjectiveGoto:New{text = "level.HGS.intro1", popupText = "level.HGS.intro_popup",
regionName = "team1_capture", mapIcon = "imp_icon"}

GoToStart.OnStart = function(self)

ShowMessageText("level.HGS.gotostart")

onspawn = OnCharacterSpawn(
function(player)
ShowObjectiveTextPopup("level.HGS.intro_popup")
antipower(player)
end
)


GoToMessage = CreateTimer("GoToMessage")
SetTimerValue(GoToMessage, 15)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.gotostart", 1)
ShowMessageText("level.HGS.gotostart", 2)
SetTimerValue(GoToMessage, 15)
StartTimer(GoToMessage)
end,
GoToMessage
)
StartTimer(GoToMessage)
--StartTimer(CheckPlayerCount)
MapAddEntityMarker("cp_center", "hud_objective_icon", 3.0, 1, "YELLOW", true, true, true)
MapAddEntityMarker("cp_center", "hud_objective_icon", 3.0, 2, "YELLOW", true, true, true)

onspawn = OnCharacterSpawn(
function(player)
ShowObjectiveTextPopup("level.HGS.intro_popup")
antipower(player)
end
)

end

GoToStart.OnComplete = function (self)

MapRemoveEntityMarker("cp_center")
StopTimer(GoToMessage)
DestroyTimer(GoToMessage)
if uf_processPlayers then
uf_processPlayers(players_alive)
print(players_alive)
else
show("Player list wasn't created")
end

end


--==============================--
---***GRACE PERIOD OBJECTIVE***---
--==============================--
Dummy = TargetType:New{classname = "com_bldg_ctfbase", killLimit = 1, icon = nil}
GracePeriod = ObjectiveAssault:New{textATT = "level.HGS.rules1", textDEF = "level.HGS.rules2",
popupText = "level.HGS.rules_popup"}
GracePeriod:AddTarget(Dummy)

GracePeriod.OnStart = function(self)

SetProperty ("cp_center1","Team",0)
SetProperty ("cp_center2","Team",0)
ShowObjectiveTextPopup("level.HGS.rules_popup")

--==============================--
-------COUNTDOWN TIMERS-----------
--==============================--
ReadRules = CreateTimer("ReadRules")
SetTimerValue(ReadRules, 17)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.gp_count", 1)
ShowMessageText("level.HGS.gp_count", 2)
DestroyTimer(ReadRules)
ShowMessageText("level.HGS.countdown3", 1)
ShowMessageText("level.HGS.countdown3", 2)
StartTimer(countdown3_gp)
end,
ReadRules
)

countdown3_gp = CreateTimer("countdown3_gp")
SetTimerValue(countdown3_gp, 1)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.countdown2", 1)
ShowMessageText("level.HGS.countdown2", 2)
DestroyTimer(countdown3_gp)
StartTimer(countdown2_gp)
end,
countdown3_gp
)

countdown2_gp = CreateTimer("countdown2_gp")
SetTimerValue(countdown2_gp, 1)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.countdown1", 1)
ShowMessageText("level.HGS.countdown1", 2)
DestroyTimer(countdown2_gp)
StartTimer(countdown1_gp)
end,
countdown2_gp
)

countdown1_gp = CreateTimer("countdown1_gp")
SetTimerValue(countdown1_gp, 1)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.gp_begin", 1)
ShowMessageText("level.HGS.gp_begin", 2)
MapRemoveEntityMarker("cp_center")
DestroyTimer(countdown1_gp)
StartTimer(GracePeriod30)
end,
countdown1_gp
)

GracePeriod30 = CreateTimer("GracePeriod30")
SetTimerValue(GracePeriod30, 10)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.time20", 1)
ShowMessageText("level.HGS.time20", 2)
DestroyTimer(GracePeriod30)
StartTimer(GracePeriod20)
end,
GracePeriod30
)

GracePeriod20 = CreateTimer("GracePeriod20")
SetTimerValue(GracePeriod20, 10)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.time10", 1)
ShowMessageText("level.HGS.time10", 2)
DestroyTimer(GracePeriod20)
StartTimer(GracePeriod10)
end,
GracePeriod20
)

GracePeriod10 = CreateTimer("GracePeriod10")
SetTimerValue(GracePeriod10, 7)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.countdown3", 1)
ShowMessageText("level.HGS.countdown3", 2)
DestroyTimer(GracePeriod10)
StartTimer(countdown3_hg)
end,
GracePeriod10
)

countdown1_hg = CreateTimer("countdown1_hg")
SetTimerValue(countdown1_hg, 1)
OnTimerElapse(
function(timer)
DestroyTimer(countdown1_hg)
KillObject("com_bldg_ctfbase2")
-- SetClassProperty("com_bldg_major_controlzone", "CaptureTime", .8)
-- SetProperty("cp_center", "CaptureRegion", "team2_capture")
-- tempSpawnBot()
end,
countdown1_hg
)

countdown2_hg = CreateTimer("countdown2_hg")
SetTimerValue(countdown2_hg, 1)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.countdown1", 1)
ShowMessageText("level.HGS.countdown1", 2)
DestroyTimer(countdown2_hg)
StartTimer(countdown1_hg)
end,
countdown2_hg
)

countdown3_hg = CreateTimer("countdown3_hg")
SetTimerValue(countdown3_hg, 1)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.countdown2", 1)
ShowMessageText("level.HGS.countdown2", 2)
DestroyTimer(countdown3_hg)
StartTimer(countdown2_hg)
end,
countdown3_hg
)

StartTimer(ReadRules)


end

GracePeriod.OnComplete = function(self)

-- SetClassProperty("com_bldg_major_controlzone", "CaptureTime", 999999)
-- SetProperty("cp_center", "CaptureRegion", "cp_center_capture")
-- SetObjectTeam("cp_center", 0)
ShowMessageText("level.HGS.gp_end", 1)
ShowMessageText("level.HGS.gp_end", 2)

end


--=============================--
----=-***GAMES OBJECTIVE***------
--=============================--

HungerGames = ObjectiveTDM:New{teamATT = 1 and 2, teamDEF = 3, MultiplayerScoreLimit = -1,
textATT = "level.HGS.rules1",
textDEF = "level.HGS.rules2", multiplayerRules = true, isCelebrityDeathmatch = true}

HungerGames.OnStart = function(self)

playersAlive = GetPlayersAlive()
ATT = 1
DEF = 2
ShowMessageText("level.HGS.games_begun", 1)
ShowMessageText("level.HGS.games_begun", 2)
SetTeamAsEnemy(1, 1)
SetTeamAsEnemy(1, 2)
SetTeamAsEnemy(2, 2)
SetTeamAsEnemy(2, 2)
SetTeamAsEnemy(3, 3)

RunTimers()

-- while (playersAlive > 1) do
-- on


end

HungerGames.OnComplete = function(self)

end

end

---------------------------------------------------------------------------
-- FUNCTION: ScriptInit
-- PURPOSE: This function is only run once
-- INPUT:
-- OUTPUT:
-- NOTES: The name, 'ScriptInit' is a chosen convention, and each
-- mission script must contain a version of this function, as
-- it is called from C to start the mission.
---------------------------------------------------------------------------
function ScriptInit()

ReadDataFile("ingame.lvl")
ReadDataFile("dc:ingame.lvl")

CIS = 1
REP = 2
--HGS = 3
-- These variables do not change
--ATT = 1 and 2
--DEF = 3


SetMaxFlyHeight(50)
SetMaxPlayerFlyHeight (50)

SetMemoryPoolSize ("ClothData",20)
SetMemoryPoolSize ("Combo",50) -- should be ~ 2x number of jedi classes
SetMemoryPoolSize ("Combo::State",650) -- should be ~12x #Combo
SetMemoryPoolSize ("Combo::Transition",650) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Condition",650) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Attack",550) -- should be ~8-12x #Combo
SetMemoryPoolSize ("Combo::DamageSample",6000) -- should be ~8-12x #Combo::Attack
SetMemoryPoolSize ("Combo::Deflect",100) -- should be ~1x #combo

--ReadDataFile("dc:sound\\tat.lvl;tat2gcw")
ReadDataFile("SIDE\\all.lvl",
"all_inf_officer_jungle",
"all_inf_wookiee")

ReadDataFile("SIDE\\imp.lvl",
"imp_inf_officer",
"imp_inf_dark_trooper")

--ReadDataFile("dc:sound\\hgs.lvl;hgscw")
--ReadDataFile("dc:sound\\kam.lvl;kam1cw")
--ReadDataFile("dc:sound\\yav.lvl;yav1cw")
ReadDataFile("sound\\dag.lvl;dag1cw")
--ReadDataFile("sound\\dag.lvl;dag1gcw")
ReadDataFile("SIDE\\rep.lvl",
"rep_inf_ep3_rifleman",
"rep_inf_ep3_rocketeer",
"rep_inf_ep3_engineer",
"rep_inf_ep3_sniper",
"rep_inf_ep3_sniper_felucia",
"rep_inf_ep3_officer",
"rep_inf_ep3_jettrooper")

ReadDataFile("SIDE\\cis.lvl",
"cis_inf_rifleman",
"cis_inf_rocketeer",
"cis_inf_engineer",
"cis_inf_sniper",
"cis_inf_officer")


ReadDataFile("dc:SIDE\\hgs.lvl",
"hgs_rep_inf_ep3_rifleman",
"hgs_rep_inf_ep3_rocketeer",
"hgs_rep_inf_ep3_engineer",
"hgs_rep_inf_ep3_sniper_felucia",
"hgs_rep_inf_ep3_officer",
"hgs_rep_inf_ep3_jettrooper",
"hgs_cis_inf_rifleman",
"hgs_cis_inf_rocketeer",
"hgs_cis_inf_engineer",
"hgs_cis_inf_sniper",
"hgs_cis_inf_officer",
"hgs_all_inf_officer_jungle",
"hgs_all_inf_wookiee",
"hgs_imp_inf_officer",
"hgs_imp_inf_dark_trooper")



SetupTeams{
rep = {
team = REP,
units = 1,
reinforcements = -1,
soldier = { "hgs_rep_inf_ep3_rifleman",0, 25},
assault = { "hgs_rep_inf_ep3_rocketeer",0, 16},
engineer = { "hgs_rep_inf_ep3_engineer",0, 16},
sniper = { "hgs_rep_inf_ep3_sniper_felucia",0, 16},
officer = {"hgs_rep_inf_ep3_officer",0, 16},
special = { "hgs_rep_inf_ep3_jettrooper",0, 16},

},
cis = {
team = CIS,
units = 1,
reinforcements = -1,
soldier = { "hgs_cis_inf_rifleman",0, 25},
assault = { "hgs_cis_inf_rocketeer",0, 16},
engineer = { "hgs_cis_inf_engineer",0, 16},
sniper = { "hgs_cis_inf_sniper",0, 16},
officer = {"hgs_cis_inf_officer",0, 16},
special = { "hgs_all_inf_officer_jungle",0, 16},
}
}

-- SetHeroClass(CIS, "cis_hero_darthmaul")
-- SetHeroClass(REP, "rep_hero_anakin")
AddUnitClass(CIS, "hgs_all_inf_wookiee", 0, 16)
AddUnitClass(REP, "hgs_imp_inf_officer", 0, 16)
AddUnitClass(REP, "hgs_imp_inf_dark_trooper", 0, 16)


-- Level Stats
-- ClearWalkers()
AddWalkerType(0, 4) -- special -> droidekas
AddWalkerType(1, 0) -- 1x2 (1 pair of legs)
AddWalkerType(2, 0) -- 2x2 (2 pairs of legs)
AddWalkerType(3, 0) -- 3x2 (3 pairs of legs)
local weaponCnt = 1024
SetMemoryPoolSize("Aimer", 75)
SetMemoryPoolSize("AmmoCounter", weaponCnt)
SetMemoryPoolSize("BaseHint", 1024)
SetMemoryPoolSize("EnergyBar", weaponCnt)
SetMemoryPoolSize("EntityCloth", 32)
SetMemoryPoolSize("EntityFlyer", 32)
SetMemoryPoolSize("EntityHover", 32)
SetMemoryPoolSize("EntityLight", 200)
SetMemoryPoolSize("EntitySoundStream", 64)
SetMemoryPoolSize("EntitySoundStatic", 32)
SetMemoryPoolSize("MountedTurret", 32)
SetMemoryPoolSize("Navigator", 128)
SetMemoryPoolSize("Obstacle", 1024)
SetMemoryPoolSize("PathNode", 1024)
SetMemoryPoolSize("SoldierAnimation", 1800)
SetMemoryPoolSize("SoundSpaceRegion", 64)
SetMemoryPoolSize("TreeGridStack", 1024)
SetMemoryPoolSize("UnitAgent", 128)
SetMemoryPoolSize("UnitController", 128)
SetMemoryPoolSize("Weapon", weaponCnt)

SetSpawnDelay(10.0, 0.25)
--ReadDataFile("dc:HGS\\HGS.lvl", "HGS_conquest")
ReadDataFile("dc:HGS\\HGS.lvl", "HGS_conquest")
SetDenseEnvironment("false")




-- Sound

SetSoundEffect("ScopeDisplayZoomIn", "binocularzoomin")
SetSoundEffect("ScopeDisplayZoomOut", "binocularzoomout")

voiceSlow = OpenAudioStream("sound\\global.lvl", "rep_unit_vo_slow")
AudioStreamAppendSegments("sound\\global.lvl", "cis_unit_vo_slow", voiceSlow)
AudioStreamAppendSegments("sound\\global.lvl", "global_vo_slow", voiceSlow)

voiceQuick = OpenAudioStream("sound\\global.lvl", "rep_unit_vo_quick")
AudioStreamAppendSegments("sound\\global.lvl", "cis_unit_vo_quick", voiceQuick)

OpenAudioStream("sound\\global.lvl", "cw_music")
-- OpenAudioStream("sound\\global.lvl", "global_vo_quick")
-- OpenAudioStream("sound\\global.lvl", "global_vo_slow")
-- OpenAudioStream("sound\\yav.lvl", "yav1")
-- OpenAudioStream("sound\\yav.lvl", "yav1")
-- OpenAudioStream("sound\\yav.lvl", "yav1_emt")
--OpenAudioStream("dc:sound\\tat.lvl", "tat2")
--OpenAudioStream("dc:sound\\tat.lvl", "tat2")
OpenAudioStream("sound\\dag.lvl", "dag1")
OpenAudioStream("sound\\dag.lvl", "dag1")
OpenAudioStream("sound\\dag.lvl", "dag1_emt")
-- OpenAudioStream("sound\\kam.lvl", "kam1")
-- OpenAudioStream("sound\\kam.lvl", "kam1")

SetBleedingVoiceOver(REP, REP, "rep_off_com_report_us_overwhelmed", 1)
SetBleedingVoiceOver(REP, CIS, "rep_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(CIS, REP, "cis_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(CIS, CIS, "cis_off_com_report_us_overwhelmed", 1)

SetOutOfBoundsVoiceOver(2, "cisleaving")
SetOutOfBoundsVoiceOver(1, "repleaving")

SetAmbientMusic(REP, 1.0, "rep_dag_amb_start", 0,1)
SetAmbientMusic(REP, 0.8, "rep_dag_amb_middle", 1,1)
SetAmbientMusic(REP, 0.2, "rep_dag_amb_end", 2,1)
SetAmbientMusic(CIS, 1.0, "cis_dag_amb_start", 0,1)
SetAmbientMusic(CIS, 0.8, "cis_dag_amb_middle", 1,1)
SetAmbientMusic(CIS, 0.2, "cis_dag_amb_end", 2,1)

SetVictoryMusic(REP, "rep_dag_amb_victory")
SetDefeatMusic (REP, "rep_dag_amb_defeat")
SetVictoryMusic(CIS, "cis_dag_amb_victory")
SetDefeatMusic (CIS, "cis_dag_amb_defeat")

SetSoundEffect("ScopeDisplayZoomIn", "binocularzoomin")
SetSoundEffect("ScopeDisplayZoomOut", "binocularzoomout")
--SetSoundEffect("BirdScatter", "birdsFlySeq1")
--SetSoundEffect("WeaponUnableSelect", "com_weap_inf_weaponchange_null")
--SetSoundEffect("WeaponModeUnableSelect", "com_weap_inf_modechange_null")
SetSoundEffect("SpawnDisplayUnitChange", "shell_select_unit")
SetSoundEffect("SpawnDisplayUnitAccept", "shell_menu_enter")
SetSoundEffect("SpawnDisplaySpawnPointChange", "shell_select_change")
SetSoundEffect("SpawnDisplaySpawnPointAccept", "shell_menu_enter")
SetSoundEffect("SpawnDisplayBack", "shell_menu_exit")



--OpeningSateliteShot
AddCameraShot(0.953374, -0.267720, 0.134110, 0.037660, -54.391048, 22.637020, -112.560837);
AddCameraShot(0.190180, -0.039485, -0.960472, -0.199413, -23.582567, 18.165585, -59.159462);
AddCameraShot(0.166568, 0.008194, -0.984805, 0.048446, -52.621288, -3.707588, 71.935303);
AddCameraShot(0.921100, 0.181319, -0.338038, 0.066543, 85.826782, -3.707588, 89.593933);
AddCameraShot(0.760499, -0.074656, 0.641947, 0.063018, 48.234692, -1.620878, 7.359371);
end


antipower = function( player )

local unit = GetCharacterUnit(player)
print("Getting player position:")
local unitLocation = GetEntityMatrix( unit )
--get the player's spawn position
--local player_pos = GetEntityMatrix(player)
print("Player position: ")
print(unitLocation)
CreateEntity("com_item_powerup_antiammo", unitLocation, "antiammo")
-- SetEntityMatrix("antiarmor", unitLocation)
-- SetEntityMatrix("antiammo", unitLocation)
SetProperty(unit, "CurShield", 0)

end

GetPlayersAlive = function(self)

return (GetNumTeamMembersAlive(1) + GetNumTeamMembersAlive(2))

end

RunTimers = function(self)

--get the path point
cp1_ammospawn1 = GetPathPoint("cp1_spawn", 0) --GetPathPoint(Pathname, node)
cp1_ammospawn2 = GetPathPoint("cp1_spawn", 1)
cp2_ammospawn1 = GetPathPoint("cp2_spawn", 0)
cp2_ammospawn2 = GetPathPoint("cp2_spawn", 1)
cp3_ammospawn1 = GetPathPoint("cp3_spawn", 0)
cp3_ammospawn2 = GetPathPoint("cp3_spawn", 1)
cp4_ammospawn1 = GetPathPoint("cp4_spawn", 0)
cp4_ammospawn2 = GetPathPoint("cp4_spawn", 1)
sammo_spawn1 = GetPathPoint("special_ammo_spawn", 0)
sammo_spawn2 = GetPathPoint("special_ammo_spawn", 1)
sammo_spawn3 = GetPathPoint("special_ammo_spawn", 2)
sammo_spawn4 = GetPathPoint("special_ammo_spawn", 3)

cp1_powerspawn1 = CreateTimer("cp1_powerspawn1")
SetTimerValue(cp1_powerspawn1, 90)
OnTimerElapse(
function(timer)
CreateEntity("com_item_powerup_dual", cp1_ammospawn1, "ammo1") --CreateEntity(class, node, name)
SetTimerValue(cp1_powerspawn1, 90)
StartTimer(cp1_powerspawn1)
end,
cp1_powerspawn1
)

cp1_powerspawn2 = CreateTimer("cp1_powerspawn2")
SetTimerValue(cp1_powerspawn2, 90)
OnTimerElapse(
function(timer)
CreateEntity("com_item_powerup_dual", cp1_ammospawn2, "ammo2")
SetTimerValue(cp1_powerspawn2, 110)
StartTimer(cp1_powerspawn2)
end,
cp1_powerspawn2
)

cp2_powerspawn1 = CreateTimer("cp2_powerspawn1")
SetTimerValue(cp2_powerspawn1, 90)
OnTimerElapse(
function(timer)
CreateEntity("com_item_powerup_dual", cp2_ammospawn1, "ammo3")
SetTimerValue(cp2_powerspawn1, 80)
StartTimer(cp2_powerspawn1)
end,
cp2_powerspawn1
)

cp2_powerspawn2 = CreateTimer("cp2_powerspawn2")
SetTimerValue(cp2_powerspawn2, 90)
OnTimerElapse(
function(timer)
CreateEntity("com_item_powerup_dual", cp2_ammospawn2, "ammo4")
SetTimerValue(cp2_powerspawn2, 120)
StartTimer(cp2_powerspawn2)
end,
cp2_powerspawn2
)

cp3_powerspawn1 = CreateTimer("cp3_powerspawn1")
SetTimerValue(cp3_powerspawn1, 90)
OnTimerElapse(
function(timer)
CreateEntity("com_item_powerup_dual", cp3_ammospawn1, "ammo5")
SetTimerValue(cp3_powerspawn1, 150)
StartTimer(cp3_powerspawn1)
end,
cp3_powerspawn1
)

cp3_powerspawn2 = CreateTimer("cp3_powerspawn2")
SetTimerValue(cp3_powerspawn2, 90)
OnTimerElapse(
function(timer)
CreateEntity("com_item_powerup_dual", cp3_ammospawn2, "ammo6")
SetTimerValue(cp3_powerspawn2, 90)
StartTimer(cp3_powerspawn2)
end,
cp3_powerspawn2
)

cp4_powerspawn1 = CreateTimer("cp4_powerspawn1")
SetTimerValue(cp4_powerspawn1, 90)
OnTimerElapse(
function(timer)
CreateEntity("com_item_powerup_dual", cp4_ammospawn1, "ammo7")
SetTimerValue(cp4_powerspawn1, 100)
StartTimer(cp4_powerspawn1)
end,
cp4_powerspawn1
)

cp4_powerspawn2 = CreateTimer("cp4_powerspawn2")
SetTimerValue(cp4_powerspawn2, 90)
OnTimerElapse(
function(timer)
CreateEntity("com_item_powerup_dual", cp4_ammospawn2, "ammo8")
SetTimerValue(cp4_powerspawn2, 60)
StartTimer(cp4_powerspawn2)
end,
cp4_powerspawn2
)

spec_powerup1 = CreateTimer("spec_powerup1")
SetTimerValue(spec_powerup1, 1)
OnTimerElapse(
function(timer)
CreateEntity("com_item_powerup_full", sammo_spawn1, "full") --CreateEntity(class, node, name)
SetTimerValue(spec_powerup1, 31)
StartTimer(spec_powerup1)
end,
spec_powerup1
)

spec_powerup2 = CreateTimer("spec_powerup2")
SetTimerValue(spec_powerup2, 1)
OnTimerElapse(
function(timer)
CreateEntity("com_item_powerup_inv", sammo_spawn2, "invinc") --CreateEntity(class, node, name)
SetTimerValue(spec_powerup2, 31)
StartTimer(spec_powerup2)
end,
spec_powerup2
)

spec_powerup3 = CreateTimer("spec_powerup3")
SetTimerValue(spec_powerup3, 1)
OnTimerElapse(
function(timer)
CreateEntity("com_item_powerup_onehit", sammo_spawn3, "onehit") --CreateEntity(class, node, name)
SetTimerValue(spec_powerup3, 31)
StartTimer(spec_powerup3)
end,
spec_powerup3
)

spec_powerup4 = CreateTimer("spec_powerup4")
SetTimerValue(spec_powerup4, 1)
OnTimerElapse(
function(timer)
CreateEntity("com_item_powerup_armor", sammo_spawn4, "armor") --CreateEntity(class, node, name)
SetTimerValue(spec_powerup4, 31)
StartTimer(spec_powerup4)
end,
spec_powerup4
)

StartTimer(cp1_powerspawn1)
StartTimer(cp1_powerspawn2)
StartTimer(cp2_powerspawn1)
StartTimer(cp2_powerspawn2)
StartTimer(cp3_powerspawn1)
StartTimer(cp3_powerspawn2)
StartTimer(cp4_powerspawn1)
StartTimer(cp4_powerspawn2)
StartTimer(spec_powerup1)
StartTimer(spec_powerup2)
StartTimer(spec_powerup3)
StartTimer(spec_powerup4)

end


function StartObjectives()
objectiveSequence = MultiObjectiveContainer:New{delayVictoryTime = 6.0 }
objectiveSequence:AddObjectiveSet(GoToStart)
objectiveSequence:AddObjectiveSet(GracePeriod)
objectiveSequence:AddObjectiveSet(HungerGames)
objectiveSequence:Start()
end

Re: Hunger Games Scripting

Posted: Fri Apr 04, 2014 2:09 pm
by [RDH]Zerted
Never use math.random() unless you're in the shell or have limited your map to SP only. Use ScriptCB_random() instead.

Re: Hunger Games Scripting

Posted: Fri Apr 04, 2014 2:11 pm
by Marth8880
Wait, what does ScriptCB_random() do? :o

Re: Hunger Games Scripting

Posted: Fri Apr 04, 2014 2:26 pm
by LRKfm946
I should probably make this thread up to date:

I no longer have the jump issue and I'm no longer using objectives, so all those issues are gone. Here's my current LUA:
Hidden/Spoiler:
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

-- load the gametype script
ScriptCB_DoFile("setup_teams")
ScriptCB_DoFile("ObjectiveConquest")

loadscreen = ScriptCB_random(1,3)


---------------------------------------------------------------------------
-- ScriptPostLoad
---------------------------------------------------------------------------
function ScriptPostLoad()


weather()

--ScriptCB_Freecamera()

cp1 = CommandPost:New{name = "cp1"}
cp2 = CommandPost:New{name = "cp2"}
cp3 = CommandPost:New{name = "cp3"}
cp4 = CommandPost:New{name = "cp4"}
cp_center = CommandPost:New{name = "cp_center"}
cp_center1 = CommandPost:New{name = "cp_center1"}
cp_center2 = CommandPost:New{name = "cp_center2"}

--This sets up the actual objective. This needs to happen after cp's are defined
conquest = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF,
textATT = "level.HGS.games1",
textDEF = "level.HGS.games2",
multiplayerRules = true}

--This adds the CPs to the objective. This needs to happen after the objective is set up
conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
conquest:AddCommandPost(cp4)
conquest:AddCommandPost(cp_center)
conquest:AddCommandPost(cp_center1)
conquest:AddCommandPost(cp_center2)

players_alive = {}
players_eliminated = {}
players = {}

debug_on = true

playerReg = true
gracePeriod = false
gamesStarted = false

numPlayersAlive = 0
numRegisteredPlayers = 0

print("Conquest is about to start")
conquest:Start()

--Turn on the registration regions
ActivateRegion("register2")
ActivateRegion("team2_capture")

--set up variables
local destLoc = GetEntityMatrix("cp_center")
local teleBack = GetPathPoint("cp_center1_spawn", 0)
print("teleBack is: ", teleBack)
local i = 1

--if this is false, the timer shouldn't be running, and nobody should be registered
regOpen = false
--if this is true, no players have registered yet, so the timer shouldn't be running
firstReg = true

--timer for registration period
registrationTimer = CreateTimer("registrationTimer")
SetTimerValue(registrationTimer, 20)

SetProperty("registration_switch", "CurHealth", 4)
SetTeamAsFriend(1, 2)
SetTeamAsFriend(2, 1)
AllowAISpawn(1, false)
AllowAISpawn(2, false)
SetClassProperty("com_bldg_controlzone", "NeutralizeTime", 999999)
SetClassProperty("com_bldg_controlzone", "CaptureTime", 999999)
SetClassProperty("com_bldg_major_controlzone", "NeutralizeTime", 999999)
SetClassProperty("com_bldg_major_controlzone", "CaptureTime", 999999)


VisualTimer = CreateTimer("VisualTimer")
ShowTimer(VisualTimer)
SetTimerValue(VisualTimer, 20)

print("Setting up some super powerups: ")


SetClassProperty("com_inf_default", "NextDropItem", "-")
SetClassProperty("com_inf_default", "DropItemClass", "com_item_powerup_armor")
SetClassProperty("com_inf_default", "DropItemProbability", 0.3)

shieldDropCnt = 0 -- debug variable used to count # times item is dropped

OnFlagPickUp(
function(flag, character)
print("ShieldRegen: Unit picked up flag")
local charPtr = GetCharacterUnit(character)

if GetEntityClass(flag) == FindEntityClass("com_item_powerup_armor") then
ShowMessageText("level.HGS.debug.pickuparmor") -- debug text
--SetProperty(charPtr, "AddShield", 175)

local curShields = GetObjectShield(charPtr)
local newShields = 0
print("ShieldRegen: Unit's current shields: ", curShields)
if curShields > 500 then
newShields = 1000
else
newShields = curShields + 500
end

SetProperty(charPtr, "CurShield", newShields)
print("ShieldRegen: Unit's new shields: ", newShields)

KillObject(flag)

shieldDropCnt = shieldDropCnt + 1
print("ShieldRegen: Shield drop count: "..shieldDropCnt)

-- local shieldPfx = CreateEffect("com_sfx_pickup_shield")
-- local charPos = GetEntityMatrix(charPtr)
-- AttachEffectToMatrix(shieldPfx, charPos)

--[[local shieldTimer = CreateTimer("shieldTimer")
SetTimerValue(shieldTimer, 1)
StartTimer(shieldTimer)
local shield_timer = OnTimerElapse(
function(timer)
print("ShieldRegen: Shield regen complete")
ShowMessageText("level.common.events.debug.noregen") -- debug text
SetProperty(charPtr, "AddShield", 0)

DestroyTimer(timer)
end,
shieldTimer
)]]
elseif GetEntityClass(flag) == FindEntityClass("com_item_powerup_adrenaline") then
print("A player has picked up the adrenaline flag.")

print("Setting new movement values.")
SetProperty(charPtr, "MaxSpeed", 15.0)
SetProperty(charPtr, "MaxStrafeSpeed", 7.0)
SetProperty(charPtr, "JumpHeight", 2.23)
SetProperty(charPtr, "JumpForwardSpeedFactor", 1.5)
SetProperty(charPtr, "JumpStrafeSpeedFactor", 1.3)
SetProperty(charPtr, "RollSpeedFactor", 1.8)
SetProperty(charPtr, "Acceleration", 100.0)
SetProperty(charPtr, "SprintAccelerateTime", 0.30)
SetProperty(charPtr, "EnergyRestore", 25.0)

-- SetProperty(unit, "MaxShield", self.maxShield or 900 )

-- --set the shield regeneration rate
-- SetProperty(unit, "AddShield", self.addShield or 160 )

-- --set the health regeneration rate
-- SetProperty(unit, "AddHealth", self.addHealth or 50 )

-- --set the energy regeneration rate, common to both MP and SP
-- SetProperty(unit, "EnergyRestore", self.energyRestore or 9 )

print("Done changing values.")

KillObject(flag)
adrTimer = CreateTimer("adrTimer")
SetTimerValue(adrTimer, 45)
OnTimerElapse(
function(timer)
print("Adrenaline time is up, restoring values.")
SetProperty(charPtr, "MaxSpeed", 7.0)
SetProperty(charPtr, "MaxStrafeSpeed", 5.25)
SetProperty(charPtr, "JumpHeight", 1.78)
SetProperty(charPtr, "JumpForwardSpeedFactor", 1.3)
SetProperty(charPtr, "JumpStrafeSpeedFactor", 1.0)
SetProperty(charPtr, "RollSpeedFactor", 1.5)
SetProperty(charPtr, "Acceleration", 70.0)
SetProperty(charPtr, "SprintAccelerateTime", 0.35)
SetProperty(charPtr, "EnergyRestore", 10.0)
print("Done restoring values.")
end,
adrTimer)
StartTimer(adrTimer)
end
end
)





--==============================--
---***GRACE PERIOD TIMERS***---
--==============================--

ReadRules = CreateTimer("ReadRules")
SetTimerValue(ReadRules, 6)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.gp2")
DestroyTimer(ReadRules)
StartTimer(ReadRules2)
end,
ReadRules
)

ReadRules2 = CreateTimer("ReadRules2")
SetTimerValue(ReadRules2, 6)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.gp3")
DestroyTimer(ReadRules2)
StartTimer(ReadRules3)
end,
ReadRules2
)

ReadRules3 = CreateTimer("ReadRules3")
SetTimerValue(ReadRules3, 5)
OnTimerElapse(
function(timer)
print("Moving all players to team 1")
for i = 1, table.getn(players_alive) do

if not players_alive then
print("something went wrong, this player doesn't exist!")
else
SetProperty(players_alive.playerUnit, "Team", 1)
SetProperty(players_alive.playerUnit, "PerceivedTeam", 1)
print("This player's team is now: ", GetCharacterTeam(players_alive.playerChar))
end
end
ShowMessageText("level.HGS.gp_count")
DestroyTimer(ReadRules3)
ShowMessageText("level.HGS.countdown3")
StartTimer(countdown3_gp)
end,
ReadRules3
)

countdown3_gp = CreateTimer("countdown3_gp")
SetTimerValue(countdown3_gp, 1)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.countdown2")
DestroyTimer(countdown3_gp)
StartTimer(countdown2_gp)
end,
countdown3_gp
)

countdown2_gp = CreateTimer("countdown2_gp")
SetTimerValue(countdown2_gp, 1)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.countdown1")
DestroyTimer(countdown2_gp)
StartTimer(countdown1_gp)
end,
countdown2_gp
)

countdown1_gp = CreateTimer("countdown1_gp")
SetTimerValue(countdown1_gp, 1)
OnTimerElapse(
function(timer)
print("The grace period has begun.")
armorspawn()
ShowMessageText("level.HGS.gp_begin")
MapRemoveEntityMarker("cp_center")
DestroyTimer(countdown1_gp)
StartTimer(GracePeriodTimer)
SetTimerValue(VisualTimer, 30)
StartTimer(VisualTimer)
KillObject("com_inv_col_16_con1")
KillObject("com_inv_col_16_con2")
KillObject("com_inv_col_16_con3")
KillObject("com_inv_col_16_con4")
KillObject("com_inv_col_16_con")
end,
countdown1_gp
)

GracePeriodTimer = CreateTimer("GracePeriodTimer")
SetTimerValue(GracePeriodTimer, 27)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.countdown3")
DestroyTimer(GracePeriodTimer)
StartTimer(countdown3_hg)
end,
GracePeriodTimer
)

countdown1_hg = CreateTimer("countdown1_hg")
SetTimerValue(countdown1_hg, 1)
OnTimerElapse(
function(timer)
DestroyTimer(countdown1_hg)
gracePeriod = false
gamesStarted = true

print("The Games have begun!\n")
ShowMessageText("level.HGS.games_begun", 1)
ShowMessageText("level.HGS.games_begun", 2)
SetTeamAsEnemy(1, 1)
SetTeamAsEnemy(1, 2)
SetTeamAsEnemy(2, 1)
SetTeamAsEnemy(2, 2)
SetTeamAsEnemy(3, 3)

cpAmmoSpawn()
superpowers()
ammospawn()
feast()

end,
countdown1_hg
)

countdown2_hg = CreateTimer("countdown2_hg")
SetTimerValue(countdown2_hg, 1)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.countdown1", 1)
ShowMessageText("level.HGS.countdown1", 2)
DestroyTimer(countdown2_hg)
StartTimer(countdown1_hg)
end,
countdown2_hg
)

countdown3_hg = CreateTimer("countdown3_hg")
SetTimerValue(countdown3_hg, 1)
OnTimerElapse(
function(timer)
ShowMessageText("level.HGS.countdown2", 1)
ShowMessageText("level.HGS.countdown2", 2)
DestroyTimer(countdown3_hg)
StartTimer(countdown2_hg)
end,
countdown3_hg
)


--=================================================================--
------*******************PLAYER REGISTRATION*******************------
--=================================================================--

-- ShowMessageText("level.HGS.gotostart")

-- GoToMessage = CreateTimer("GoToMessage")
-- SetTimerValue(GoToMessage, 15)
-- OnTimerElapse(
-- function(timer)
-- ShowMessageText("level.HGS.gotostart", 1)
-- ShowMessageText("level.HGS.gotostart", 2)
-- SetTimerValue(GoToMessage, 15)
-- StartTimer(GoToMessage)
-- end,
-- GoToMessage
-- )
-- StartTimer(GoToMessage)
--StartTimer(CheckPlayerCount)



OnCharacterSpawn(
function(character)
print("Someone spawned.")
local charUnit = GetCharacterUnit(character)
--ShowObjectiveTextPopup("level.HGS.intro_popup")
testArmor()
print("\tTaking away their sheilds")
antipower(character)
playerInfo = {
playerChar = character,
playerUnit = charUnit,
playerTeam = GetCharacterTeam(character),
registered = false,
playerClass = GetCharacterClass(character)--,
--playerName = ReturnName(charUnit)
}

if table.getn(players_alive) == 0 then
print("\tThis is the first person to spawn, adding to players_alive.\n")
table.insert(players_alive, playerInfo)
else
print("\tchecking if they're already in players_alive")
for i = 1, table.getn(players_alive) do
if not players_alive then
print("\tsomething went wrong, this player doesn't exist!\n")
elseif players_alive.playerChar == character then
print("\tThis person's already in the list!")

print("\tSetting his registration to: ", players_alive.registered)
playerInfo.registered = players_alive.registered
print("\tthe player's registration is now ", players_alive.registered)

print("\tReplacing him in the list")
table.remove(players_alive, i)
table.insert(players_alive, playerInfo)

numRegisteredPlayers = GetNumRegisteredPlayers(players_alive)
print("\tThere are now this many registered players: ", numRegisteredPlayers)
print(" ")
else
print("\tThe player isn't in players_alive yet, adding him now.")
table.insert(players_alive, playerInfo)
end
end
end
end
)




function ResetRegistration()
print("Resetting registration")

--resetting the registration timer
StopTimer(registrationTimer)
SetTimerValue(registrationTimer, 20)
StopTimer(VisualTimer)
SetTimerValue(VisualTimer, 20)

MapRemoveRegionMarker("register2")
MapRemoveRegionMarker("team2_capture")

regOpen = false
firstReg = true

print("\tregOpen is now ", regOpen)
print("\tfirstReg is now ", firstReg)
print(" ")

--teleport each player that is registered back to the waiting room
for i = 1, table.getn(players_alive) do

if not players_alive then
print("something went wrong, this player doesn't exist!")
else
print("\tTeleporting character back to start: ", players_alive[i].playerUnit)
local teleUnit = GetCharacterUnit(players_alive[i].playerChar)
SetEntityMatrix(teleUnit, teleBack)

print("\tUnregistering him now")
players_alive[i].registered = false
print("\tthe player's registration is now ", players_alive[i].registered)
print("\tthe player has been safely teleported back")

numRegisteredPlayers = GetNumRegisteredPlayers(players_alive)
print("\tThere are now this many registered players: ", numRegisteredPlayers)
print(" ")
end
end
end


OnTimerElapse(
function(timer)
numRegisteredPlayers = GetNumRegisteredPlayers(players_alive)
--if there are enough players registered (more than 1), the games can start
if (numRegisteredPlayers > 0) then

print("We have enough people, let's play.\n")

--Destroy the registration zones/regions
MapRemoveRegionMarker("register2")
MapRemoveRegionMarker("team2_capture")

KillObject("com_bldg_ctfbase2")
KillObject("com_bldg_ctfbase3")
DeactivateRegion("register2")
DeactivateRegion("team2_capture")

--stop the registration message
--StopTimer(GoToMessage)
--DestroyTimer(GoToMessage)
StopTimer(registrationTimer)
DestroyTimer(registrationTimer)

print("\nKilling unregistered players")
for i = 1, table.getn(players_alive) do
if not players_alive[i] then
print("\tsomething went wrong, this player doesn't exist!")

else if players_alive[i].registered == false then

print("\tThis player is not registered, kill them: ", players_alive[i].playerUnit)
KillObject(players_alive[i].playerUnit)

end
end
print("\tchecked a player")
end
print("Done killing unregistered players.\n")

regOpen = false
playerReg = false
gracePeriod = true

numPlayersAlive = table.getn(players_alive)

KillObject("registration_switch")
ActivateObject("com_inv_col_16_con1")
ActivateObject("com_inv_col_16_con2")
ActivateObject("com_inv_col_16_con3")
ActivateObject("com_inv_col_16_con4")
ActivateObject("com_inv_col_16_con")
SetClassProperty("com_bldg_controlzone", "NeutralizeTime", 1)
SetClassProperty("com_bldg_major_controlzone", "NeutralizeTime", 1)

SetProperty(players_alive[1].playerUnit, "Team", 1)
SetProperty(players_alive[1].playerUnit, "PerceivedTeam", 1)
--SetProperty(players_alive[2].playerUnit, "Team", 2)
--SetProperty(players_alive[2].playerUnit, "PerceivedTeam", 2)

SetTimerValue(VisualTimer, 20)
StartTimer(VisualTimer)
StartTimer(ReadRules)

ShowMessageText("level.HGS.gp1")

else
print("Not enough people.")
ResetRegistration()
print("Registration is now CLOSED", regOpen)
print("\n")
ShowMessageText("level.HGS.regclosed")
ShowMessageText("level.HGS.reset")
end
end,
registrationTimer
)

OnObjectKill(
function(object, killer)

local name = GetEntityName(object)
if name == "registration_switch" then
if not gracePeriod then
RespawnObject("registration_switch")
end
SetProperty("registration_switch", "CurHealth", 4)
if not killer then return end --do nothing if no killer
if not IsCharacterHuman(killer) then return end --do nothing unless killer is a human
print("Someone hit the switch. Registration is now: ")
if regOpen == true then
regOpen = false
firstReg = true
ResetRegistration()
print("Registration is now CLOSED", regOpen)
print("\n")
ShowMessageText("level.HGS.regclosed")
ShowMessageText("level.HGS.reset")

elseif regOpen == false then
MapAddRegionMarker("register2", "hud_objective_icon", 3.0, 1, "YELLOW", true, true, true)
MapAddRegionMarker("team2_capture", "hud_objective_icon", 3.0, 2, "YELLOW", true, true, true)

regOpen = true
print("OPEN", regOpen)
print("\n")
ShowMessageText("level.HGS.regopen")
end
end
end
)


regTele1 = OnEnterRegion(
function(region, character)
if regOpen == true then
print("A player has entered the player 1 region")
--deactivating regions temporarily to prevent double-registration
DeactivateRegion("register2")
DeactivateRegion("team2_capture")

if IsCharacterHuman(character) then

local charUnit = GetCharacterUnit(character)
SetEntityMatrix(charUnit, destLoc)

print("\tFinding the character in the players_alive list")
for i = 1, table.getn(players_alive) do

if not players_alive[i] then
print("something went wrong, this player doesn't exist!")
else if character == players_alive[i].playerChar then
print("\tFound him, registering him now")
players_alive[i].registered = true
print("\tThe player is registered:", players_alive[i].registered)
numRegisteredPlayers = GetNumRegisteredPlayers(players_alive)
print("\tThere are now this many registered players: ", numRegisteredPlayers)
ShowMessageText("level.HGS.entered")
end
end
end



if firstReg then
print("\tFirst player registered, starting timer.\n")
firstReg = false
StartTimer(registrationTimer)
StartTimer(VisualTimer)
else
print("\tNew player registered, resetting timer value\n")
SetTimerValue(registrationTimer, 20)
SetTimerValue(VisualTimer, 20)
end
end
ActivateRegion("register2")
ActivateRegion("team2_capture")
end
end,
"team2_capture")

regTele2 = OnEnterRegion(
function(region, character)
if regOpen == true then

print("A player has entered the player 2 region")
--deactivating regions temporarily to prevent double-registration
DeactivateRegion("register2")
DeactivateRegion("team2_capture")

if IsCharacterHuman(character) then

local charUnit = GetCharacterUnit(character)
SetEntityMatrix(charUnit, destLoc)

print("\tFinding the character in the players_alive list")
for i = 1, table.getn(players_alive) do

if not players_alive[i] then
print("something went wrong, this player doesn't exist!")
else if character == players_alive[i].playerChar then
print("\tFound him, registering him now")
players_alive[i].registered = true
print("\tThe player is registered:", players_alive[i].registered)
numRegisteredPlayers = GetNumRegisteredPlayers(players_alive)
print("\tThere are now this many registered players: ", numRegisteredPlayers)
ShowMessageText("level.HGS.entered")
end
end
end

if firstReg then
print("\tFirst player registered, starting timer.\n")
firstReg = false
StartTimer(registrationTimer)
StartTimer(VisualTimer)
else
print("\tNew player registered, resetting timer value\n")
SetTimerValue(registrationTimer, 20)
SetTimerValue(VisualTimer, 20)
end
end
ActivateRegion("register2")
ActivateRegion("team2_capture")
end
end,
"register2")
--RespawnObject("com_bldg_ctfbase2")
--MapRemoveEntityMarker("cp_center")

-- if uf_processPlayers then
-- uf_processPlayers(players_alive)
-- print(players_alive)
-- else
-- show("Player list wasn't created")
-- end

-- SetClassProperty("com_bldg_major_controlzone", "CaptureTime", 999999)
-- SetProperty("cp_center", "CaptureRegion", "cp_center_capture")
-- SetObjectTeam("cp_center", 0)



--=================================================================--
------*******************HUNGER GAMES STUFFS*******************------
--=================================================================--

OnCharacterDeath( --THIS could happen anywhere, in or oustide the arena
function(character)
print("Ruh roh, someone died.")
numPlayersAlive = GetPlayersAlive()
--even if a guy dies, we still need to de-register him and stuff.

--1. If the games haven't started, simply remove him from players_alive
if playerReg == true then
print("\tPlayer registration is open, so we'll just remove him from players_alive.")
local e
for e = 1, table.getn(players_alive) do
if character == players_alive[e].playerChar then
--print("(\tNow pretending to remove the player from players_alive, bla bla bla)\n")
print("\tFound the player, is he registered?", players_alive[e].registered)
print("\tRemoving the player from players_alive")
table.remove(players_alive, e)
numRegisteredPlayers = GetNumRegisteredPlayers(players_alive)
print("\tThere are now this many registered players: ", numRegisteredPlayers)
print(" ")
end
end


--2. If the games have started, then this player must be assigned a rank
else
print("\tThe games have started, so we need to add him to the dead people list.")
local f
for f = 1, table.getn(players_alive) do
if character == players_alive[f].playerChar then
print("\tFound him, creating his info table and adding him to players_eliminated")
playerInfo = {playerChar = character,
playerRank = table.getn(players_eliminated)+1}
table.insert(players_eliminated, playerInfo)
print("\tRemoving him from players alive")
table.remove(players_alive, f)
numPlayersAlive = table.getn(players_alive)
addPointsToChar(character, playerInfo.playerRank)
print("\tThere are now this many players alive: ", numPlayersAlive)
end
end


--3. If there's only 1 player left alive, then the game is over, that player is the winner
if table.getn(players_alive) <= 0 then
print("\n\tThere's only one person left alive!! He's the winner!")
if not players_alive[1] then
print("something went wrong, player not found")
else
local charUnit = players_alive[1].playerUnit
addPointsToChar(players_alive[1].playerChar, 100)
SetProperty(charUnit, "Team", 2)
SetProperty(charUnit, "PerceivedTeam", 2)
SetReinforcementCount(1, 1)
AddReinforcements(1, -1)
end
SetReinforcementCount(1, 1)
AddReinforcements(1, -1)
end
end
end
)



SafetyCheck = CreateTimer("SafetyCheck")
SetTimerValue(SafetyCheck, 20)
OnTimerElapse(
function(timer)
print("performing safety check")
local f
for f = 1, table.getn(players_alive) do
if not players_alive[f] then
print("something went wrong, player not found")
else if IsObjectAlive(players_alive[f].playerUnit) then
print("This player's still alive!")
else
table.remove(players_alive, f)
numRegisteredPlayers = numRegisteredPlayers - 1
end
end
if not playerReg then
if table.getn(players_alive) <= 0 then
print("\n\tThere's only one person left alive!! He's the winner!")
if not players_alive[1] then
print("something went wrong, player not found")
else
local charUnit = players_alive[1].playerUnit
addPointsToChar(players_alive[1].playerChar, 100)
SetProperty(charUnit, "Team", 2)
SetProperty(charUnit, "PerceivedTeam", 2)
SetReinforcementCount(1, 1)
AddReinforcements(1, -1)
end
SetReinforcementCount(1, 1)
AddReinforcements(1, -1)
end
if GetPlayersAlive() <= 0 then
print("Something's gone terribly wrong, ending the map now")
print("Setting Team 1 reinforcements to 0. The round SHOULD end now.")
SetReinforcementCount(1, 1)
AddReinforcements(1, -1)
end
end
end

SetTimerValue(SafetyCheck, 20)
StartTimer(SafetyCheck)
end,
"SafetyCheck")
StartTimer(SafetyCheck)


print("End of post script\n")
end

function weather()
WeatherMode = ScriptCB_random(1,3)
if WeatherMode == 1 then
ReadDataFile("dc:HGS\\HGS_sky.lvl", "norm")
elseif WeatherMode == 2 then
ReadDataFile("dc:HGS\\HGS_sky.lvl", "rain")
elseif WeatherMode == 3 then
ReadDataFile("dc:HGS\\HGS_sky.lvl", "night")
end
end

---------------------------------------------------------------------------
-- FUNCTION: ScriptInit
-- PURPOSE: This function is only run once
-- INPUT:
-- OUTPUT:
-- NOTES: The name, 'ScriptInit' is a chosen convention, and each
-- mission script must contain a version of this function, as
-- it is called from C to start the mission.
---------------------------------------------------------------------------
function ScriptInit()

if loadscreen == 1 then
ReadDataFile("dc:LoadS\\common.lvl")
elseif loadscreen == 2 then
ReadDataFile("dc:LoadT\\common.lvl")
elseif loadscreen == 3 then
ReadDataFile("dc:LoadF\\common.lvl")
-- else
-- ReadDataFile("dc:LoadM\\common.lvl")
end

ReadDataFile("ingame.lvl")
ReadDataFile("dc:ingame.lvl")

CIS = 1
REP = 2
--HGS = 3
-- These variables do not change
--ATT = 1 and 2
--DEF = 3


SetMaxFlyHeight(33)
SetMaxPlayerFlyHeight (33)

SetMemoryPoolSize ("ClothData",20)
SetMemoryPoolSize ("Combo",50) -- should be ~ 2x number of jedi classes
SetMemoryPoolSize ("Combo::State",650) -- should be ~12x #Combo
SetMemoryPoolSize ("Combo::Transition",650) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Condition",650) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Attack",550) -- should be ~8-12x #Combo
SetMemoryPoolSize ("Combo::DamageSample",6000) -- should be ~8-12x #Combo::Attack
SetMemoryPoolSize ("Combo::Deflect",100) -- should be ~1x #combo


ReadDataFile("SIDE\\all.lvl",
"all_inf_rifleman_jungle",
"all_inf_rocketeer_jungle",
"all_inf_sniper_jungle",
"all_inf_engineer_jungle",
"all_inf_officer_jungle",
"all_inf_wookiee")

ReadDataFile("SIDE\\imp.lvl",
"imp_inf_officer",
"imp_inf_dark_trooper")

--ReadDataFile("dc:sound\\hgs.lvl;hgscw")
--ReadDataFile("dc:sound\\kam.lvl;kam1cw")
--ReadDataFile("dc:sound\\yav.lvl;yav1cw")
ReadDataFile("sound\\dag.lvl;dag1cw")
ReadDataFile("dc:sound\\hgs.lvl;hgsgcw")
--ReadDataFile("sound\\dag.lvl;dag1gcw")
ReadDataFile("SIDE\\rep.lvl",
"rep_inf_ep3_rifleman",
"rep_inf_ep3_rocketeer",
"rep_inf_ep3_engineer",
"rep_inf_ep3_sniper",
"rep_inf_ep3_sniper_felucia",
"rep_inf_ep3_officer",
"rep_inf_ep3_jettrooper")

ReadDataFile("SIDE\\cis.lvl",
"cis_inf_rifleman",
"cis_inf_officer")


ReadDataFile("dc:SIDE\\hgs.lvl",
"hgs_rep_inf_ep3_rifleman",
"hgs_rep_inf_ep3_rocketeer",
"hgs_rep_inf_ep3_engineer",
"hgs_rep_inf_ep3_sniper_felucia",
"hgs_rep_inf_ep3_officer",
"hgs_rep_inf_ep3_jettrooper",
"hgs_all_inf_rifleman_jungle",
"hgs_all_inf_rocketeer_jungle",
"hgs_all_inf_engineer_jungle",
"hgs_all_inf_sniper_jungle",
"hgs_cis_inf_rifleman",
"hgs_cis_inf_officer",
"hgs_all_inf_officer_jungle",
"hgs_all_inf_wookiee",
"hgs_imp_inf_officer",
"hgs_imp_inf_dark_trooper")



SetupTeams{
rep = {
team = REP,
units = 16,
reinforcements = -1,
soldier = { "hgs_rep_inf_ep3_rifleman",0, 25},
assault = { "hgs_rep_inf_ep3_rocketeer",0, 16},
engineer = { "hgs_rep_inf_ep3_engineer",0, 16},
sniper = { "hgs_rep_inf_ep3_sniper_felucia",0, 16},
officer = {"hgs_rep_inf_ep3_officer",0, 16},
special = { "hgs_rep_inf_ep3_jettrooper",0, 16},

},
cis = {
team = CIS,
units = 16,
reinforcements = -1,
soldier = { "hgs_all_inf_rifleman_jungle",0, 25},
assault = { "hgs_all_inf_rocketeer_jungle",0, 16},
engineer = { "hgs_all_inf_engineer_jungle",0, 16},
sniper = { "hgs_all_inf_sniper_jungle",0, 16},
officer = {"hgs_all_inf_officer_jungle",0, 16},
special = { "hgs_all_inf_wookiee",0, 16},
}
}

AddUnitClass(CIS, "hgs_cis_inf_rifleman", 0, 16)
AddUnitClass(CIS, "hgs_cis_inf_officer", 0, 16)
AddUnitClass(REP, "hgs_imp_inf_officer", 0, 16)
AddUnitClass(REP, "hgs_imp_inf_dark_trooper", 0, 16)

-- Level Stats
-- ClearWalkers()
AddWalkerType(0, 4) -- special -> droidekas
AddWalkerType(1, 0) -- 1x2 (1 pair of legs)
AddWalkerType(2, 0) -- 2x2 (2 pairs of legs)
AddWalkerType(3, 0) -- 3x2 (3 pairs of legs)
local weaponCnt = 1024
SetMemoryPoolSize("Aimer", 75)
SetMemoryPoolSize("AmmoCounter", weaponCnt)
SetMemoryPoolSize("BaseHint", 1024)
SetMemoryPoolSize("EnergyBar", weaponCnt)
SetMemoryPoolSize("EntityCloth", 32)
SetMemoryPoolSize("EntityFlyer", 32)
SetMemoryPoolSize("EntityHover", 32)
SetMemoryPoolSize("EntityLight", 200)
SetMemoryPoolSize("EntitySoundStream", 64)
SetMemoryPoolSize("EntitySoundStatic", 32)
SetMemoryPoolSize("MountedTurret", 32)
SetMemoryPoolSize("Music", 128)
SetMemoryPoolSize("Navigator", 128)
SetMemoryPoolSize("Obstacle", 1024)
SetMemoryPoolSize("PathNode", 1024)
SetMemoryPoolSize("SoldierAnimation", 1800)
SetMemoryPoolSize("SoundSpaceRegion", 64)
SetMemoryPoolSize("Timer", 100)
SetMemoryPoolSize("TreeGridStack", 1024)
SetMemoryPoolSize("UnitAgent", 128)
SetMemoryPoolSize("UnitController", 128)
SetMemoryPoolSize("Weapon", weaponCnt)
SetMemoryPoolSize("FlagItem", 512)
SetMemoryPoolSize("PowerupItem", 512)

SetSpawnDelay(10.0, 0.25)
--ReadDataFile("dc:HGS\\HGS.lvl", "HGS_conquest")
ReadDataFile("dc:HGS\\HGS.lvl", "HGS_conquest")
SetDenseEnvironment("false")




-- Sound

SetSoundEffect("ScopeDisplayZoomIn", "binocularzoomin")
SetSoundEffect("ScopeDisplayZoomOut", "binocularzoomout")

voiceSlow = OpenAudioStream("sound\\global.lvl", "rep_unit_vo_slow")
AudioStreamAppendSegments("sound\\global.lvl", "cis_unit_vo_slow", voiceSlow)
AudioStreamAppendSegments("sound\\global.lvl", "global_vo_slow", voiceSlow)

voiceQuick = OpenAudioStream("sound\\global.lvl", "rep_unit_vo_quick")
AudioStreamAppendSegments("sound\\global.lvl", "cis_unit_vo_quick", voiceQuick)

OpenAudioStream("sound\\global.lvl", "cw_music")
-- OpenAudioStream("sound\\global.lvl", "global_vo_quick")
-- OpenAudioStream("sound\\global.lvl", "global_vo_slow")
-- OpenAudioStream("sound\\yav.lvl", "yav1")
-- OpenAudioStream("sound\\yav.lvl", "yav1")
-- OpenAudioStream("sound\\yav.lvl", "yav1_emt")
--OpenAudioStream("dc:sound\\hgs.lvl", "")
OpenAudioStream("dc:sound\\hgs.lvl", "myg1")
OpenAudioStream("dc:sound\\hgs.lvl", "end1")
OpenAudioStream("dc:sound\\hgs.lvl", "hgs")
OpenAudioStream("sound\\dag.lvl", "dag1")
OpenAudioStream("sound\\dag.lvl", "dag1")
OpenAudioStream("sound\\dag.lvl", "dag1_emt")
-- OpenAudioStream("sound\\kam.lvl", "kam1")
-- OpenAudioStream("sound\\kam.lvl", "kam1")

SetBleedingVoiceOver(REP, REP, "rep_off_com_report_us_overwhelmed", 1)
SetBleedingVoiceOver(REP, CIS, "rep_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(CIS, REP, "cis_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(CIS, CIS, "cis_off_com_report_us_overwhelmed", 1)

SetOutOfBoundsVoiceOver(2, "cisleaving")
SetOutOfBoundsVoiceOver(1, "repleaving")

SetAmbientMusic(REP, 1.0, "rep_dag_amb_start", 0,1)
SetAmbientMusic(REP, 0.8, "rep_dag_amb_middle", 1,1)
SetAmbientMusic(REP, 0.2, "rep_dag_amb_end", 2,1)
SetAmbientMusic(CIS, 1.0, "cis_dag_amb_start", 0,1)
SetAmbientMusic(CIS, 0.8, "cis_dag_amb_middle", 1,1)
SetAmbientMusic(CIS, 0.2, "cis_dag_amb_end", 2,1)

SetVictoryMusic(REP, "rep_dag_amb_victory")
SetDefeatMusic (REP, "rep_dag_amb_defeat")
SetVictoryMusic(CIS, "cis_dag_amb_victory")
SetDefeatMusic (CIS, "cis_dag_amb_defeat")

SetSoundEffect("ScopeDisplayZoomIn", "binocularzoomin")
SetSoundEffect("ScopeDisplayZoomOut", "binocularzoomout")
--SetSoundEffect("BirdScatter", "birdsFlySeq1")
--SetSoundEffect("WeaponUnableSelect", "com_weap_inf_weaponchange_null")
--SetSoundEffect("WeaponModeUnableSelect", "com_weap_inf_modechange_null")
SetSoundEffect("SpawnDisplayUnitChange", "shell_select_unit")
SetSoundEffect("SpawnDisplayUnitAccept", "shell_menu_enter")
SetSoundEffect("SpawnDisplaySpawnPointChange", "shell_select_change")
SetSoundEffect("SpawnDisplaySpawnPointAccept", "shell_menu_enter")
SetSoundEffect("SpawnDisplayBack", "shell_menu_exit")



--OpeningSateliteShot
AddCameraShot(0.953374, -0.267720, 0.134110, 0.037660, -54.391048, 22.637020, -112.560837);
AddCameraShot(0.190180, -0.039485, -0.960472, -0.199413, -23.582567, 18.165585, -59.159462);
AddCameraShot(0.166568, 0.008194, -0.984805, 0.048446, -52.621288, -3.707588, 71.935303);
AddCameraShot(0.921100, 0.181319, -0.338038, 0.066543, 85.826782, -3.707588, 89.593933);
AddCameraShot(0.760499, -0.074656, 0.641947, 0.063018, 48.234692, -1.620878, 7.359371);
end


antipower = function( player )

local unit = GetCharacterUnit(player)
local unitLocation = GetEntityMatrix( unit )
--get the player's spawn position
--local player_pos = GetEntityMatrix(player)
--CreateEntity("com_item_powerup_antiammo", unitLocation, "antiammo")
-- SetEntityMatrix("antiarmor", unitLocation)
-- SetEntityMatrix("antiammo", unitLocation)
SetProperty(unit, "CurShield", 0)

end

superpowers = function(self)
print("Superpowers has started.")
node1 = ScriptCB_random(0,2)
print("The node for the swamp is:", node1)
node2 = ScriptCB_random(3,5)
print("The node for the forest is:", node2)
node3 = ScriptCB_random(6,8)
print("The node for the town is:", node3)
--node4 = ScriptCB_random(9,11)
--print("The node for the mountain is:", node)

SPnodes = {node1, node2, node3}--,node4}

--local x = ScriptCB_random(1,4)
--print("The area for the adrenaline is:", x, SPnodes[x])
--sammo_spawn4 = GetPathPoint("special_ammo_spawn", 3)
--table.remove(SPnodes, x)
local x = ScriptCB_random(3)
print("The area for the full restore is:", x, SPnodes[x])
sammo_spawn1 = GetPathPoint("special_ammo_spawn", SPnodes[x])
table.remove(SPnodes, x)
x = ScriptCB_random(2)
print("The area for the invincibility is:", x, SPnodes[x])
sammo_spawn2 = GetPathPoint("special_ammo_spawn", SPnodes[x])
table.remove(SPnodes, x)
sammo_spawn3 = GetPathPoint("special_ammo_spawn", SPnodes[1])
print("The area for the one hit kill is:", 1, SPnodes[1])


spec_powerup1 = CreateTimer("spec_powerup1")
SetTimerValue(spec_powerup1, 120)
OnTimerElapse(
function(timer)
print("Spawning full restore.")
CreateEntity("com_item_powerup_full", sammo_spawn1, "full") --CreateEntity(class, node, name)
DestroyTimer(spec_powerup1)
end,
spec_powerup1
)

spec_powerup2 = CreateTimer("spec_powerup2")
SetTimerValue(spec_powerup2, 120)
OnTimerElapse(
function(timer)
print("Spawning invincibility.")
CreateEntity("com_item_powerup_inv", sammo_spawn2, "invinc") --CreateEntity(class, node, name)
DestroyTimer(spec_powerup2)
end,
spec_powerup2
)

spec_powerup3 = CreateTimer("spec_powerup3")
SetTimerValue(spec_powerup3, 120)
OnTimerElapse(
function(timer)
print("Spawning one hit kill.")
CreateEntity("com_item_powerup_onehit", sammo_spawn3, "onehit") --CreateEntity(class, node, name)
DestroyTimer(spec_powerup3)
end,
spec_powerup3
)

spec_powerup4 = CreateTimer("spec_powerup4")
SetTimerValue(spec_powerup4, 120)
OnTimerElapse(
function(timer)
print("Spawning adrenaline.")
CreateEntity("com_item_powerup_armor", sammo_spawn4, "armor") --CreateEntity(class, node, name)
DestroyTimer(spec_powerup4)
end,
spec_powerup4
)

StartTimer(spec_powerup1)
StartTimer(spec_powerup2)
StartTimer(spec_powerup3)
StartTimer(spec_powerup4)

end

GetPlayersAlive = function(self)

return (GetNumTeamMembersAlive(1) + GetNumTeamMembersAlive(2))

end

cpAmmoSpawn = function(self)
print("The cp ammo spawn has started.")

--get the path point
cp1_ammospawn1 = GetPathPoint("cp1_spawn", 0) --GetPathPoint(Pathname, node)
cp1_ammospawn2 = GetPathPoint("cp1_spawn", 1)
cp2_ammospawn1 = GetPathPoint("cp2_spawn", 0)
cp2_ammospawn2 = GetPathPoint("cp2_spawn", 1)
cp3_ammospawn1 = GetPathPoint("cp3_spawn", 0)
cp3_ammospawn2 = GetPathPoint("cp3_spawn", 1)
cp4_ammospawn1 = GetPathPoint("cp4_spawn", 0)
cp4_ammospawn2 = GetPathPoint("cp4_spawn", 1)

cp1_powerspawn1 = CreateTimer("cp1_powerspawn1")
SetTimerValue(cp1_powerspawn1, 150)
OnTimerElapse(
function(timer)
print("Spawning cp1 ammo 1.")
CreateEntity("com_item_powerup_dual", cp1_ammospawn1, "ammo1") --CreateEntity(class, node, name)
SetTimerValue(cp1_powerspawn1, (ScriptCB_random(6, 18)*10))
StartTimer(cp1_powerspawn1)
end,
cp1_powerspawn1
)

cp1_powerspawn2 = CreateTimer("cp1_powerspawn2")
SetTimerValue(cp1_powerspawn2, 150)
OnTimerElapse(
function(timer)
print("Spawning cp1 ammo 2.")
CreateEntity("com_item_powerup_dual", cp1_ammospawn2, "ammo2")
SetTimerValue(cp1_powerspawn2, (ScriptCB_random(6, 18)*10))
StartTimer(cp1_powerspawn2)
end,
cp1_powerspawn2
)

cp2_powerspawn1 = CreateTimer("cp2_powerspawn1")
SetTimerValue(cp2_powerspawn1, 150)
OnTimerElapse(
function(timer)
print("Spawning cp2 ammo 1.")
CreateEntity("com_item_powerup_dual", cp2_ammospawn1, "ammo3")
SetTimerValue(cp2_powerspawn1, (ScriptCB_random(6, 18)*10))
StartTimer(cp2_powerspawn1)
end,
cp2_powerspawn1
)

cp2_powerspawn2 = CreateTimer("cp2_powerspawn2")
SetTimerValue(cp2_powerspawn2, 150)
OnTimerElapse(
function(timer)
print("Spawning cp2 ammo 2.")
CreateEntity("com_item_powerup_dual", cp2_ammospawn2, "ammo4")
SetTimerValue(cp2_powerspawn2, (ScriptCB_random(6, 18)*10))
StartTimer(cp2_powerspawn2)
end,
cp2_powerspawn2
)

cp3_powerspawn1 = CreateTimer("cp3_powerspawn1")
SetTimerValue(cp3_powerspawn1, 150)
OnTimerElapse(
function(timer)
print("Spawning cp3 ammo 1.")
CreateEntity("com_item_powerup_dual", cp3_ammospawn1, "ammo5")
SetTimerValue(cp3_powerspawn1, (ScriptCB_random(6, 12)*10))
StartTimer(cp3_powerspawn1)
end,
cp3_powerspawn1
)

cp3_powerspawn2 = CreateTimer("cp3_powerspawn2")
SetTimerValue(cp3_powerspawn2, 150)
OnTimerElapse(
function(timer)
print("Spawning cp3 ammo 2.")
CreateEntity("com_item_powerup_dual", cp3_ammospawn2, "ammo6")
SetTimerValue(cp3_powerspawn2, (ScriptCB_random(6, 12)*10))
StartTimer(cp3_powerspawn2)
end,
cp3_powerspawn2
)

cp4_powerspawn1 = CreateTimer("cp4_powerspawn1")
SetTimerValue(cp4_powerspawn1, 150)
OnTimerElapse(
function(timer)
print("Spawning cp4 ammo 1.")
CreateEntity("com_item_powerup_dual", cp4_ammospawn1, "ammo7")
SetTimerValue(cp4_powerspawn1, (ScriptCB_random(6, 12)*10))
StartTimer(cp4_powerspawn1)
end,
cp4_powerspawn1
)

cp4_powerspawn2 = CreateTimer("cp4_powerspawn2")
SetTimerValue(cp4_powerspawn2, 150)
OnTimerElapse(
function(timer)
print("Spawning cp4 ammo 2.")
CreateEntity("com_item_powerup_dual", cp4_ammospawn2, "ammo8")
SetTimerValue(cp4_powerspawn2, (ScriptCB_random(6, 12)*10))
StartTimer(cp4_powerspawn2)
end,
cp4_powerspawn2
)

StartTimer(cp1_powerspawn1)
StartTimer(cp1_powerspawn2)
StartTimer(cp2_powerspawn1)
StartTimer(cp2_powerspawn2)
StartTimer(cp3_powerspawn1)
StartTimer(cp3_powerspawn2)
StartTimer(cp4_powerspawn1)
StartTimer(cp4_powerspawn2)


end


ammospawn = function(self)
print("The ammo spawn has started.")

--get the path point
ammospawn1 = GetPathPoint("normal_ammo_spawn", 0) --GetPathPoint(Pathname, node)
ammospawn2 = GetPathPoint("normal_ammo_spawn", 1)
ammospawn3 = GetPathPoint("normal_ammo_spawn", 2)
ammospawn4 = GetPathPoint("normal_ammo_spawn", 3)
ammospawn5 = GetPathPoint("normal_ammo_spawn", 4)
ammospawn6 = GetPathPoint("normal_ammo_spawn", 5)
ammospawn7 = GetPathPoint("normal_ammo_spawn", 6)
ammospawn8 = GetPathPoint("normal_ammo_spawn", 7)
ammospawn9 = GetPathPoint("normal_ammo_spawn", 8)
ammospawn10 = GetPathPoint("normal_ammo_spawn", 9)
ammospawn11 = GetPathPoint("normal_ammo_spawn", 10)
ammospawn12 = GetPathPoint("normal_ammo_spawn", 11)
ammospawn13 = GetPathPoint("normal_ammo_spawn", 12)
ammospawn14 = GetPathPoint("normal_ammo_spawn", 13)
ammospawn15 = GetPathPoint("normal_ammo_spawn", 14)
ammospawn16 = GetPathPoint("normal_ammo_spawn", 15)
-- ammospawn17 = GetPathPoint("normal_ammo_spawn", 16)
-- ammospawn18 = GetPathPoint("normal_ammo_spawn", 17)
-- ammospawn19 = GetPathPoint("normal_ammo_spawn", 18)
-- ammospawn20 = GetPathPoint("normal_ammo_spawn", 19)


powerspawn1 = CreateTimer("powerspawn1")
SetTimerValue(powerspawn1, (ScriptCB_random(9, 18)*10))
OnTimerElapse(
function(timer)
print("Spawning normal ammo 1.")
CreateEntity("com_item_powerup_dual", ammospawn1, "nammo1") --CreateEntity(class, node, name)
SetTimerValue(powerspawn1, (ScriptCB_random(9, 18)*20))
StartTimer(powerspawn7)
end,
powerspawn1
)

There are 19 more of these, I took them out in this post to reduce number of characters



StartTimer(powerspawn1)
StartTimer(powerspawn2)
StartTimer(powerspawn3)
StartTimer(powerspawn5)
StartTimer(powerspawn6)
StartTimer(powerspawn7)
StartTimer(powerspawn9)
StartTimer(powerspawn10)
StartTimer(powerspawn11)
StartTimer(powerspawn13)
StartTimer(powerspawn14)
StartTimer(powerspawn15)
-- StartTimer(powerspawn17)
-- StartTimer(powerspawn18)
-- StartTimer(powerspawn19)


end


testArmor = function(self)
testspawn1 = GetPathPoint("center_ammo_spawn", 0)
testspawn2 = GetPathPoint("center_ammo_spawn", 1)
testspawn3 = GetPathPoint("center_ammo_spawn", 2)
testspawn4 = GetPathPoint("center_ammo_spawn", 3)

CreateEntity("com_item_powerup_adrenaline", testspawn1, "testarmor1")
CreateEntity("com_item_powerup_adrenaline", testspawn2, "testarmor2")
CreateEntity("com_item_powerup_adrenaline", testspawn3, "testarmor3")
CreateEntity("com_item_powerup_adrenaline", testspawn4, "testarmor4")
end

armorspawn = function(self)
print("The armor spawn has started")

--get the path point
armorspawn1 = GetPathPoint("armor_spawn", 0) --GetPathPoint(Pathname, node)
armorspawn2 = GetPathPoint("armor_spawn", 1)
armorspawn3 = GetPathPoint("armor_spawn", 2)
armorspawn4 = GetPathPoint("armor_spawn", 3)
armorspawn5 = GetPathPoint("armor_spawn", 4)
armorspawn6 = GetPathPoint("armor_spawn", 5)
armorspawn7 = GetPathPoint("armor_spawn", 6)
armorspawn8 = GetPathPoint("armor_spawn", 7)
armorspawn9 = GetPathPoint("armor_spawn", 8)
armorspawn10 = GetPathPoint("armor_spawn", 9)
armorspawn11 = GetPathPoint("armor_spawn", 10)
-- armorspawn12 = GetPathPoint("armor_spawn", 11)
-- armorspawn13 = GetPathPoint("armor_spawn", 12)
-- armorspawn14 = GetPathPoint("armor_spawn", 13)
-- armorspawn15 = GetPathPoint("armor_spawn", 14)
-- armorspawn16 = GetPathPoint("armor_spawn", 15)


apowerspawn1 = CreateTimer("apowerspawn1")
SetTimerValue(apowerspawn1, 1)
OnTimerElapse(
function(timer)
print("Spawning armor 1.")
CreateEntity("com_item_powerup_armor", armorspawn1, "armor1") --CreateEntity(class, node, name)
SetTimerValue(apowerspawn1, (ScriptCB_random(9, 18)*20))
print(GetTimerValue(apowerspawn1))
StartTimer(apowerspawn7)
end,
apowerspawn1
)

There are 15 more of these, I took them out in this post to reduce number of characters


StartTimer(apowerspawn1)
StartTimer(apowerspawn2)
StartTimer(apowerspawn3)
StartTimer(apowerspawn4)
StartTimer(apowerspawn5)
StartTimer(apowerspawn6)
StartTimer(apowerspawn7)
StartTimer(apowerspawn8)
StartTimer(apowerspawn9)
StartTimer(apowerspawn10)
StartTimer(apowerspawn11)
-- StartTimer(apowerspawn12)
-- StartTimer(apowerspawn13)
-- StartTimer(apowerspawn14)
-- StartTimer(apowerspawn15)
-- StartTimer(apowerspawn16)



end

feast = function(self)
print("The feast function has started.")
feastspawn1 = GetPathPoint("center_ammo_spawn", 0)
feastspawn2 = GetPathPoint("center_ammo_spawn", 1)
feastspawn3 = GetPathPoint("center_ammo_spawn", 2)
feastspawn4 = GetPathPoint("center_ammo_spawn", 3)

feasttimer = CreateTimer("feasttimer")
SetTimerValue(feasttimer, 600)
OnTimerElapse(
function(timer)
print("Feast time!")
ShowMessageText("level.HGS.feast")
option(ScriptCB_random(1,8))
SetTimerValue(feasttimer, (ScriptCB_random(6, 10)*60))
StartTimer(feasttimer)
end,
feasttimer
)

option = function(num)
if num == 1 then
print("\tOption 1 was picked; 1 dual.")
CreateEntity("com_item_powerup_dual", feastspawn4, "fammo1")

elseif num == 2 then
print("\tOption 2 was picked; 1 defense and 1 armor.")
CreateEntity("com_item_powerup_defense", feastspawn1, "fbuff1")
CreateEntity("com_item_powerup_armor", feastspawn2, "farmor1")

elseif num == 3 then
print("\tOption 3 was picked; one full restore.")
CreateEntity("com_item_powerup_full", feastspawn3, "fammo1")

elseif num == 4 then
print("\tOption 4 was picked; 1 offense and 3 ammos.")
CreateEntity("com_item_powerup_offense", feastspawn2, "fbuff1")
CreateEntity("com_item_powerup_ammo", feastspawn1, "fammo1")
CreateEntity("com_item_powerup_ammo", feastspawn3, "fammo2")
CreateEntity("com_item_powerup_ammo", feastspawn4, "fammo3")

elseif num == 5 then
print("\tOption 5 was picked; two duals.")
CreateEntity("com_item_powerup_dual", feastspawn1, "fammo1")
CreateEntity("com_item_powerup_dual", feastspawn3, "fammo2")

elseif num == 6 then
print("\tOption 6 was picked; two armors.")
CreateEntity("com_item_powerup_armor", feastspawn4, "farmor1")
CreateEntity("com_item_powerup_armor", feastspawn2, "farmor2")

elseif num == 7 then
print("\tOption 7 was picked; two duals.")
CreateEntity("com_item_powerup_dual", feastspawn3, "fammo1")
CreateEntity("com_item_powerup_dual", feastspawn2, "fammo2")

elseif num == 8 then
print("\tOption 8 was picked; offense, defense, and energy.")
CreateEntity("com_item_powerup_offense", feastspawn4, "fbuff1")
CreateEntity("com_item_powerup_defense", feastspawn3, "fbuff2")
CreateEntity("com_item_powerup_energy", feastspawn1, "fener1")
end
end
StartTimer(feasttimer)
end

function GetNumRegisteredPlayers(players_alive)
local i
local numRegPla = 0

for i = 1, table.getn(players_alive) do
if not players_alive[i] then
print("something went wrong, this player doesn't exist!")
else if players_alive[i].registered == true then
numRegPla = numRegPla + 1
end
end
end
return numRegPla
end

NOTE: I took some unimportant stuff out to get under the character limit for the post

Current issues are:

- Missing sounds still (I posted in the request thread for someone to make one for me because I don't have enough time to get it done on my own :( I've followed every tutorial I can find and it still won't work.)
- I need to set up my traps/custom sound regions/regional sound streams. Is it possible to have 2 sound stream regions overlapping?
- fix super-powerups/think of a fourth one

Re: Hunger Games Scripting

Posted: Fri Apr 04, 2014 3:16 pm
by Marth8880
Hidden/Spoiler:
Please remove or change this:
[code]print("ME5_RandomSides: Configuring Shield Functionality for PICKUPS...")[/code]
Thanks. :)
But really though, what's the difference between using math.random() and ScriptCB_random()? Does ScriptCB_random() work online? :o

Re: Hunger Games Scripting

Posted: Fri Apr 04, 2014 3:26 pm
by [RDH]Zerted
Actually I just noticed I used math.random() in Holocron, so maybe it works fine. It looks like ScriptCB_random() returns a number between 0 and 1 but I can't test that. I'd assume ScriptCB_random() works online and math.random() doesn't.

Re: Hunger Games Scripting

Posted: Fri Apr 04, 2014 3:36 pm
by LRKfm946
I got ScriptCB_random() working. I do believe it's a number b/t 0 and 1. So for a number b/t 60 and 180 seconds, I did (math.ceil(ScriptCB_random()*120)+60)
Hidden/Spoiler:
[quote="Marth8880"]Please remove or change this:
[code]print("ME5_RandomSides: Configuring Shield Functionality for PICKUPS...")[/code]
Thanks. :)[/quote]
My bad, fixed! :P

Re: Hunger Games Scripting

Posted: Fri Apr 04, 2014 3:37 pm
by Marth8880
Hmm. I use math.random all over the place in this mod and it doesn't seem to cause any problems. :o Granted I can't use it in online matches (except for things like music), but still. :P