MenuQC Help Needed

Discuss programming in the QuakeC language.
Post Reply
MauveBib
Posts: 634
Joined: Thu Nov 04, 2004 1:22 am

MenuQC Help Needed

Post by MauveBib »

Hey all, long time no see!

I'm working on a big project at the moment, and it's one that really needs menuqc.

Does anyone have any (working) links to any mods with sample menuqc I can take a look at? Other than Nexuiz/Whateverit'scallednow and the non-working DPMod code?

Cheers
Apathy Now!
MauveBib
Posts: 634
Joined: Thu Nov 04, 2004 1:22 am

Re: MenuQC Help Needed

Post by MauveBib »

More specifically, I need help with getting a working server browser, and text input boxes (for things like player name).
Apathy Now!
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: MenuQC Help Needed

Post by Spike »

http://triptohell.info/moodles/junk/csqcmenujunk.zip
menusys/mitem_servers.qc has some basic server browser stuff.


there's some programmable sort of logic that is used to determine if each server is considered 'visible' or not. mostly this is overkill and can be implemented in the qc instead, but if you know how it works it can be handy as a speedup
resethostcachemasks(); //clear server filters.
sethostcachemaskstring(0, gethostcacheindexforkey("gamedir"), MOD_GAMEDIR, SLIST_TEST_EQUAL); //filters out any servers that do not equal MOD_GAMEDIR.

you'll probably want this too. it'll save you from doing it from qc code. you can sort by other things instead, like "numplayers".
sethostcachesort(gethostcacheindexforkey("ping"), TRUE); //sort the list by ping

this is also vitally important...
refreshhostcache(); //actually pings the master servers
because without that, you won't have any servers on your list at all. you only need one call to it and certainly mustn't spam it. the engine will update the list each frame according to your filters.
note that it will run asyncronously and will take a few seconds to complete, and that qc has no real way to know if it has actually completed or not.


and finally, to print out (replace print with the relevent draw calls yourself) a list of ip addresses, do:

Code: Select all

numservers = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT) //returns how many servers passed the filters
for(i = 0; i < numservers; i++)
{
field_address = gethostcacheindexforkey("address") //gets a handle to the address/ip column.
print("Server ip: ", gethostcachestring(field_address, i), "\n");
}
you can use name/numplayers/maxplayers/address/ping/map/gamedir 'cache index' values to retrieve a handle to those keys for printing/displaying those bits of information instead.
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: MenuQC Help Needed

Post by Baker »

:!: It has been a long time.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
MauveBib
Posts: 634
Joined: Thu Nov 04, 2004 1:22 am

Re: MenuQC Help Needed

Post by MauveBib »

Thanks a lot, that's really helpful.

I'm having a bit of difficulty pulling through "gamedir"; the check for the correct gamedir isn't working and when I try to display it it's blank... Likewise I'm struggling to pull the server address through. I only seem to be able to pull through the "name" and "ping"...

Also, how would I go about having an input text box for the player to type things in e.g. server name, player name etc?
Apathy Now!
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: MenuQC Help Needed

Post by Spike »

try 'game' instead of 'gamedir'?
I guess fte is a bit more permissive

regarding text entry, you'll have to draw it yourself. my version has that code in mitem_edittext.qc in that zip I already linked.
for menuqc specifically, m_keydown takes two arguments. the first is the 'scancode', the second is the 'charcode'. if its a proper text char (a-z, A-Z, 0-9, punctuation, etc) then the charcode value will contain a non-zero value.
you can then:
curval = strcat(curval, chr2str(charcode));
to append the printable char.
however you'll first want to check the scancode to see if its backspace or delete and use substring accordingly instead, of course (specify -1 for the length if you want the entire rest of the string by the way).

but yeah, you guessed it. draw it yourself, and do your own keyboard input.

once you do have text entry working, you can just sethostcachemaskstring() and then redo your sethostcachemaskstring calls with the new settings. the list should update accordingly.
MauveBib
Posts: 634
Joined: Thu Nov 04, 2004 1:22 am

Re: MenuQC Help Needed

Post by MauveBib »

Yeah, I pretty much figured that'd be the case for text boxes.

"game" works, but only pulls through "Darkplaces-Quake" for everything, so it's not much use for filtering on. Hmm.
Apathy Now!
MauveBib
Posts: 634
Joined: Thu Nov 04, 2004 1:22 am

Re: MenuQC Help Needed

Post by MauveBib »

Ok, a bit of trial and error, and the field name we're after is "mod".
Apathy Now!
MauveBib
Posts: 634
Joined: Thu Nov 04, 2004 1:22 am

Re: MenuQC Help Needed

Post by MauveBib »

Ok, really weird one.

To start a server I've got a button that runs the following:

cmd ("map start");

This works fine as long as the client has already been in a map, but if it's done straight from the menu without entering a map first it crashes DP half way through loading the map. Typing it from the console works fine.

I can even go into a map from the console, then crash out of the map back to the console and then the button will work, but straight from loading it crashes DP...

Anyone have any ideas at all?
Apathy Now!
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: MenuQC Help Needed

Post by Spike »

define 'crash'.

there's no \n of course. but that shouldn't crash the engine, you'll just get some message about the map 'start<SOMECONSOLECOMMAND>' not being found when you next trigger some console command.
MauveBib
Posts: 634
Joined: Thu Nov 04, 2004 1:22 am

Re: MenuQC Help Needed

Post by MauveBib »

Physically crash out of the engine, window message "darkplaces has crashed..." or whatever.

I've tried with and without \n.
Apathy Now!
LordHavoc
Posts: 322
Joined: Fri Nov 05, 2004 3:12 am
Location: western Oregon, USA
Contact:

Re: MenuQC Help Needed

Post by LordHavoc »

Try "\nmap start\n" and see if that does anything good? The crash is definitely a bug though.
MauveBib
Posts: 634
Joined: Thu Nov 04, 2004 1:22 am

Re: MenuQC Help Needed

Post by MauveBib »

In the end I threw in a massive hack to just load a map at the start of the game and force the menu over the top, but obviously if it's fixable that'd be way better.

I'm away from home for a few more weeks but I'll have a play when I get back.
Apathy Now!
Post Reply