Page 1 of 1

LUA Code - Flag Teleports - Updated

Posted: Tue Sep 29, 2009 6:26 pm
by Fiodis
I'm writing a code so that, when the player spawns as a specific unit, the flag in a 1-flag CTF match is teleported to their matrix (so they pick it up).
The code:
Hidden/Spoiler:
[code]function ScriptPostLoad()

SoundEvent_SetupTeams( REP, 'rep', CIS, 'cis' )

ctf = ObjectiveOneFlagCTF:New{teamATT = 1, teamDEF = 2,
textATT = "game.modes.1flag", textDEF = "game.modes.1flag2",
captureLimit = 8, flag = "flag", flagIcon = "flag_icon",
flagIconScale = 3.0, homeRegion = "homeregion",
captureRegionATT = "team1_capture", captureRegionDEF = "team2_capture",
capRegionMarkerATT = "hud_objective_icon_circle", capRegionMarkerDEF = "hud_objective_icon_circle",
capRegionMarkerScaleATT = 3.0, capRegionMarkerScaleDEF = 3.0, multiplayerRules = true}

ctf:Start()

EnableSPHeroRules()

OnCharacterSpawn (
function (carrier)
if GetEntityClass(carrier) == "imp_inf_dark_trooper" then
local position = GetEntityMatrix(carrier)
local flagplace = GetEntityMatrix(flag)
SetEntityMatrix(flagplace, position)
end
end
)

end[/code][/size]
I get some odd CTD-causing errors, though:

Code: Select all

Message Severity: 2
.\Memory\RedMemory.cpp(634)
Allocating 408136 bytes attempt failed - no free blocks left in Heap 5 (Runtime)

Message Severity: 3
.\Memory\RedMemory.cpp(538)
Allocating 408136 bytes failed - no free blocks left in Heap 5 (Runtime)
Aside from the stock errors, these are the only ones in my error log. I have no mungelog.

My code looks all right to me - I have all the ends and ) in the right spots...and anyway the error doesn't mention LUA (though the code must be the cause of the error). ANy ideas on how to fix this?


EDIT - Hmm, the crash was probably due to another issue, because I ran it again and I was able to play. However, when I spawned as the dark trooper, nothing happened. Also, no AI were spawning. I captured the flag manually and the capture region didn't work. I got this:

Code: Select all

Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: (none):0: table index is nil
stack traceback:
	(none): in function `SoundEvent_SetupTeams'
	(none): in function `ScriptPostLoad'
What does that mean? My setup teams section:
Hidden/Spoiler:
[code] SetupTeams{
all = {
team = ALL,
units = 20,
reinforcements = 150,
soldier = { "all_inf_rifleman",9, 25},
assault = { "all_inf_rocketeer",1,4},
engineer = { "all_inf_engineer",1,4},
sniper = { "all_inf_sniper",1,4},
officer = { "all_inf_officer",1,4},
special = { "all_inf_wookiee",1,4},

},
imp = {
team = IMP,
units = 20,
reinforcements = 150,
soldier = { "imp_inf_rifleman",9, 25},
assault = { "imp_inf_rocketeer",1,4},
engineer = { "imp_inf_engineer",1,4},
sniper = { "imp_inf_sniper",1,4},
officer = { "imp_inf_officer",1,4},
special = { "imp_inf_dark_trooper",0,0},
},
}

SetHeroClass(ALL, "all_hero_hansolo_tat")
SetHeroClass(IMP, "imp_hero_bobafett")[/code][/size]

Re: LUA Code - Flag Teleports - Updated

Posted: Mon Oct 12, 2009 7:21 pm
by [RDH]Zerted
You have an error with your SoundEvent_SetupTeams function call in your ScriptPostLoad function. You might have to change those parameters to IMP and ALL or you might have to change something near the end of your script.