Page 1 of 1

Scripting issues

Posted: Sat May 30, 2009 10:15 am
by MetalcoreRancor
Ok, so I've been working on a wave mode with Itfactor's upcoming map, using Maveritchell's template he allowed me to use.

The template works fine, and for the sake of confidentiality, I will not be posting that part of the lua here for reference. Aside from that, my problem is last night I was given directions by repsharpshooter to set up a table system for forced in spawning, and ending the game when the table hits 0.

I don't know a lick about this kind of coding set up, so any help would be great.

All I know is, I can't spawn as the ATT, aka hunters side, and when I switch sides it instantly spawns me as the wrong side, DEF.
Hidden/Spoiler:
[code]function ScriptPostLoad()
AllowAISpawn(ALL, false)
AllowAISpawn(IMP, false)
--ScriptCB_SetGameRules("campaign")
EnableSPHeroRules()
-- This is the actual objective setup
TDM = ObjectiveTDM:New{teamATT = 1, teamDEF = 2,
multiplayerScoreLimit = 2000,
textATT = "game.modes.tdm",
textDEF = "game.modes.tdm2", multiplayerRules = true, isCelebrityDeathmatch = true}
TDM:Start()
local KOH_timerSpawn = OnTimerElapse(
function( timer )
show("KOH_timerSpawn OnTimerElapse()")

--spawn new units
spawnUnits( self.teamATT )


--reset and restart the timer
SetTimerValue( "spawnTimer", self.spawnTime )
ShowTimer( "spawnTimer" )
StartTimer( "spawnTimer" )
end, "spawnTimer"
)

local spawnUnits = function( team )
show("spawnUnits()")

--check input
if not team then show("Warning: No team given.") return end

--get the amount of players on the given team
local size = GetTeamSize(team)
show(size)

--for each team member,
local a
for a = 0, size do

--get the unit of the next team member
local character = GetTeamMember(team, a)
local unit = GetCharacterUnit( character )

--if there is not a unit the character is dead, so spawn a new unit for the character
if not unit then

--get a random path and path node
local path, node = getPathAndNode( team )

--spawn the given player at the generated path point
SpawnCharacter(character, GetPathPoint(path, node))

end--if unit
end--for each team member
end--end of spawnUnits()

|wave coding|

---------------------------------------------------------------------------
-- ScriptInit
---------------------------------------------------------------------------
function ScriptInit()


SetMemoryPoolSize ("ClothData",20)
SetMemoryPoolSize ("Combo",70) -- should be ~ 2x number of jedi classes
SetMemoryPoolSize ("Combo::State",850) -- should be ~12x #Combo
SetMemoryPoolSize ("Combo::Transition",850) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Condition",850) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Attack",750) -- should be ~8-12x #Combo
SetMemoryPoolSize ("Combo::DamageSample",8000) -- should be ~8-12x #Combo::Attack
SetMemoryPoolSize ("Combo::Deflect",140) -- should be ~1x #combo -- should be ~1x #combo

ReadDataFile("ingame.lvl")

ALL = 1
IMP = 2
-- These variables do not change
ATT = 1
DEF = 2
SetUberMode(1);
SetMaxFlyHeight(40)
SetMaxPlayerFlyHeight(40)

ReadDataFile("sound\\tat.lvl;tat2gcw")
ReadDataFile("dc:SIDE\\geo.lvl",
"hnt_inf_hunter_engineer",
"hnt_inf_hunter_commando",
"hnt_inf_hunter_melee",
"zom_inf_juggernaught",
"zom_inf_ghost",
"zom_inf_leaper",
"zom_inf_nomnom",
"zom_inf_pigzombie",
"hnt_inf_hunter_rocket",
"zom_inf_female",
"zom_inf_martyr",
"zom_inf_insanezombie",
"hnt_inf_hunter_sniper",
"hnt_inf_survivor")


ReadDataFile("dc:SIDE\\tur.lvl",
"tur_bldg_healthbot",
"hnt_weap_healthinjection")
SetMemoryPoolSize("MountedTurret", 35)


--ReadDataFile("SIDE\\snw.lvl", "snw_inf_wampa")

SetupTeams{
hero = {
team = ALL,
units = 6,
reinforcements = -1,

},
}

AddUnitClass(ALL, "hnt_inf_hunter_rocket",1,2)
AddUnitClass(ALL, "hnt_inf_hunter_sniper",1,2)
AddUnitClass(ALL, "hnt_inf_hunter_engineer",1,2)



SetupTeams{
villain = {
team = IMP,
units = 10,
reinforcements = -1,


},
}

AddUnitClass(IMP,"zom_inf_female",1,60)
--AddUnitClass(IMP,"zom_inf_nomnom",100,110)
--AddUnitClass(IMP,"zom_inf_juggernaught",100,110)
--AddUnitClass(IMP,"zom_inf_martyr",100,110)
--AddUnitClass(IMP,"zom_inf_insanezombie",4,10)
--AddUnitClass(IMP,"zom_inf_leaper",100,110)
--AddUnitClass(IMP,"zom_inf_ghost",100,110)
--LOL ZOMBEHS

SetTeamName(3, "Zombies")
AddUnitClass (3, "zom_inf_leaper", 100, 150)
AddUnitClass (3, "zom_inf_female", 100, 150)
AddUnitClass (3, "zom_inf_pigzombie", 40, 50)
SetUnitCount (3, 50)
--first number is numteam, second is numunits
AddAIGoal(3, "Deathmatch", 100)


SetTeamName(4, "Zombies")
AddUnitClass (4, "zom_inf_nomnom", 100, 150)
AddUnitClass (4, "zom_inf_juggernaught", 100, 150)
AddUnitClass (4, "zom_inf_martyr", 30, 50)
SetUnitCount (4, 50)
--first number is numteam, second is numunits
AddAIGoal(4, "Deathmatch", 100)

SetTeamName(5, "Zombies")
AddUnitClass(5,"zom_inf_ghost",50,75)
AddUnitClass (5, "zom_inf_insanezombie", 100, 150)
SetUnitCount (5, 50)
--first number is numteam, second is numunits
AddAIGoal(5, "Deathmatch", 100)


--SetTeamName(7, "Survivors")
--AddUnitClass (7, "hnt_inf_survivor", 5, 10)
--SetUnitCount (7, 15)
--AddAIGoal(7, "Deathmatch", 100)



SetTeamAsEnemy(ATT,3)
SetTeamAsEnemy(3,ATT)
SetTeamAsFriend(DEF,3)
SetTeamAsFriend(3,DEF)

SetTeamAsEnemy(ATT,4)
SetTeamAsEnemy(4,ATT)
SetTeamAsFriend(DEF,4)
SetTeamAsFriend(4,DEF)
SetTeamAsFriend(3,4)
SetTeamAsFriend(4,3)

SetTeamAsEnemy(ATT,5)
SetTeamAsEnemy(5,ATT)
SetTeamAsFriend(DEF,5)
SetTeamAsFriend(5,DEF)
SetTeamAsFriend(4,5)
SetTeamAsFriend(5,4)
SetTeamAsFriend(3,5)
SetTeamAsFriend(5,3)[/code]

Re: Scripting issues

Posted: Mon Jun 01, 2009 1:20 am
by RepSharpshooter
Just to clarify what I told you to do, this assumes you want the game to end when all players have died, not just one. Now, you cant let players spawn when they want to, or else theyd respawn after they die. This means you have to force spawn them through lua. To accomplish this:
1. Remove normal cp where they spawn
2. Create a new timer. At the elapse of the timer, say set timer 15 secs, then start timer. This will make it loop every 15 secs.
On Elapse, use a for loop to iterate through team 1 and spawn characters in if they are not already alive (the code I gave you today).

>>>But here is a problem, how do we know if they have already died once? You cant spawn someone in twice. This is where a table needs to be made. The table is nothing more than a list of characters that have already been spawned. After we spawn someone, we need to use table.insert( tablename, character) to "register" them in the table. Then, before we spawn, we must iterate through this table to check to see if they are already registered<<<<
But then how do you know when there is no one left alive? You actually need two tables. The first table is a reigstry of everyone that ever registered. The second is similar to the first, but it only has people who registered and are still alive. When this second table reaches zero in size, this is when the battle ends.

To accomplish this, OnCharacterDeath you need to iterate through the second table, find where the character who died is, then remove this element from the table. Be careful not to remove an element as you iterate through a for loop, or make sure you use a return statement. (i.e. if you remove an element while it's iterating through the table, it will miscalculate the table's size and try to iterate too far). Anyways. then after you remove it is the place to check if table.getn(tablename) == 0 If it is, end the map.


This is the premise Battle Arena and HKH runs on, which is very complicated and reflects the entire extent of my lua coding knowledge. I really cant do much more for you short of coding it myself, which I don't really want to do no offense, im just too busy.

Re: Scripting issues

Posted: Mon Jun 01, 2009 11:05 am
by MetalcoreRancor

Code: Select all

        victorious =   OnCharacterDeath(   
                         function(character)          
                          if GetNumTeamMembersAlive(ATT) == 0 then
                         MissionVictory(DEF)
                       end
                    end
                   )
This is the solution I came up with.

Re: Scripting issues

Posted: Mon Jun 01, 2009 1:22 pm
by RepSharpshooter
That works too, the reason my method is insanely more complicated is because in Battle Arena people were dead or alive at the same time on the same team so I couldn't use that.

Hmm wait a sec:

Code: Select all

        victorious =   OnCharacterDeath(   
                         function(character)          
                          if GetNumTeamMembersAlive(ATT) == 0 then
                         MissionVictory(DEF)
                       end
                    end
                   )
That will cover your victory statement, but it doesn't cover the spawn issue. You still must implement the forced spawn system, or else people can just spawn in when they want and the number of people alive will never reach 0. That bit of code may eliminate the need for a second table though, but you'll still need the first.

Re: Scripting issues

Posted: Mon Jun 01, 2009 4:06 pm
by MetalcoreRancor
My answer to that is to develope a code structure to force respawning, as one of the enemy zombies. I just haven't worked out the bugs in this system.