Better way to centerprint

Discuss programming in the QuakeC language.
Post Reply
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Better way to centerprint

Post by Wazat »

I've been using SVC_CENTERPRINT and WriteChar to do my shop printing in Conquest. However, I have a need to be able to write strings too, so I don't have to separate everything into one letter at a time, which would be a disaster to try and implement. I'm trying to add weapon and shield descriptions to the shop, which would involve full sentences and even item stats (pulled from the code using ftos), so you can imagine how maddening it will be to try to make that work using chars only.

So, can I use WriteString as well as WriteChar, at least in Darkplaces? Would there be any compadibility issues with other engines?

If I can't do strings, then what I'll probably do is send the player to a different menu screen that uses centerprint(self, "blah blah...") whenever the player asks for a description of something, let him scroll up and down with the arrow keys, and then return him to where he was before when he presses the confirm or cancel key. It's just that I don't *want* to do that. ;)
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

You can writechar strings, though it takes FRIK_FILE's substring function to do it, and one huuuuge fatoff if statement to do it.

The downside of writestring is that it includes a null terminator.
On the upside, WriteString works in any engine.
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Post by Wazat »

I considered using substring, and that wouldn't be too hard, but I'd be further isolating the non-DP users. I'm still willing to do it tho...

So with WriteString, its null terminator will end the centerprint, and I won't be able to centerprint any more after that? That limits its usefulness. :(
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
c0burn
Posts: 208
Joined: Fri Nov 05, 2004 12:48 pm
Location: Liverpool, England
Contact:

Post by c0burn »

Wazat wrote:I considered using substring, and that wouldn't be too hard, but I'd be further isolating the non-DP users. I'm still willing to do it tho...

So with WriteString, its null terminator will end the centerprint, and I won't be able to centerprint any more after that? That limits its usefulness. :(
Sort of. He means that every Writestring does a "\n" automatically - So it's a bit of a pain if you didn't want a new line right there.
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Post by Wazat »

Hmmm... that's a problem too. It would be nice if DP included a special WriteString that doesn't have that problem.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

c0burn wrote:Sort of. He means that every Writestring does a "\n" automatically - So it's a bit of a pain if you didn't want a new line right there.
Wrong. I mean a null terminator of zero value terminating the string. No new line about it. The centerprint ends then and there, any more chars will (probably) result in the client disconnecting (and probably in a hideous way).

FRIK_FILE can be found in DP, Telejano, FTE, 50 other engines...
Every worthwhile (modders) engine has a form of it. It might take the form of QSG_FILE or evil evil mvdsv hacks, but they all have a form, and strangly all with the same args. The only people you'd isolate are origional dosquake users and quakeworld users.

Tell the dosquake users to get linux and that one's solved, tell the quakeworld users to use FTE as thier server and that ones solved (wasn't really an issue anyway seeing as the progs is a subtly different 'format' anyway).

The downside of substring is that it uses temporary strings...
And I'm betting you're relying on the fact that the engine has 16 temp strings (meaning you need DP or FTE anyway, both of which support FRIK_FILE).

I don't see it as an issue that you'll prevent origional id builds from running your mod as a server. DP and FTE are fine for dedicated servers to those backwards clients.
Tei
Posts: 193
Joined: Mon Oct 25, 2004 12:22 pm

Post by Tei »

returning to roots,...

the solution can be to build the string offline, then send the string. You can do that with zone strings (the frika extensions)

as Spike say, WriteString append a \0 so you cant send more than one string

anyway, If FrikaC can make impresive mods like Prydon Gate that run on ... anithing, maybe what Wazat need its already solved on PG code or other FrikaC mod

Whats exactly the problem? What you need and its imposible or dificult with normal code?

if a solutions on QC its boring and long, you dont need to write everything yourself....
You can use other lang, like C++ or PERL to generalte loooong sections of QC code to parse stuff on a dumb way. I
noctrun
Posts: 5
Joined: Mon Nov 15, 2004 10:58 am

Post by noctrun »

prydon gate way let's you setup the entire screen letter by letter line by line in a way that works in any quake engine

however you can't print strings with it, but if your engine supports FRIK_FILE you can add it's easy to add that:

Code: Select all

float(string str) indexed =
{
	     if (str == "\{32}") { return 32; }
	else if (str == "\{33}") { return 33; }
	else if (str == "\{34}") { return 34; }
	else if (str == "\{35}") { return 35; }
	else if (str == "\{36}") { return 36; }
	else if (str == "\{37}") { return 37; }
	else if (str == "\{38}") { return 38; }
	else if (str == "\{39}") { return 39; }
	else if (str == "\{40}") { return 40; }
	else if (str == "\{41}") { return 41; }
	else if (str == "\{42}") { return 42; }
	else if (str == "\{43}") { return 43; }
	else if (str == "\{44}") { return 44; }
	else if (str == "\{45}") { return 45; }
	else if (str == "\{46}") { return 46; }
	else if (str == "\{47}") { return 47; }
	else if (str == "\{48}") { return 48; }
	else if (str == "\{49}") { return 49; }
	else if (str == "\{50}") { return 50; }
	else if (str == "\{51}") { return 51; }
	else if (str == "\{52}") { return 52; }
	else if (str == "\{53}") { return 53; }
	else if (str == "\{54}") { return 54; }
	else if (str == "\{55}") { return 55; }
	else if (str == "\{56}") { return 56; }
	else if (str == "\{57}") { return 57; }
	else if (str == "\{58}") { return 58; }
	else if (str == "\{59}") { return 59; }
	else if (str == "\{60}") { return 60; }
	else if (str == "\{61}") { return 61; }
	else if (str == "\{62}") { return 62; }
	else if (str == "\{63}") { return 63; }
	else if (str == "\{64}") { return 64; }
	else if (str == "\{65}") { return 65; }
	else if (str == "\{66}") { return 66; }
	else if (str == "\{67}") { return 67; }
	else if (str == "\{68}") { return 68; }
	else if (str == "\{69}") { return 69; }
	else if (str == "\{70}") { return 70; }
	else if (str == "\{71}") { return 71; }
	else if (str == "\{72}") { return 72; }
	else if (str == "\{73}") { return 73; }
	else if (str == "\{74}") { return 74; }
	else if (str == "\{75}") { return 75; }
	else if (str == "\{76}") { return 76; }
	else if (str == "\{77}") { return 77; }
	else if (str == "\{78}") { return 78; }
	else if (str == "\{79}") { return 79; }
	else if (str == "\{80}") { return 80; }
	else if (str == "\{81}") { return 81; }
	else if (str == "\{82}") { return 82; }
	else if (str == "\{83}") { return 83; }
	else if (str == "\{84}") { return 84; }
	else if (str == "\{85}") { return 85; }
	else if (str == "\{86}") { return 86; }
	else if (str == "\{87}") { return 87; }
	else if (str == "\{88}") { return 88; }
	else if (str == "\{89}") { return 89; }
	else if (str == "\{90}") { return 90; }
	else if (str == "\{91}") { return 91; }
	else if (str == "\{92}") { return 92; }
	else if (str == "\{93}") { return 93; }
	else if (str == "\{94}") { return 94; }
	else if (str == "\{95}") { return 95; }
	else if (str == "\{96}") { return 96; }
	else if (str == "\{97}") { return 97; }
	else if (str == "\{98}") { return 98; }
	else if (str == "\{99}") { return 99; }
	else if (str == "\{100}") { return 100; }
	else if (str == "\{101}") { return 101; }
	else if (str == "\{102}") { return 102; }
	else if (str == "\{103}") { return 103; }
	else if (str == "\{104}") { return 104; }
	else if (str == "\{105}") { return 105; }
	else if (str == "\{106}") { return 106; }
	else if (str == "\{107}") { return 107; }
	else if (str == "\{108}") { return 108; }
	else if (str == "\{109}") { return 109; }
	else if (str == "\{110}") { return 110; }
	else if (str == "\{111}") { return 111; }
	else if (str == "\{112}") { return 112; }
	else if (str == "\{113}") { return 113; }
	else if (str == "\{114}") { return 114; }
	else if (str == "\{115}") { return 115; }
	else if (str == "\{116}") { return 116; }
	else if (str == "\{117}") { return 117; }
	else if (str == "\{118}") { return 118; }
	else if (str == "\{119}") { return 119; }
	else if (str == "\{120}") { return 120; }
	else if (str == "\{121}") { return 121; }
	else if (str == "\{122}") { return 122; }
	else if (str == "\{123}") { return 123; }
	else if (str == "\{124}") { return 124; }
	else if (str == "\{125}") { return 125; }
	else			  { return 160; }
};

void(string str) pstr =
{
	local	float	str_cnt;
	local	float	sub_start;
	local	float	print;

	//this requires the FRIK_FILE
	str_cnt = strlen(str);

	while (str_cnt > 0)
	{
		print = indexed(substring(str, sub_start, 1));
		p1(print);
		sub_start = sub_start + 1;
		str_cnt = str_cnt - 1;
	}
};
Sajt
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Post by Sajt »

Or you could just strcat the thing together and use the builtin centerprint :p
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Post by Wazat »

Yea, that's probably what I'll do. I need to keep centerprints relatively short so they don't go off-screen, so I'll probably just have the stats of the item at the bottom of the screen, with a description scrolling across to keep it from taking too much room (which is easy to do with substring).

Something like:

Code: Select all

	Rocket Launcher
Cost			2200
Credits			110064

	Choose slot:
	1. Axe
	2. Shotgun
	3. Bio Rifle
	4. Empty
	5. Empty

  [es unguided rockets for high dama]
(^ note that this is scrolling across the screen at a certain reasonable speed)

  Power	100	AtkSpd	 20
  Ammo	10	Capacity 30
  Ammo Price		 150
And, since these messages will always be at the end of the print (hopefully), I can just concatenate the needed information into a string and use writestring after all the stuff above it has been printed. It'll end the centerprint, but I would have had to end it anyway at that point.
Doing it this way, I can have a check in there to make sure the player's engine supports FRIK_FILE's strcat and substring functions. If not, I just won't print that part of the menu.

Hopefully it'll work like that, anyway... :?
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Post Reply