Different lua questions

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
Anakin
Master of the Force
Master of the Force
Posts: 4817
Joined: Sat Sep 19, 2009 11:37 am
Projects :: RC Side Mod - Remastered - SWBF3 Legacy
Location: Mos Espa (germany)

Different lua questions

Post by Anakin »

Hi,

does anyone knows, what's wrong with this script?? It isn't loaded when i add it to my custom common.lvl
Hidden/Spoiler:
[code]
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

-- Multiplayer game name screen.

-- Helper function. Given a layout (x,y,width, height), returns a
-- fully-built item.
function Teamstats_Listbox_CreateItem(layout)

--print ("Teamstats_Listbox_CreateItem")
local insidewidth = layout.width - 10;
-- Make a coordinate system pegged to the top-left of where the cursor would go.
local Temp = NewIFContainer {
x = layout.x - 0.5 * insidewidth, y=layout.y + 1,
bInertPos = 1,
}

local Font = teamstats_listbox_layoutL.font
local FontHeight = teamstats_listbox_layoutL.fontheight
local WidthPer = insidewidth * 0.125
teamstats_listbox_layoutL.NameWidth = (insidewidth - WidthPer * 4) + 5 -- pixels we let name use

Temp.labelstr = NewIFText {
HScale = 0.8,
VScale = 1,
x = 2, y = FontHeight * -0.5 - 5, textw = insidewidth, -- Need full width, will manuall clamp later
valign = "vcenter", texth = layout.height,
clip = "character",
halign = "left", font = Font,
ColorR= 255, ColorG = 255, ColorB = 255,
style = "normal",
bInertPos = 1,
nocreatebackground = 1,
startdelay = math.random() * 0.25,
inert_all = 1,
}

Temp.val1str = NewIFText{
HScale = 0.8,
VScale = 1,
x = insidewidth - WidthPer * 4, y = FontHeight * -0.5 - 5,
valign = "vcenter", texth = layout.height, -- ScriptCB_GetFontHeight("gamefont_tiny"),
textw = WidthPer, halign = "right", font = Font,
ColorR= 255, ColorG = 255, ColorB = 255,
style = "normal",
bInertPos = 1,
nocreatebackground = 1,
startdelay = math.random() * 0.25,
inert_all = 1,
}
Temp.val2str = NewIFText{
HScale = 0.8,
VScale = 1,
x = insidewidth - WidthPer * 3, y = FontHeight * -0.5 - 5,
valign = "vcenter", texth = layout.height, -- ScriptCB_GetFontHeight("gamefont_tiny"),
textw = WidthPer, halign = "right", font = Font,
ColorR= 255, ColorG = 255, ColorB = 255,
style = "normal",
bInertPos = 1,
nocreatebackground = 1,
startdelay = math.random() * 0.25,
inert_all = 1,
}
Temp.val3str = NewIFText{
HScale = 0.8,
VScale = 1,
x = insidewidth - WidthPer * 2, y = FontHeight * -0.5 - 5,
valign = "vcenter", texth = layout.height, -- ScriptCB_GetFontHeight("gamefont_tiny"),
textw = WidthPer, halign = "right", font = Font,
ColorR= 255, ColorG = 255, ColorB = 255,
style = "normal",
bInertPos = 1,
nocreatebackground = 1,
startdelay = math.random() * 0.25,
inert_all = 1,
}
Temp.val4str = NewIFText{
HScale = 0.8,
VScale = 1,
x = insidewidth - WidthPer * 1, y = FontHeight * -0.5 - 5,
valign = "vcenter", texth = layout.height, -- ScriptCB_GetFontHeight("gamefont_tiny"),
textw = WidthPer, halign = "right", font = Font,
ColorR= 255, ColorG = 255, ColorB = 255,
style = "normal",
bInertPos = 1,
nocreatebackground = 1,
startdelay = math.random() * 0.25,
inert_all = 1,
}
return Temp
end

-- Helper function. For a destination item (previously created w/
-- CreateItem), fills it in with data, which may be nil (==blank it)
function Teamstats_Listbox_PopulateItem(Dest,Data)
if(Data) then
-- force the name into word clipping
-- IFText_fnSetTextBreak(Dest.labelstr,"none")
-- Contents to show. Do so.
local NameUStr = Data.labelustr
IFText_fnSetString(Dest.val1str,Data.val1str)
IFText_fnSetString(Dest.val2str,Data.val2str)
IFText_fnSetString(Dest.val3str,Data.val3str)
IFText_fnSetString(Dest.val4str,Data.val4str)

-- NameUStr = ScriptCB_tounicode("WWWWWWWWWWWWWWM")
-- IFText_fnSetString(Dest.val1str,"1111")
-- IFText_fnSetString(Dest.val2str,"2222")
-- IFText_fnSetString(Dest.val3str,"3333")

-- Shrink font horizontally on name until it fits. This will make super-long
-- XLive gamertags work even after they shoved in an extra column since BF1

local TextHScale = 1.0
IFText_fnSetScale(Dest.labelstr, TextHScale, 1.0)
IFText_fnSetUString(Dest.labelstr,NameUStr)
local fLeft, fTop, fRight, fBot = IFText_fnGetDisplayRect(Dest.labelstr)
local TextW = fRight - fLeft
-- Initial guess at scale: a very close fit
TextHScale = math.min(1.0, teamstats_listbox_layoutL.NameWidth / TextW)
-- print("Initial TextHScale = ", TextHScale)
repeat
IFText_fnSetScale(Dest.labelstr, TextHScale, 1.0)
IFText_fnSetUString(Dest.labelstr,NameUStr)
fLeft, fTop, fRight, fBot = IFText_fnGetDisplayRect(Dest.labelstr)
TextW = fRight - fLeft
TextHScale = TextHScale * 0.95 -- shrink over time
-- print("Shrunk TextHScale to ", TextHScale)
until (TextW < teamstats_listbox_layoutL.NameWidth)

if(Data.ColorR) then
IFObj_fnSetColor(Dest.labelstr,Data.ColorR,Data.ColorG,Data.ColorB)
IFObj_fnSetColor(Dest.val1str,Data.ColorR,Data.ColorG,Data.ColorB)
IFObj_fnSetColor(Dest.val2str,Data.ColorR,Data.ColorG,Data.ColorB)
IFObj_fnSetColor(Dest.val3str,Data.ColorR,Data.ColorG,Data.ColorB)
IFObj_fnSetColor(Dest.val4str,Data.ColorR,Data.ColorG,Data.ColorB)
end

-- set points to yellow
IFObj_fnSetColor(Dest.val1str,255,255,0)
end

IFObj_fnSetVis(Dest,Data) -- Show if there are contents

-- if the cpp == -1, then don't show this entry (its padding)
if(Data and Data.val3str == "-1") then
IFObj_fnSetVis(Dest,nil)
end

end

-- Helper function. Given a layout (x,y,width, height), returns a
-- fully-built item.
function Teamstats_AwardsListbox_CreateItem(layout)
--print ("Teamstats_AwardsListbox_CreateItem")
local insidewidth = layout.width - 10;
-- Make a coordinate system pegged to the top-left of where the cursor would go.
local Temp = NewIFContainer {
x = layout.x - 0.5 * insidewidth, y=layout.y + 1,
bInertPos = 1,
}

local Font = teamstats_awardsListbox_layoutL.font
local FontHeight = teamstats_awardsListbox_layoutL.fontheight
local WidthPer = insidewidth * 0.125
teamstats_awardsListbox_layoutL.NameWidth = 0.5 * insidewidth - 5 -- pixels we let name use

Temp.labelustr = NewIFText {
HScale = 0.8,
VScale = 1,
x = 2, y = FontHeight * -0.5, textw = insidewidth, -- Need full width, will manually clamp later
valign = "vcenter", texth = layout.height,
clip = "character",
halign = "left", font = Font,
ColorR= 255, ColorG = 255, ColorB = 255,
style = "normal",
bInertPos = 1,
nocreatebackground = 1,
startdelay = math.random() * 0.25,
inert_all = 1,
}

Temp.contentsustr = NewIFText{
HScale = 0.8,
VScale = 1,
--x = insidewidth - WidthPer * 4, y = FontHeight * -0.5,
x = 0, y = FontHeight * -0.5,
valign = "vcenter", texth = layout.height, -- ScriptCB_GetFontHeight("gamefont_tiny"),
textw = insidewidth, halign = "right", font = Font,
ColorR= 255, ColorG = 255, ColorB = 255,
style = "normal",
bInertPos = 1,
nocreatebackground = 1,
startdelay = math.random() * 0.25,
inert_all = 1,
}
return Temp
end

-- Helper function. For a destination item (previously created w/
-- CreateItem), fills it in with data, which may be nil (==blank it)
function Teamstats_AwardsListbox_PopulateItem(Dest,Data)
--print ("Teamstats_AwardsListbox_PopulateItem")

if (Data) then
-- force the name into word clipping
-- IFText_fnSetTextBreak(Dest.labelustr,"none")
-- Contents to show. Do so.
local NameUStr = Data.labelustr
--IFText_fnSetUString(Dest.contentsustr,Data.contentsustr)
ifs_careerstats_fnShrinkToFit(Dest.contentsustr, Data.contentsustr, teamstats_awardsListbox_layoutL.NameWidth)

-- Shrink font horizontally on name until it fits. This will make super-long
-- XLive gamertags work even after they shoved in an extra column since BF1

local TextHScale = 1.0
IFText_fnSetScale(Dest.labelustr, TextHScale, 1.0)
IFText_fnSetUString(Dest.labelustr,NameUStr)
local fLeft, fTop, fRight, fBot = IFText_fnGetDisplayRect(Dest.labelustr)
local TextW = fRight - fLeft
-- Initial guess at scale: a very close fit
TextHScale = math.min(1.0, teamstats_awardsListbox_layoutL.NameWidth / TextW)
-- print("Initial TextHScale = ", TextHScale)
repeat
IFText_fnSetScale(Dest.labelustr, TextHScale, 1.0)
IFText_fnSetUString(Dest.labelustr,NameUStr)
fLeft, fTop, fRight, fBot = IFText_fnGetDisplayRect(Dest.labelustr)
TextW = fRight - fLeft
TextHScale = TextHScale * 0.95 -- shrink over time
-- print("Shrunk TextHScale to ", TextHScale)
until (TextW < teamstats_awardsListbox_layoutL.NameWidth)

if(Data.ColorR) then
IFObj_fnSetColor(Dest.labelustr,Data.ColorR,Data.ColorG,Data.ColorB)
IFObj_fnSetColor(Dest.contentsustr,Data.ColorR,Data.ColorG,Data.ColorB)
end

-- set points to yellow
IFObj_fnSetColor(Dest.contentsustr,255,255,0)
end

IFObj_fnSetVis(Dest,Data) -- Show if there are contents

-- if the cpp == -1, then don't show this entry (its padding)
--if(Data and Data.val3str == "-1") then
-- IFObj_fnSetVis(Dest,nil)
--end

end



teamstats_listbox_layoutL = {
-- showcount = 20, -- filled in from code later
yTop = -63,
yHeight = 26,
ySpacing = -6,
-- width = 430, -- filled in from code later
x = 0,
-- slider = 1,
font = "gamefont_tiny",
CreateFn = Teamstats_Listbox_CreateItem,
PopulateFn = Teamstats_Listbox_PopulateItem,
}

teamstats_listbox_layoutR = {
-- showcount = 20, -- filled in from code later
yTop = -63,
yHeight = 26,
ySpacing = -6,
-- width = 430, -- filled in from code later
x = 0,
-- slider = 1,
font = "gamefont_tiny",
CreateFn = Teamstats_Listbox_CreateItem,
PopulateFn = Teamstats_Listbox_PopulateItem,
}

teamstats_awardsListbox_layoutL = {
yHeight = 15,
ySpacing = 1,
x = 0,
font = "gamefont_tiny",
CreateFn = Teamstats_AwardsListbox_CreateItem,
PopulateFn = Teamstats_AwardsListbox_PopulateItem,
}

teamstats_awardsListbox_layoutR = {
yHeight = 15,
ySpacing = 1,
x = 0,
font = "gamefont_tiny",
CreateFn = Teamstats_AwardsListbox_CreateItem,
PopulateFn = Teamstats_AwardsListbox_PopulateItem,
}

function ifs_teamstats_fnFillContents(this)
-- Reset listbox, show it. [Remember, Lua starts at 1!]
local playerIdxL,playerIdxR
playerIdxR = ScriptCB_GetTeamstats(1)
playerIdxL = ScriptCB_GetTeamstats(0)
if(this.SetCursorToPlayer) then
if(playerIdxL >= 0) then
this.bCursorOnLeft = 1
teamstats_listbox_layoutL.CursorIdx = playerIdxL + 1
teamstats_listbox_layoutL.SelectedIdx = playerIdxL + 1
teamstats_listbox_layoutL.FirstShownIdx = math.max(playerIdxL-4,1)
teamstats_listbox_layoutR.CursorIdx = nil
teamstats_listbox_layoutR.SelectedIdx = playerIdxL + 1
teamstats_listbox_layoutR.FirstShownIdx = math.max(playerIdxL-4,1)
end
if(playerIdxR >= 0) then
this.bCursorOnLeft = nil
teamstats_listbox_layoutL.CursorIdx = nil
teamstats_listbox_layoutL.SelectedIdx = playerIdxR + 1
teamstats_listbox_layoutL.FirstShownIdx = math.max(playerIdxR-4,1)
teamstats_listbox_layoutR.CursorIdx = playerIdxR + 1
teamstats_listbox_layoutR.SelectedIdx = playerIdxR + 1
teamstats_listbox_layoutR.FirstShownIdx = math.max(playerIdxR-4,1)
end
end
teamstats_awardsListbox_layoutL.CursorIdx = nil
teamstats_awardsListbox_layoutR.CursorIdx = nil

ListManager_fnFillContents(this.LeftList,teamstats_listbox_contentsL,teamstats_listbox_layoutL)
ScriptCB_GetTeamstats(1)
ListManager_fnFillContents(this.RightList,teamstats_listbox_contentsR,teamstats_listbox_layoutR)
ScriptCB_GetAwardStats(0)
ListManager_fnFillContents(this.awardsLeftList,teamstats_awardsListbox_contentsL,teamstats_awardsListbox_layoutL)
ScriptCB_GetAwardStats(1)
ListManager_fnFillContents(this.awardsRightList,teamstats_awardsListbox_contentsR,teamstats_awardsListbox_layoutR)
end

-- Helper function, blanks out the onscreen contents. Used to keep the
-- glyphcache from overloading.
function ifs_teamstats_fnBlankContents(this)
local i,Max

local BlankUStr = ScriptCB_tounicode("")

Max = table.getn(teamstats_listbox_contentsL)
for i=1,Max do
teamstats_listbox_contentsL.labelustr = BlankUStr
teamstats_listbox_contentsL.val1str = ""
teamstats_listbox_contentsL.val2str = ""
teamstats_listbox_contentsL.val3str = ""
teamstats_listbox_contentsL.val4str = ""
end

Max = table.getn(teamstats_listbox_contentsR)
for i=1,Max do
teamstats_listbox_contentsR.labelustr = BlankUStr
teamstats_listbox_contentsR.val1str = ""
teamstats_listbox_contentsR.val2str = ""
teamstats_listbox_contentsR.val3str = ""
teamstats_listbox_contentsR.val4str = ""
end
if ( teamstats_awardsListbox_contentsL ) then
Max = table.getn(teamstats_awardsListbox_contentsL)
for i=1,Max do
teamstats_awardsListbox_contentsL[i].labelustr = BlankUStr
teamstats_awardsListbox_contentsL[i].contentsustr = ""
end
else
print ("ifs_teamstats_fnBlankContents: teamstats_awardsListbox_contentsL == nil")
end

if ( teamstats_awardsListbox_contentsR ) then
Max = table.getn(teamstats_awardsListbox_contentsR)
for i=1,Max do
teamstats_awardsListbox_contentsR[i].labelustr = BlankUStr
teamstats_awardsListbox_contentsR[i].contentsustr = ""
end
else
print ("ifs_teamstats_fnBlankContents: teamstats_awardsListbox_contentsR == nil")
end

-- Repaint
ListManager_fnFillContents(this.LeftList,teamstats_listbox_contentsL,teamstats_listbox_layoutL)
ListManager_fnFillContents(this.RightList,teamstats_listbox_contentsR,teamstats_listbox_layoutR)
ListManager_fnFillContents(this.awardsLeftList,teamstats_awardsListbox_contentsL,teamstats_awardsListbox_layoutL)
ListManager_fnFillContents(this.awardsRightList,teamstats_awardsListbox_contentsR,teamstats_awardsListbox_layoutR)
end

teamstats_listbox_contents = {}

teamstats_listbox_contentsL = {
-- Filled in from C++
-- Stubbed to show the string.format it wants.
-- { labelustr = "Player 1", contentsustr = "5"},
-- **OR**
-- { labelustr = " Favorite Vehicle", contentsustr = "AT-ST"},
}

teamstats_listbox_contentsR = {
-- Filled in from C++
-- Stubbed to show the string.format it wants.
-- { labelustr = "Player 1", contentsustr = "5"},
-- **OR**
-- { labelustr = " Favorite Vehicle", contentsustr = "AT-ST"},
}

teamstats_awardsListbox_contentsL = {}
teamstats_awardsListbox_contentsR = {}

function ifs_teamstats_fnFlipLeftRight(this)
this.bCursorOnLeft = not this.bCursorOnLeft

-- Flip the selections/cursor positions
if(this.bCursorOnLeft) then
-- Was just on the right, now on left
local Pos = teamstats_listbox_layoutR.SelectedIdx

-- make sure the position isn't off the bottom of the listbox
Pos = ScriptCB_TeamStatsValidatePos( 0, Pos );

teamstats_listbox_layoutL.CursorIdx = Pos
teamstats_listbox_layoutR.CursorIdx = nil
teamstats_listbox_layoutL.SelectedIdx = Pos
teamstats_listbox_layoutR.SelectedIdx = Pos

ListManager_fnFillContents(this.LeftList,teamstats_listbox_contentsL,teamstats_listbox_layoutL)
ListManager_fnFillContents(this.RightList,teamstats_listbox_contentsR,teamstats_listbox_layoutR)
-- Just move cursor on side that's now dim
ListManager_fnMoveCursor(this.RightList,teamstats_listbox_layoutR)
else
-- Was just on the left, now on right
local Pos = teamstats_listbox_layoutL.SelectedIdx

-- make sure the position isn't off the bottom of the listbox
Pos = ScriptCB_TeamStatsValidatePos( 1, Pos );

teamstats_listbox_layoutR.CursorIdx = Pos
teamstats_listbox_layoutL.CursorIdx = nil
teamstats_listbox_layoutR.SelectedIdx = Pos
teamstats_listbox_layoutL.SelectedIdx = Pos

ListManager_fnFillContents(this.LeftList,teamstats_listbox_contentsL,teamstats_listbox_layoutL)
ListManager_fnFillContents(this.RightList,teamstats_listbox_contentsR,teamstats_listbox_layoutR)
-- Just move cursor on side that's now dim
ListManager_fnMoveCursor(this.LeftList,teamstats_listbox_layoutL)
end
end

--validate the cursor position (make sure we're not on a null entry)
function ifs_teamstats_fnValidateCursor(this)
local Pos = teamstats_listbox_layoutL.SelectedIdx
if(this.bCursorOnLeft) then
Pos = ScriptCB_TeamStatsValidatePos( 0, Pos );
else
Pos = ScriptCB_TeamStatsValidatePos( 1, teamstats_listbox_layoutR.SelectedIdx );
end

--set the cursor to the validated position
teamstats_listbox_layoutL.SelectedIdx = Pos
teamstats_listbox_layoutR.SelectedIdx = Pos

if(this.bCursorOnLeft) then
teamstats_listbox_layoutL.CursorIdx = Pos
teamstats_listbox_layoutR.CursorIdx = nil
else
teamstats_listbox_layoutL.CursorIdx = nil
teamstats_listbox_layoutR.CursorIdx = Pos
end
ListManager_fnMoveCursor(this.LeftList,teamstats_listbox_layoutL)
ListManager_fnMoveCursor(this.RightList,teamstats_listbox_layoutR)
end

-- turn the selected item gSelectedTextColor (currently blue)
function ifs_teamstats_fnUpdateTeamSelection(this)
--print ("ifs_teamstats_fnUpdateTeamSelection")
if (this.bCursorOnLeft) then
local cursorIdx = teamstats_listbox_layoutL.CursorIdx
local firstShownIdx = teamstats_listbox_layoutL.FirstShownIdx
if ( cursorIdx and gSelectedTextColor ) then
--if ( not this.LeftList[cursorIdx] ) then
-- print ("not this.LeftList[cursorIdx]", cursorIdx, teamstats_listbox_layoutL.SelectedIdx, teamstats_listbox_layoutR.FirstShownIdx)
--else print ("this.leftlist[cursoridx]")
--end

IFObj_fnSetColor(this.LeftList[cursorIdx-firstShownIdx+1].labelstr, gSelectedTextColor[1], gSelectedTextColor[2], gSelectedTextColor[3])
end
else
local cursorIdx = teamstats_listbox_layoutR.CursorIdx
local firstShownIdx = teamstats_listbox_layoutR.FirstShownIdx
if ( cursorIdx and gSelectedTextColor ) then
--if ( not this.RightList[cursorIdx] ) then
-- print ("not this.RightList[cursorIdx]", cursorIdx)
--else print ("this.RightList[cursoridx]") end
IFObj_fnSetColor(this.RightList[cursorIdx-firstShownIdx+1].labelstr, gSelectedTextColor[1], gSelectedTextColor[2], gSelectedTextColor[3])
end
end
end

ifs_teamstats = NewIFShellScreen {
nologo = 1,
fMAX_IDLE_TIME = 30.0,
fCurIdleTime = 0,
movieIntro = nil, -- played before the screen is displayed
movieBackground = nil, -- played while the screen is displayed
bAcceptIsSelect = 1,
bNohelptext_back = 1, -- We use PS2-Square/XBox-X to exit this screen.

-- title = NewIFText {
-- string = "ifs.stats.teamstatstitle",
-- font = "gamefont_large",
-- y = 0,
-- textw = 460, -- center on screen. Fixme: do real centering!
-- ScreenRelativeX = 0.5, -- center
-- ScreenRelativeY = 0, -- top
-- ColorR= 255, ColorG = 255, ColorB = 255, -- Something that's readable!
-- },

titleTeamStats = NewIFText {
string = "ifs.stats.teamstatstitle",
font = "gamefont_medium",
ScreenRelativeX = 0.5,
ScreenRelativeY = 0.017,
textw = 150,
ColorR= gTitleTextColor[1], ColorG = gTitleTextColor[2], ColorB = gTitleTextColor[3], -- Something that's readable!
style = "normal",
--nocreatebackground = 1,
halign = "hcenter",
bgleft = "bf2_buttons_topleft",
bgmid = "bf2_buttons_title_center",
bgright = "bf2_buttons_topright",
bg_width = 460,
},

titleAwards = NewIFText {
string = "ifs.stats.awards",
font = "gamefont_medium",
ScreenRelativeX = 0.5,
ScreenRelativeY = 0.637,
textw = 350,
ColorR= gTitleTextColor[1], ColorG = gTitleTextColor[2], ColorB = gTitleTextColor[3], -- Something that's readable!
style = "normal",
--nocreatebackground = 1,
halign = "hcenter",
bgleft = "bf2_buttons_topleft",
bgmid = "bf2_buttons_title_center",
bgright = "bf2_buttons_topright",
bg_width = 460,
},

bgTexture = NewIFImage {
ZPos = 250,
ScreenRelativeX = 0,
ScreenRelativeY = 0,
UseSafezone = 0,
texture = "statsscreens_bg",
localpos_l = 0,
localpos_t = 0,
-- Size, UVs aren't fully specified here, but in NewIFShellScreen()
},


bCursorOnLeft = 1,

Enter = function(this, bFwd)
gIFShellScreenTemplate_fnEnter(this, bFwd) -- call default enter function

-- if we're in MP and the client never received stats, just skip the stats and go
-- back to the shell now
if(not ScriptCB_ClientGotStats()) then
ScriptCB_QuitFromStats()
ScriptCB_SndPlaySound("shell_menu_exit");
return
end

if(this.Helptext_Back) then
IFText_fnSetString(this.Helptext_Accept.helpstr,"ifs.stats.personalstatstitle")
gHelptext_fnMoveIcon(this.Helptext_Accept)
end

if(bFwd) then
-- Horrible hack -- We need the memory on the PS2 for the stats,
-- and the only way to get that now is to kick some screens out of
-- memory.
if(gPlatformStr == "PS2") then
-- ifs_pausemenu = nil -- die if we ever exit out of here.
ifs_opt_controller = nil -- we need memory, NOW
ifs_mp_lobby = nil -- we need memory, NOW
ifs_sideselect = nil
ifs_charselect = nil
ifs_mapselect = nil
ifs_readyselect = nil
ifs_fakeconsole = nil
end
this.bCursorOnLeft = 1
teamstats_listbox_layoutL.FirstShownIdx = 1
teamstats_listbox_layoutR.FirstShownIdx = 1
teamstats_listbox_layoutL.SelectedIdx = 1
teamstats_listbox_layoutR.SelectedIdx = 1
teamstats_listbox_layoutL.CursorIdx = 1
teamstats_listbox_layoutR.CursorIdx = nil

this.SetCursorToPlayer = 1
end
ifs_teamstats_fnFillContents(this)
this.SetCursorToPlayer = nil
ifs_teamstats_fnUpdateTeamSelection(this)

this.fCurIdleTime = this.fMAX_IDLE_TIME

if(gE3Build) then
if(ScriptCB_GetAmHost()) then
gE3StatsTimeout = 15
else
gE3StatsTimeout = 20
end
else
gE3StatsTimeout = 0 -- can quit right away
end

if(gPlatformStr == "PC") then --quickee hack for PC
gE3StatsTimeout = 0
end

if((ScriptCB_InNetGame()) and (ScriptCB_GetGameRules() == "metagame") and (ScriptCB_GetAmHost())) then
this.fCurIdleTime = 0
gE3StatsTimeout = 0
end
end,

Exit = function(this, bFwd)
-- Reduce lua memory, glyphcache usage
ifs_teamstats_fnBlankContents(this)
teamstats_listbox_contents = nil
teamstats_listbox_contentsL = nil
teamstats_listbox_contentsR = nil
teamstats_awardsListbox_contents = nil
teamstats_awardsListbox_contentsL = nil
teamstats_awardsListbox_contentsR = nil
end,

-- Accept button bumps the page
Input_Accept = function(this)

if(this.bCursorOnLeft) then
ifs_personalstats.fTeam = 1
ifs_personalstats.fIdx = teamstats_listbox_layoutL.SelectedIdx
else
ifs_personalstats.fTeam = 2
ifs_personalstats.fIdx = teamstats_listbox_layoutR.SelectedIdx
end
ifs_movietrans_PushScreen(ifs_personalstats)
ScriptCB_SndPlaySound("shell_menu_enter");
this.fCurIdleTime = this.fMAX_IDLE_TIME
end,

-- Misc ( == PS2-Square/XBox-X) button quits stats
Input_Misc = function(this)
if(ScriptCB_CanClientLeaveStats()) then
this.fCurIdleTime = this.fMAX_IDLE_TIME
if(not gE3StatsTimeout or gE3StatsTimeout < 0) then
ScriptCB_QuitFromStats()
ScriptCB_SndPlaySound("shell_menu_exit");
end
end
end,

--Back button quits stats
Input_Back = function(this)
this.fCurIdleTime = this.fMAX_IDLE_TIME
--ScriptCB_PopScreen()
--ScriptCB_SndPlaySound("shell_menu_exit");
end,

-- No U/D/L/R functionality possible on this screen (gotta have stubs
-- here, or the base class will override)

Input_GeneralUp = function(this)
this.fCurIdleTime = this.fMAX_IDLE_TIME
ListManager_fnNavUp(this.LeftList,teamstats_listbox_contentsL,teamstats_listbox_layoutL)
ListManager_fnNavUp(this.RightList,teamstats_listbox_contentsR,teamstats_listbox_layoutR)
ifs_teamstats_fnUpdateTeamSelection(this)
ifs_teamstats_fnValidateCursor(this)
end,
Input_GeneralDown = function(this)
this.fCurIdleTime = this.fMAX_IDLE_TIME
ListManager_fnNavDown(this.LeftList,teamstats_listbox_contentsL,teamstats_listbox_layoutL)
ListManager_fnNavDown(this.RightList,teamstats_listbox_contentsR,teamstats_listbox_layoutR)
--validate the cursor position (make sure we're not on a null entry)
ifs_teamstats_fnValidateCursor(this)
ifs_teamstats_fnUpdateTeamSelection(this)
end,

Input_LTrigger = function(this)
this.fCurIdleTime = this.fMAX_IDLE_TIME
ListManager_fnPageUp(this.LeftList,teamstats_listbox_contentsL,teamstats_listbox_layoutL)
ListManager_fnPageUp(this.RightList,teamstats_listbox_contentsR,teamstats_listbox_layoutR)
ifs_teamstats_fnUpdateTeamSelection(this)
ifs_teamstats_fnValidateCursor(this)
end,
Input_RTrigger = function(this)
this.fCurIdleTime = this.fMAX_IDLE_TIME
ListManager_fnPageDown(this.LeftList,teamstats_listbox_contentsL,teamstats_listbox_layoutL)
ListManager_fnPageDown(this.RightList,teamstats_listbox_contentsR,teamstats_listbox_layoutR)
--validate the cursor position (make sure we're not on a null entry)
ifs_teamstats_fnValidateCursor(this)
ifs_teamstats_fnUpdateTeamSelection(this)
end,

Input_GeneralLeft = function(this)
this.fCurIdleTime = this.fMAX_IDLE_TIME
ifs_teamstats_fnFlipLeftRight(this)
ScriptCB_SndPlaySound("shell_select_change");
ifs_teamstats_fnUpdateTeamSelection(this)
ifs_teamstats_fnValidateCursor(this)
end,
Input_GeneralRight = function(this)
this.fCurIdleTime = this.fMAX_IDLE_TIME
ifs_teamstats_fnFlipLeftRight(this)
ScriptCB_SndPlaySound("shell_select_change");
ifs_teamstats_fnUpdateTeamSelection(this)
ifs_teamstats_fnValidateCursor(this)
end,

Update = function(this, fDt)
-- Call default base class's update function (make button bounce)
gIFShellScreenTemplate_fnUpdate(this,fDt)

-- If the host is busy, then wait on this screen
if(fDt > 0.5) then
fDt = 0.5 -- clamp this to sane values
end

if(ScriptCB_CanClientLeaveStats()) then
gE3StatsTimeout = 0 -- allow quit now
if(this.Helptext_Done) then
IFObj_fnSetVis(this.Helptext_Done, 1) -- show helptext
end
else
gE3StatsTimeout = 1 -- keep clients from leaving
if(this.Helptext_Done) then
IFObj_fnSetVis(this.Helptext_Done, nil) -- hide helptext
end
end

if(gE3StatsTimeout) then
gE3StatsTimeout = gE3StatsTimeout - fDt
end

-- if we've been sitting here for a while, bail to the teaser screen
this.fCurIdleTime = this.fCurIdleTime - fDt
if((this.fCurIdleTime < 0) and (not gE3StatsTimeout or gE3StatsTimeout < 0)) then
this.fCurIdleTime = 100
ScriptCB_QuitFromStats()
ScriptCB_SndPlaySound("shell_menu_exit");
end
end,


-- Callback (from C++) to repaint the listbox with the current contents
-- in the global teamstats_listbox_contents
RepaintListbox = function(this, bOnLeft)
--print ("RepaintListbox")
if(bOnLeft ) then
teamstats_listbox_layoutR.CursorIdx = nil
else
teamstats_listbox_layoutL.CursorIdx = nil
end
ListManager_fnFillContents(this.LeftList,teamstats_listbox_contentsL,teamstats_listbox_layoutL)
ListManager_fnFillContents(this.RightList,teamstats_listbox_contentsR,teamstats_listbox_layoutR)
ListManager_fnFillContents(this.awardsLeftList,teamstats_awardsListbox_contentsL,teamstats_awardsListbox_layoutL)
ListManager_fnFillContents(this.awardsRightList,teamstats_awardsListbox_contentsR,teamstats_awardsListbox_layoutR)
end,

}

-- Helper function, sets up parts of this screen that need any
-- programmatic work (i.e. scaling to screensize)
function ifs_teamstats_fnBuildScreen(this)
-- Ask game for screen size, fill in values
local r, b, v, widescreen = ScriptCB_GetScreenInfo()
this.bgTexture.localpos_l = 0
this.bgTexture.localpos_t = 0
this.bgTexture.localpos_r = r*widescreen
this.bgTexture.localpos_b = b
this.bgTexture.uvs_b = v

--if(this.Helptext_Back) then
-- IFText_fnSetString(this.Helptext_Back.helpstr,"ifs.stats.back")
--end

if(gPlatformStr ~= "PC") then
this.Helptext_Done = NewHelptext {
ScreenRelativeX = 0.0, -- left
ScreenRelativeY = 1.0, -- bottom
y = -15, -- just above bottom
x = 0,
buttonicon = "btnmisc",
string = "ifs.stats.done",
}
end

-- Inset slightly from fulls screen size
local w,h = ScriptCB_GetSafeScreenInfo()
-- w = w * 0.95
--h = h * 0.82

this.listbox = NewButtonWindow { ZPos = 200, x=0, y = 0,
ScreenRelativeX = 0.5, -- center
ScreenRelativeY = 0.345, -- top part of screen
width = w,
height = h * 0.54,
}

-- Cut width in half for 2-column layout, make containers to drop them into
w = w * 0.5
this.LeftList = NewIFContainer {
ScreenRelativeX = 0.5,
ScreenRelativeY = 0.32,
x =-w * 0.5
}
this.RightList = NewIFContainer {
ScreenRelativeX = 0.5,
ScreenRelativeY = 0.32,
x = w * 0.5
}

-- awards
this.awardsListbox = NewButtonWindow { ZPos = 200, x=0, y = 0,
ScreenRelativeX = 0.5, -- center
ScreenRelativeY = 0.805, -- bottom part of screen
width = w * 2,
height = h * 0.22,
}

this.awardsLeftList = NewIFContainer {
ScreenRelativeX = 0.5,
ScreenRelativeY = 0.805,
x =-w * 0.5
}

this.awardsRightList = NewIFContainer {
ScreenRelativeX = 0.5,
ScreenRelativeY = 0.805,
x = w * 0.5
}

local offset_x = 0.062
local offset_w = 0.120

this.LeftList.ColumnHeader1 = NewIFImage {
x = w * (offset_x + 0*offset_w), y = h * -0.22,
texture = "points", -- .tga assumed
localpos_r = w*0.07, localpos_b = h*0.04,
inert = 1,
}
this.LeftList.ColumnHeader2 = NewIFImage {
x = w * (offset_x + 1*offset_w), y = h * -0.22,
texture = "stats_kills", -- .tga assumed
localpos_r = w*0.07, localpos_b = h*0.04,
inert = 1,
}
this.LeftList.ColumnHeader3 = NewIFImage {
x = w * (offset_x + 2*offset_w), y = h * -0.22,
texture = "stats_deaths", -- .tga assumed
localpos_r = w*0.07, localpos_b = h*0.04,
inert = 1,
}
this.LeftList.ColumnHeader4 = NewIFImage {
x = w * (offset_x + 3*offset_w), y = h * -0.22,
texture = "stats_flags", -- .tga assumed
localpos_r = w*0.07, localpos_b = h*0.04,
inert = 1,
}
this.LeftList.TeamIcon = NewIFImage {
x = -w * 0.3, y = h * -0.22,
texture = "stats_cpp", -- .tga assumed
localpos_r = w*0.07, localpos_b = h*0.04,
inert = 1,
}

this.RightList.ColumnHeader1 = NewIFImage {
x = w * (offset_x + 0*offset_w), y = h * -0.22,
texture = "points", -- .tga assumed
localpos_r = w*0.07, localpos_b = h*0.04,
inert = 1,
}
this.RightList.ColumnHeader2 = NewIFImage {
x = w * (offset_x + 1*offset_w), y = h * -0.22,
texture = "stats_kills", -- .tga assumed
localpos_r = w*0.07, localpos_b = h*0.04,
inert = 1,
}
this.RightList.ColumnHeader3 = NewIFImage {
x = w * (offset_x + 2*offset_w), y = h * -0.22,
texture = "stats_deaths", -- .tga assumed
localpos_r = w*0.07, localpos_b = h*0.04,
inert = 1,
}
this.RightList.ColumnHeader4 = NewIFImage {
x = w * (offset_x + 3*offset_w), y = h * -0.22,
texture = "stats_flags", -- .tga assumed
localpos_r = w*0.07, localpos_b = h*0.04,
inert = 1,
}
this.RightList.TeamIcon = NewIFImage {
x = - w * 0.3, y = h * -0.22,
texture = "stats_cpp", -- .tga assumed
localpos_r = w*0.07, localpos_b = h*0.04,
inert = 1,
}

-- set the team icon textures
local team1 = ScriptCB_TeamStatsGetTeam1();
if(team1 == 1) then -- aliance
this.LeftList.TeamIcon.texture = "all_icon"
this.RightList.TeamIcon.texture = "imp_icon"
elseif(team1 == 2) then
this.LeftList.TeamIcon.texture = "imp_icon"
this.RightList.TeamIcon.texture = "all_icon"
elseif(team1 == 3) then
this.LeftList.TeamIcon.texture = "rep_icon"
this.RightList.TeamIcon.texture = "cis_icon"
else
this.LeftList.TeamIcon.texture = "cis_icon"
this.RightList.TeamIcon.texture = "rep_icon"
end

this.titleTeamStats.bg_width = w*2 * 0.945
this.titleTeamStats.bgoffsetx = w * -0.009
this.titleTeamStats.bgexpandy = 6
this.titleAwards.bg_width = w*2 * 0.945
this.titleAwards.bgoffsetx = w * -0.009
this.titleAwards.bgexpandy = 6

teamstats_listbox_layoutL.fontheight = ScriptCB_GetFontHeight(teamstats_listbox_layoutL.font)
teamstats_listbox_layoutL.yHeight = math.max(26,teamstats_listbox_layoutL.fontheight)
teamstats_listbox_layoutR.fontheight = ScriptCB_GetFontHeight(teamstats_listbox_layoutR.font)
teamstats_listbox_layoutR.yHeight = math.max(26,teamstats_listbox_layoutR.fontheight)

teamstats_listbox_layoutL.width = w
teamstats_listbox_layoutR.width = teamstats_listbox_layoutL.width
teamstats_listbox_layoutL.showcount = math.floor(this.listbox.height / (teamstats_listbox_layoutL.yHeight + teamstats_listbox_layoutL.ySpacing)) - 2
teamstats_listbox_layoutR.showcount = teamstats_listbox_layoutL.showcount

teamstats_awardsListbox_layoutL.fontheight = ScriptCB_GetFontHeight(teamstats_awardsListbox_layoutL.font)
teamstats_awardsListbox_layoutL.yHeight = math.max(18,teamstats_awardsListbox_layoutL.fontheight)
teamstats_awardsListbox_layoutR.fontheight = ScriptCB_GetFontHeight(teamstats_awardsListbox_layoutR.font)
teamstats_awardsListbox_layoutR.yHeight = math.max(18,teamstats_awardsListbox_layoutR.fontheight)

teamstats_awardsListbox_layoutL.width = w
teamstats_awardsListbox_layoutR.width = teamstats_awardsListbox_layoutL.width
teamstats_awardsListbox_layoutL.showcount = 4 --math.floor(this.awardsListbox.height / (teamstats_awardsListbox_layoutL.yHeight + teamstats_awardsListbox_layoutL.ySpacing)) - 1
teamstats_awardsListbox_layoutR.showcount = 4 --teamstats_awardsListbox_layoutL.showcount

ListManager_fnInitList(ifs_teamstats.LeftList,teamstats_listbox_layoutL)
ListManager_fnInitList(ifs_teamstats.RightList,teamstats_listbox_layoutR)
ListManager_fnInitList(ifs_teamstats.awardsLeftList,teamstats_awardsListbox_layoutL)
ListManager_fnInitList(ifs_teamstats.awardsRightList,teamstats_awardsListbox_layoutR)
end


ifs_teamstats_fnBuildScreen(ifs_teamstats) -- programatic chunks
ifs_teamstats_fnBuildScreen = nil

AddIFScreen(ifs_teamstats,"ifs_teamstats")
ifs_teamstats = DoPostDelete(ifs_teamstats)

[/code]
Last edited by Anakin on Thu Feb 20, 2014 11:28 am, edited 1 time in total.
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: Different lua questions

Post by Locutus »

I think it would be easier if you marked changes in red.
User avatar
Anakin
Master of the Force
Master of the Force
Posts: 4817
Joined: Sat Sep 19, 2009 11:37 am
Projects :: RC Side Mod - Remastered - SWBF3 Legacy
Location: Mos Espa (germany)

Re: Different lua questions

Post by Anakin »

I changed nothing but the font names.
User avatar
Nedarb7
Lieutenant General
Lieutenant General
Posts: 676
Joined: Sat Sep 22, 2012 3:41 pm

Re: Different lua questions

Post by Nedarb7 »

What does the common.req look like? Also is it loaded in the LUA?
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Different lua questions

Post by [RDH]Zerted »

You need to provide more information about that first script. What is it called? Which folder is it in? Your common.req. Any munge errors after cleaning and remunging. Which lines did you change. How do you know it isn't loaded. Etc...

If you put a print statement at the bottom of the file you'll know if the problem is that it isn't being loaded or if you changes aren't working.


As for the pausemenu, this line: "this.buttons.console.hidden = gFinalBuild" hides the console button. There's probably a few more lines you'll need to change if you want to see those buttons. You need to walk through all the code to see how it interacts with itself.
User avatar
Anakin
Master of the Force
Master of the Force
Posts: 4817
Joined: Sat Sep 19, 2009 11:37 am
Projects :: RC Side Mod - Remastered - SWBF3 Legacy
Location: Mos Espa (germany)

Re: Different lua questions

Post by Anakin »

Hi,

so the script names are:
1. ifs_teamstats
2. ifs_pausemenu

These are the stock ones i found in the C:\BF2_ModTools\data_RCM\Common\scripts folder.

this is my common.req
Hidden/Spoiler:
[code]
ucft
{
REQN
{
"script"
"ifs_pausemenu"
"ifs_awardstats"
"ifs_fakeconsole"
"popup_ab"
"popup_busy"
"popup_loadsave2"
"popup_ok"
"popup_yesno"
"popup_yesno_large"
"popups_common"
"popups_lobby"
"popup_vote"
}

REQN
{
"textures"
"points"
"stats_kills"
}
}
[/code]
The problem is that after i add the ifs_teamstat script, or the ifs_personalstats, or the ifs_careerstats script to the common.req they don't work anymore.
So i know that they are not loaded, because after you play a game and won the next game starts directly and there is no stat displayed. if i only have the careerstats and personalstats in the common.req the teamstats are shown, but the button for personal stats,.. don't work.

So what i changed is only this. you see in all these files things like that:
font = gMenuButtonFont,

or
font = "gamefont_large"

I changed them to
font = "gamefon_large_rc"

For the pausemenu it works fine, only that the freecam, etc buttons are not shown.
@[RDH]Zerted: thanks for the tipp i'll have a look at this.

my luas look like that:
Hidden/Spoiler:
[code]
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

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


ReadDataFile("dc:common.lvl")
ReadDataFile("common.lvl")
-- These variables do not change
ATT = 1
DEF = 2

-- Empire Attacking (attacker is always #1)
CIS = ATT
REP = DEF

---------------------------------------------------------------------------
-- 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 ScriptPostLoad()
.
.
.
[/code]

Also i first tryed to get the fonts on the stat screen working by adding the red line to the ObjectiveConquest file (it's loaded in the mission.req). (After i have no idea of the BBCode from the colors i underlined it)
Hidden/Spoiler:
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

ScriptCB_DoFile("Objective")

--=============================
-- CommandPost
-- Class representing a specific CP, allowing some measure of customization
-- of what happens at each post when it is captured
--=============================
CommandPost =
{
-- fields that need to be specified when calling New()
name = "noname", --name of the CP

-- Overridable functions
OnCapture = function()
--override me to customize behavior when the command post is captured
end,
}

function CommandPost:New(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end

--=============================
-- ObjectiveConquest
-- Handles the logic for a conquest game (A.K.A. capture the command posts)
--=============================
ObjectiveConquest = Objective:New
{
-- external values
icon = "hud_objective_icon_circle",

-- internal values
defaultBleedRate = 0.3333333333, --how many units will be lost per second
defeatTimerSeconds = 20, --how long the defeat timer lasts after capping the all the CPs
}

function ObjectiveConquest:GetOpposingTeam(team)
if team == self.teamATT then
return self.teamDEF
else
return self.teamATT
end
end


function ObjectiveConquest:AddCommandPost(cp)
--make sure we have a table to add the cp to
self.commandPosts = self.commandPosts or {}

--do all the error checking we can on the cp
assert(cp.name, "WARNING: no name supplied for the command post")
cp.name = string.lower(cp.name)

self.commandPosts[cp.name] = cp

--keep a running tally of the bleedValue relative to each team
if not self.totalBleedValue then
self.totalBleedValue = {}
self.totalBleedValue[self.teamATT] = 0
self.totalBleedValue[self.teamDEF] = 0
end
self.totalBleedValue[self.teamATT] = self.totalBleedValue[self.teamATT] + GetCommandPostBleedValue(cp.name, self.teamATT)
self.totalBleedValue[self.teamDEF] = self.totalBleedValue[self.teamDEF] + GetCommandPostBleedValue(cp.name, self.teamDEF)
end


--Add a threshold value for bleeding. Basically
function ObjectiveConquest:AddBleedThreshold(team, threshold, rate)
--assert(team == self.teamATT or team == self.teamDEF, "invalid team!")

if not self.bleedRates then
--initialize the bleedRates two-dimensional array
self.bleedRates = {}
self.bleedRates[self.teamATT] = {}
self.bleedRates[self.teamDEF] = {}
end

self.bleedRates[team][threshold] = rate
end

-- Get game time limit as set in game options menu, if any. 0 if none.
function ObjectiveConquest:GetGameTimeLimit()
return ScriptCB_GetCONMaxTimeLimit()
end

function ObjectiveConquest:GameOptionsTimeLimitUp()
local team1pts = GetReinforcementCount(1)
local team2pts = GetReinforcementCount(2)
if ( team1pts > team2pts ) then
MissionVictory(1)
elseif ( team1pts < team2pts ) then
MissionVictory(2)
else
--tied, so victory for both
MissionVictory({1,2})
end
end

function ObjectiveConquest:Start()
--===============================
-- Local functions
--===============================


local UpdateBleedRate = function(team)
--count up the total bleedPoints (bleedPoints only count if they're on a CP owned by a different team)
local bleedPoints = 0
for i, cp in pairs(self.commandPosts) do
local cpTeam = GetObjectTeam(cp.name)
if cpTeam == self:GetOpposingTeam(team) then
--print("cp.name:", cp.name, "bleedPoints:", GetCommandPostBleedValue(cp.name, cpTeam)) --uncomment me for test output!
bleedPoints = bleedPoints + GetCommandPostBleedValue(cp.name, cpTeam)
end
end


--set the bleed rate based on the total accumulated bleedPoints
local bleedRate = 0.0
if self.bleedRates and self.bleedRates[team] then
--look through the unsorted list for the highest threshold that bleedPoints is higher than
local highestThresholdSoFar = 0
for threshold, rate in pairs(self.bleedRates[team]) do
if bleedPoints >= threshold and threshold > highestThresholdSoFar then
bleedRate = rate
highestThresholdSoFar = threshold
end
end
else
--default bleeding rule is to start bleeding when the team's bleed points are greater
--than half the total points
if bleedPoints > (self.totalBleedValue[team] / 2.0) then
bleedRate = self.defaultBleedRate
end
end

--print("totalbleedpts:", self.totalBleedValue[team]) --uncomment me for test output!
--print("team:", team, "bleedPoints:", bleedPoints, "bleedRate:", bleedRate) --uncomment me for test output!

--setup the bleedrate display (i.e. how fast the score flashes in the HUD)
SetBleedRate(team, bleedRate)

if bleedRate > 0.0 then
--start bleeding reinforcements
StopTimer(self.bleedTimer[team])
SetTimerValue(self.bleedTimer[team], 1.0)
SetTimerRate(self.bleedTimer[team], bleedRate)
StartTimer(self.bleedTimer[team])
else
--stop bleeding reinforcements
StopTimer(self.bleedTimer[team])
end
end


--turns off the timers and resets the winningTeam number
local DisableWinnerDoodads = function()
self.winningTeam = 0
StopTimer(self.defeatTimer)

--hide the timers (HACK: this way of displaying the lose timer should be updated to use new HUD code)
SetDefeatTimer(nil, self.teamATT)
SetVictoryTimer(nil, self.teamATT)
SetDefeatTimer(nil, self.teamDEF)
SetVictoryTimer(nil, self.teamDEF)
end


local UpdateState = function()
if self.multiplayerRules then
UpdateBleedRate(self.teamDEF)
UpdateBleedRate(self.teamATT)
end

--check to see if one team (the winningTeam) has all the CPs
self.winningTeam = 0
for i, cp in pairs(self.commandPosts) do
--NOTE: destroyed CP's aren't supposed to count against the win/loss accounting
if IsObjectAlive(cp.name) then
local cpTeam = GetObjectTeam(cp.name)

if cpTeam == 0 then
--can't have a winner if one of the CPs is still neutral
DisableWinnerDoodads()
return
elseif self.winningTeam == 0 then
--start tracking this team that might be winning
self.winningTeam = cpTeam
elseif self.winningTeam ~= cpTeam then
--there is no winner, since we just found two CP's that don't match
DisableWinnerDoodads()
return
end
end
end

if self.winningTeam ~= 0 then
if self.disallowDefensiveVictory and self.winningTeam ~= self.teamATT then
return
end

if self.multiplayerRules then
--start the defeat timer to end the game in a few seconds
SetTimerValue(self.defeatTimer, self.defeatTimerSeconds)
StartTimer(self.defeatTimer)

--tell the C++ code about the defeat/victory timer (which will display it on the HUD)
SetDefeatTimer(self.defeatTimer, self:GetOpposingTeam(self.winningTeam))
SetVictoryTimer(self.defeatTimer, self.winningTeam)
else
--end the objective immediately
self:Complete(self.winningTeam)
end
end
end


local InitBleedTimer = function(team)
self.bleedTimer[team] = CreateTimer("bleed" .. team)

OnTimerElapse(
function (timer)
if GetReinforcementCount(team) > GetNumTeamMembersAlive(team) then
--tick off a reinforcement when the timer elapses, and start it up again
if GetReinforcementCount(team) > 0 then
AddReinforcements(team, -1)
end
SetTimerValue(timer, GetTimerValue(timer) + 1.0)
StartTimer(timer)
else
--disallow bleeding when a team gets really low on reinforcements (so the team
--doesn't run entirely out of units due to bleedrate, as per designer request)
SetBleedRate(team, 0.0)
StopTimer(timer)
end
end,
self.bleedTimer[team]
)
end


local InitDefeatTimer = function()
self.defeatTimer = CreateTimer("defeat")
SetTimerRate(self.defeatTimer, 1.0)

OnTimerElapse(
function (timer)
StopTimer(timer)
SetReinforcementCount(self:GetOpposingTeam(self.winningTeam), 0)
self:Complete(self.winningTeam)
end,
self.defeatTimer
)
end


local UpdatePostMapMarker = function(postPtr)
if not self.multiplayerRules then
--check the team that capped the CP, and change the map marker accordingly
if GetObjectTeam(postPtr) == self.teamATT then
MapRemoveEntityMarker(postPtr, self.teamATT)
else
MapAddEntityMarker(postPtr, self.icon, 4.0, self.teamATT, "YELLOW", true)
end
end
end

--==========
-- Set the number of guys in the level to number in game options
--==========
ScriptCB_SetNumBots(ScriptCB_GetCONNumBots())

--===============================
-- Initialization logic
--===============================
--initialize the base objective data first
Objective.Start(self)

--initialize internal values
self.commandPosts = self.commandPosts or {}

self.bleedTimer = {}
InitBleedTimer(self.teamATT)
InitBleedTimer(self.teamDEF)

InitDefeatTimer()

if self.multiplayerRules then
self.disallowDefensiveVictory = false
else
self.disallowDefensiveVictory = true --in single player/co-op, the defense can't win by capping all the CPs
end

numCPs = 0
for i, cp in pairs(self.commandPosts) do
if not self.multiplayerRules then
MapAddEntityMarker(cp.name, self.icon, 4.0, self.teamATT, "YELLOW", true)
end
numCPs = numCPs + 1
end
if(numCPs == 0) then
print ("ERROR: no valid CommandPosts were added to the ObjectiveConquest")
return
end

--set AI goals
self.AIGoals = {}
if self.AIGoalWeight > 0.0 then
table.insert(self.AIGoals, AddAIGoal(self.teamATT, "Conquest", 100*self.AIGoalWeight))
table.insert(self.AIGoals, AddAIGoal(self.teamDEF, "Conquest", 100*self.AIGoalWeight))
end

--do an initial update on the state
UpdateState()

--=======================================
-- Event responses
--=======================================
-- command post captures
OnFinishCapture(
function (postPtr)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end

UpdatePostMapMarker(postPtr)
UpdateState()
end
)

-- command post neutralize
OnFinishNeutralize(
function (postPtr)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end

UpdatePostMapMarker(postPtr)
UpdateState()
end
)

-- command post spawn
OnCommandPostRespawn(
function (postPtr)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end

UpdatePostMapMarker(postPtr)
UpdateState()
end
)

-- command post kill
OnCommandPostKill(
function (postPtr)
if self.isComplete then return end
if not self.commandPosts[GetEntityName(postPtr)] then return end

if not self.multiplayerRules then
MapRemoveEntityMarker(postPtr, self.teamATT)
end

UpdateState()
end
)
end

function ObjectiveConquest:Complete(winningTeam)
ReadDataFile("core.lvl")
if not self.multiplayerRules then
--remove all the cp markers
for i, cp in pairs(self.commandPosts) do
MapRemoveEntityMarker(cp.name)
end
end

--then call the default objective complete method
Objective.Complete(self, winningTeam)
end
The first times it worked. When you see the victory screen the ligning becomes a strange looking but than you had the stock fonts loaded and all was displayed. But after a while it only worked from time to time and now it doesn't work anymore. And i haven't changed something on this.
That's why i would like to make the changes in the stats scripts. But than there are no stats shown up -.-

==EDIT==

@[RDH]Zerted: The Freecam now works :D Thank you very much for this tipp.
My only problem is now, that the fakeconsole does not display all commands.
Do you maybe know how to add the victory command?? because i don't want to play the game allways to see if the stats now work.
Post Reply