Page 1 of 1

Modes - Woot I did it all by my self

Posted: Thu Dec 27, 2007 10:42 am
by RepSharpshooter
How does one go about creating new modes, unique from the existing ones? Is there a limit to the number of modes? I dabbled around in the LUA scripts, and failed to find something related to modes. Teancum talked about hex editing the mission lvl. How is that done? And is there a way to just munge a script or something? I'm very ignorant on this issue. I'm sure there's something there, but I've been looking, and I don't know where to look.

Re: Modes

Posted: Thu Dec 27, 2007 1:14 pm
by Teancum
Creating all new modes requires rebuilding shell.lvl, which is not fun. However, if you want to add any modes from the Conversion Pack or the shipped game there's a few topics on it if you search.

Re: Modes

Posted: Thu Dec 27, 2007 1:40 pm
by RepSharpshooter
http://www.gametoast.com/forums/viewtop ... ll#p214061
Nothing was really accomplished there, but this seems to go over it, I'll see what I can do (may not be much, but I am a C++ programmer, whatever that's worth (probably not worth much either :funny2: ))

Re: Modes

Posted: Thu Dec 27, 2007 2:22 pm
by Teancum
Yeah, all that stuff is involved in building the shell. There's a few lua's you have to do a bunch of edits to, then icons and reqs. Plus it'll conflict with the convo pack shell. If I ever rebuild the convo pack shell I'll add however many modes you want.

Re: Modes

Posted: Thu Dec 27, 2007 3:11 pm
by RepSharpshooter
Hidden/Spoiler:
[code]{
key = "mode_ffa", showstr = "modename.name.ffa",
descstr = "modename.description.ffa", subst = "ffa",
icon = "mode_icon_XL",
},[/code]
I added this to missionlist.lua. There's no way this is all I have to do, due to it requiring a bunch of edits. I know I need to edit the addme.lua so this mode_ffa is called. I'll keep looking for luas to edit. Sorta groping in the dark though.

addme:
Hidden/Spoiler:
[code]sp_missionselect_listbox_contents[sp_n+1] = { isModLevel = 1, mapluafile = "RVK%s_%s", era_g = 1, era_c = 1, mode_con_g = 1, mode_con_c = 1, mode_ctf_g = 1, mode_ctf_c = 1, mode_eli_g = 1, mode_ffa = 1}
mp_n = table.getn(mp_missionselect_listbox_contents)
mp_missionselect_listbox_contents[mp_n+1] = sp_missionselect_listbox_contents[sp_n+1]

-- associate this mission name with the current downloadable content directory
-- (this tells the engine which maps are downloaded, so you need to include all new mission lua's here)
-- first arg: mapluafile from above
-- second arg: mission script name
-- third arg: level memory modifier. the arg to LuaScript.cpp: DEFAULT_MODEL_MEMORY_PLUS(x)

AddDownloadableContent("RVK","RVKg_con",4)
AddDownloadableContent("RVK","RVKc_con",4)
AddDownloadableContent("RVK","RVKg_ctf",4)
AddDownloadableContent("RVK","RVKc_ctf",4)
AddDownloadableContent("RVK","RVKg_eli",4)
AddDownloadableContent("RVK","RVKg_ffa",4)[/code]
I added a RVKg_ffa.lua, and it runs fine, it just doesn't show up in the mode select. So I'm beginning to try and find wherever they use modes. I see that they take the lua name (RVKg_ffa) and separate the ffa part of it, then match it with the key I made at the top of this post. In this current state, it doesn't work, so I'm going to look around and see what else calls modes.

EDIT did this:
Hidden/Spoiler:
[code]buttonlist = {
{ tag = "con", string = "modename.name.con", },
{ tag = "ctf", string = "modename.name.ctf", },
{ tag = "1flag", string = "modename.name.1flag", },
{ tag = "tdm", string = "modename.name.tdm", },
{ tag = "obj", string = "modename.name.obj", },
{ tag = "ffa", string = "modename.name.con", },
},[/code]
(I don't have a string for it yet, so conquest will do)


EDIT: Changed ifs_missionselect_pcmulti.lua as follows:
Hidden/Spoiler:
[code]
mode_list = {
{
key = "mode_con", showstr = "modename.name.con",
descstr = "modename.description.con", subst = "con",
icon = "mode_icon_con",
},
{
key = "mode_ctf", showstr = "modename.name.ctf",
descstr = "modename.description.ctf", subst = "ctf",
icon = "mode_icon_2ctf",
},
{
key = "mode_1flag", showstr = "modename.name.1flag",
descstr = "modename.description.1flag", subst = "1flag",
icon = "mode_icon_ctf",
},
{
key = "mode_assault", showstr = "modename.name.assault",
descstr = "modename.description.assault", subst = "Diet Dr. Pepper",
icon = "mode_icon_Diet Dr. Pepper",
},
{
key = "mode_hunt", showstr = "modename.name.hunt",
descstr = "modename.description.hunt", subst = "hunt",
icon = "mode_icon_hunt",
},
{
key = "mode_ffa", showstr = "modename.name.hunt",
descstr = "modename.description.hunt", subst = "ffa",
icon = "mode_icon_hunt",
},
}
[/code]
This adds the mode buttons?
Hidden/Spoiler:
[code]function ifs_missionselect_pcMulti_fnAddModeBoxes(this)

-- Now, do the boxes above and below the columns
local ColumnWidthL = 170
local ColumnWidthC = 200
local ColumnWidthR = 220
local ListHeightC = 170
local TopBoxHeight = 30 -- enough for two lines of text
local infobox_offset_y = 50 + 5
local infobox_offset_x = -38

local new_shell_offset_x = 240

local icon_x = 27
local icon_y = 18
local icon_height = 18
local icon_era_offset_y = 45

local era_text_offset_x = 32 + icon_height
local era_text_offset_y = 12

local era_check_offset_x = 10
local era_check_offset_y = 19

if( this == ifs_missionselect ) then
mode_list[6] =
{
key = "mode_xl", showstr = "modename.name.xl",
descstr = "modename.description.xl", subst = "xl",
icon = "mode_icon_XL",
}
end

this.mode_checkbox = NewIFContainer { --container for all the backgrounds
ScreenRelativeX = 0, -- left side of screen
ScreenRelativeY = 0, -- top
x = ColumnWidthL + infobox_offset_x + new_shell_offset_x - 50,
y = infobox_offset_y + ListHeightC + TopBoxHeight + icon_era_offset_y - 225, -- top-justify against left box
ZPos = 180,
}

local i
local Count = table.getn(mode_list)
print( "O HI!!! Count is: ", Count )

for i = 1,Count do
print( "YU GATTA! this is mode_list.key ", mode_list.key )
this.mode_checkbox = NewIFContainer {
--ScreenRelativeX = 0, -- left side of screen
--ScreenRelativeY = 0, -- top
--x = ColumnWidthL + infobox_offset_x + new_shell_offset_x - 50,
y = i * 20, -- top-justify against left box
--ZPos = 0,
bChecked = 1,
key = mode_list.key,

checkbox = NewIFImage {
--ZPos = 0,
x = era_check_offset_x, y = era_check_offset_y,
texture = "check_yes",
localpos_l = 1, localpos_t = 1,
localpos_r = 14, localpos_b = 14,
AutoHotspot = 1, tag = "check_mode" .. i,
bIsFlashObj = 1, flash_alpha = 1.0,
hotspot_width = 100,
},

text= NewIFText {
x = era_text_offset_x,
y = era_text_offset_y,
halign = "left", valign = "vcenter",
font = "gamefont_super_tiny",
textw = ColumnWidthR - 80, texth = TopBoxHeight,
startdelay=math.random()*0.5, nocreatebackground=1,
string = mode_list.showstr,
},

icon = NewIFImage {
--ZPos = 240,
localpos_l = icon_x,
localpos_r = icon_x + icon_height,
localpos_t = icon_y,
localpos_b = icon_y + icon_height,
--ColorR = 240,
--ColorG = 32,
--ColorB = 32,
texture = mode_list.icon,
},
}
end
end[/code]

It makes this.mode_checkbox which then checks against, uh something, still working on it. I need to find the part where it iterates through this and it is displayed.

This is what displays it? I think here it is checking if the key for the mode in the mission select list = the key in the check box. Then what does it do? I have no idea, displays it?
Hidden/Spoiler:
[code]
function ifs_missionselect_pcMulti_fnShowHideGameModes( this )
local i, j
local number = ifs_missionselect_pcMulti_fnGetNumSelectedMaps( this )
if( number > 1 ) then
ifs_missionselect_pcMulti_fnShowHideGameModesMulti( this )
else
for i = 1, table.getn(this.mode_checkbox) do
IFObj_fnSetVis(this.mode_checkbox, nil)
for j = 1, table.getn(gMissionselectModes) do
if( ( this.mode_checkbox.key == gMissionselectModes[j].key ) or
( (this.mode_checkbox.key == "mode_assault") and (gMissionselectModes[j].key == "mode_eli") ) )then
-- make "mode_eli" equal to "mode_assault" for mos eisley
print(" missionselect_listbox_contents[ifs_mspc_MapList_layout.SelectedIdx].mapluafile = ", missionlist_GetLocalizedMapName( missionselect_listbox_contents[ifs_mspc_MapList_layout.SelectedIdx].mapluafile ) )
IFObj_fnSetVis(this.mode_checkbox, 1)
end
end
end
end[/code]


Hmm I may just end up using Zerted's shell, lol. I still want to know how this works though, I'm a lot farther into understanding how the game works. If I just sat back and went off the work of others, I wouldn't have learned anything useful to me later.

Edit: missionlist_ExpandModelist is used in missionselect_pcmulti when you select a map, it returns which modes it has. I'm going to print that out, and I'll see if the addme lua correctly added a "ffa" mode.

EDIT: Ok, so missionlist_ExpandModelist returned an array with 4 elements, hence 4 modes were detected from my addme lua. That's good. Here is a function that calls missionlist_ExpandModelist. Its name: ShowHideGameModes. So I think this is were things either work/don't work. I'm assuming my little mode_ffa was sent in ret from missionlist_ExpandModelist, (I DON'T KNOW CAUSE I DON'T KNOW HOW To print out elements of a table and the lua resources are too blah). So Assuming the mode_ffa went into that, it must be something here that is screwy.
Hidden/Spoiler:
[code]function ifs_missionselect_pcMulti_fnShowHideGameModesMulti( this )
local i, j
for i = 1, table.getn(missionselect_listbox_contents) do
if( missionselect_listbox_contents.bSelected ) then
local MapSelection = missionselect_listbox_contents
local MissionselectModes = missionlist_ExpandModelist(MapSelection.mapluafile)
for j = 1, table.getn(MissionselectModes) do
for k = 1, table.getn(this.mode_checkbox) do
if( ( this.mode_checkbox[k].key == MissionselectModes[j].key ) or
( (this.mode_checkbox[k].key == "mode_assault") and (MissionselectModes[j].key == "mode_eli") ) )then
IFObj_fnSetVis(this.mode_checkbox[k], 1)
end
end
end
end
end
end[/code]


EDIT: Ok blah = 3 and gibble is 4. blah SHOULD be 4 and gibble should be 5 I think.
Blah = number of modes in the mode list
gibble = number of elements returned from missionlist_ExpandModelist

So ExpandModelist isn't doing it's job, it's missing my ffa mode. I'll look around and see what's up.

EDIT: this is what printed out of that ^ function:
Gibble chuh: ret 1 modename.name.con
Gibble chuh: ret 2 modename.name.ctf
Gibble chuh: ret 3 modename.name.assault
Gibble chuh: ret 4 modename.name._all_modes_
That's why gibble is one more than blah. All modes is on the end :? And it looks like I need to replace the modename.name with ffa or else it won't work, I'll do that.

EDIT WOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOT

It worked
Addme lua needed to be mode_ffa_g not just mode_ffa xD
Hey you could use this as a strange tutorial if I clean it up.
Now, about localizing it, hopefully, I can just put it in my addon folder, and it'll read the local core keys.

EDIT: Localizing via addme script = fail. I don't know how else to localize it. Even with zerted's shell, how would I localize it? Can't you define hard coded strings in the LUA? I don't care if the germans can't read it :P

Re: Modes - Woot I did it all by my self

Posted: Fri Dec 28, 2007 1:48 am
by authraw
With such descriptive variables as "gibble" and "blah", it's no wonder you were able to figure it out on your own. :)

Way to go! Now I just need a nice big chunk of free time so I can try to follow what you did here and another chunk to decide whether or not it's really worth pursuing. ;)

Re: Modes - Woot I did it all by my self

Posted: Fri Dec 28, 2007 11:15 am
by Teancum
It's best to localize without replacing core.lvl. I had a custom core.lvl, but never could get the sound settings right, causing it to be much harder on a sound card (mine would constantly give out that annoying sound you get when you push a card to hard).

As far as localizing it, there's an easier way. In ifs_missionselect_pcmulti.lua change

{
key = "mode_ffa", showstr = "modename.name.ffa",
descstr = "modename.description.ffa", subst = "[Diet Dr Pepper]",
icon = "mode_icon_Diet Dr. Pepper",
},

to

{
key = "mode_ffa", showstr = "Free For All (appears next to checkbox)",
descstr = "RepSharpShooter's description (appears at the bottom)", subst = "[Diet Dr Pepper]",
icon = "mode_icon_Diet Dr. Pepper",
},

The icons need to be added to shell.req so to have them appear. Other than that you've got it. Actually, there's some steps you don't even need. I mostly discouraged it due to the fact that I didn't know how good of a coder you were. If I remember right I just added to ifs_missionselect_pcmulti.lua and then added the new icon to the req. Any of the actual custom code for that mode goes in /data_###/common/scripts

Re: Modes - Woot I did it all by my self

Posted: Fri Dec 28, 2007 11:34 am
by RepSharpshooter
Now I thought I could do that, somehow, last time I tried to define a string like that, it didn't work, so I was weary about it, but I knew it could be done like that. Yeah there may be some steps I didn't need, because half the time I didn't even know what I was doing. It turned out my addme lua was wrong, and my mode could have worked a long time ago.

One thing though, I'd like to warn you about (Zerted probably already fixed it being the genius he is, but)
In ifs_missionselect_pcmulti, in function ifs_missionselect_pcMulti_fnAddModeBoxes(this), theres a couple lines of code:

Code: Select all

if( this == ifs_missionselect ) then
		mode_list[6] = 
		{
			key = "mode_xl", showstr = "modename.name.xl",
			descstr = "modename.description.xl", subst = "xl",
			icon = "mode_icon_XL",
		}
	end
Now the lazy coders put 6 in instead of a constant, or looking up how many previous modes there were. When I added a mode, I needed to change it to 7. I'd replace that number with table.getn(mode_list) to make it redundant no matter how many modes you add. Or you could just add this to the mode_list array, doesn't matter. When I left it at 6, it'd overwrite the XL key over my FFA (both being at location 6)