centerprint help
Moderator: InsideQC Admins
6 posts
• Page 1 of 1
centerprint help
hey wondering if anyone could help me, i want to centerprint a message but have it change depending on a variable, is this possible without just making if statements and every possible text variation?... let me word this better. my mod contains the ability to upgrade a class-type charactoristic (mage, robot, alien...) and you can upgrade with whichever you prefer to use at the time of upgrade. so when your experience points have reached the next level, and the menu comes up to choose the next ability you wouid like, the menu reflects your current upgrades and the next level of that upgrade.
ex:
local string skill1text, skill2text;
if (self.skill1 == 1)
{
sskill = "mage level 1: power to bargain with car dealers"
}
if (self.skill2 == 1)
{
sskill = "squirell level 1: climb trees"
}
if (self.skill2 == 2)
{
sskill = "squirell level 2: eat my nuts"
}
// then while the menu is open...
centerprint(self," MENU!\n" , skill1text , skill2text, "=====\n");
};
hope someone gets what im saying and has an answer that will make me happy
thanks-
root one
ex:
local string skill1text, skill2text;
if (self.skill1 == 1)
{
sskill = "mage level 1: power to bargain with car dealers"
}
if (self.skill2 == 1)
{
sskill = "squirell level 1: climb trees"
}
if (self.skill2 == 2)
{
sskill = "squirell level 2: eat my nuts"
}
// then while the menu is open...
centerprint(self," MENU!\n" , skill1text , skill2text, "=====\n");
};
hope someone gets what im saying and has an answer that will make me happy
thanks-
root one
-

RooT - Posts: 40
- Joined: Wed Sep 07, 2005 1:28 am
If you're using FrikQCC or FTEQCC as compiler, you can open up defs.qc and replace the centerprint definition with:
void(entity client, string s, ...) centerprint = #73;
This will allow you to include up to 7 strings in a row in the centerprint command. (because builtin functions have a limit of 8 arguments)
If you're using an older compiler, replace centerprint in defs.qc with:
void(entity client, string s) centerprint = #73;
void(entity client, string s1, string s2) centerprint2 = #73;
void(entity client, string s1, string s2, string s3) centerprint3 = #73;
void(entity client, string s1, string s2, string s3, string s4) centerprint4 = #73;
void(entity client, string s1, string s2, string s3, string s4, string s5) centerprint5 = #73;
void(entity client, string s1, string s2, string s3, string s4, string s5, string s6) centerprint6 = #73;
void(entity client, string s1, string s2, string s3, string s4, string s5, string s6, string s7) centerprint7 = #73;
And use the appropriate one based on how many arguments you need.
If you need more than 7 different strings put together, there are further ways to do it, but they are hacky and will only be explained to you if you really need them
void(entity client, string s, ...) centerprint = #73;
This will allow you to include up to 7 strings in a row in the centerprint command. (because builtin functions have a limit of 8 arguments)
If you're using an older compiler, replace centerprint in defs.qc with:
void(entity client, string s) centerprint = #73;
void(entity client, string s1, string s2) centerprint2 = #73;
void(entity client, string s1, string s2, string s3) centerprint3 = #73;
void(entity client, string s1, string s2, string s3, string s4) centerprint4 = #73;
void(entity client, string s1, string s2, string s3, string s4, string s5) centerprint5 = #73;
void(entity client, string s1, string s2, string s3, string s4, string s5, string s6) centerprint6 = #73;
void(entity client, string s1, string s2, string s3, string s4, string s5, string s6, string s7) centerprint7 = #73;
And use the appropriate one based on how many arguments you need.
If you need more than 7 different strings put together, there are further ways to do it, but they are hacky and will only be explained to you if you really need them
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
- Sajt
- Posts: 1215
- Joined: Sat Oct 16, 2004 3:39 am
Remember that you can only have 1 ftos in each print, or the last one will override all the ones before it. If you need more, I recommend you use Darkplaces because it has strcat and string zones to get around 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.
- Wazat
- Posts: 771
- Joined: Fri Oct 15, 2004 9:50 pm
- Location: Middle 'o the desert, USA
coud you explain?
wazat what do you mean i can only have one ftos? this wouldnt work?:
if (self.showtext)
{
local string t1, t2, t3;
t1 = ftos(self.inside);
t2 = ftos(self.3d);
t3 = ftos(self.rules);
centerprint5(self, "You know what?\n", t1, t2, t3);
that would work i thought?
if (self.showtext)
{
local string t1, t2, t3;
t1 = ftos(self.inside);
t2 = ftos(self.3d);
t3 = ftos(self.rules);
centerprint5(self, "You know what?\n", t1, t2, t3);
that would work i thought?
-

RooT - Posts: 40
- Joined: Wed Sep 07, 2005 1:28 am
Re: coud you explain?
RooT wrote:t1 = ftos(self.inside);
t2 = ftos(self.3d);
t3 = ftos(self.rules);
centerprint5(self, "You know what?\n", t1, t2, t3);
Unfortunately that won't work.
The problem is that ftos puts the string in a buffer. All strings in QC are actually just pointers to some memory location that's holding the string. Constant strings (s1 = "bleh") are always fine; however, when you say t1 = ftos(self.inside), t1 is pointing to ftos's buffer.
What this all means is, if I set t1 to point to the ftos buffer (asking ftos to convert a number in the process), then convert one or two more numbers, t1-t3 will all have the same value, because each call to ftos just overwrites what's in the buffer at the moment.
Thus, if self.rules is 10, your centerprint will print:
You know what?
10 10 10
The reason sprints work so well with this is, you call ftos, and then sprint it out. Then you call ftos again and sprint it out:
- Code: Select all
s = ftos(a1);
sprint(a1);
s = ftos(a2);
sprint(a2);
s = ftos(a3);
sprint(a3);
Thus, the number is printed and properly used before ftos erases and writes over it.
The best way around this for centerprints is to use strcat() or string zones, both of which usually come together and are provided by new engines like Darkplaces.
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.
- Wazat
- Posts: 771
- Joined: Fri Oct 15, 2004 9:50 pm
- Location: Middle 'o the desert, USA
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest