ensiform Posted March 20, 2006 Share Posted March 20, 2006 Here's a fix, because if you try this with your text auto wrap func it will not show up correctly: ^7Capture the Flag,\n^1All kills legal^7!\n\n^3www^7.^3WildJedi^7.^3com^7 You will see: Capture the Flag, All kills legal http://www.WildJedi.com its a pretty easy fix just add this function: // replaces all occurances of "\n" with '\n' char *Q_AddCR(char *s) { char *copy, *place, *start; if(!*s) return s; start = s; while(*s) { if(*s == '\\') { copy = s; place = s; *s++; if(*s && *s == 'n') { *copy = '\n'; while(*++s) { *++copy = *s; } *++copy = '\0'; s = place; continue; } } *s++; } return start; } Also, the auto lose color on new line bug is fixed in here as well as adding the Q_AddCR() to the TextWrapCenterPrint: //[AdminSys] void TextWrapCenterPrint(char orgtext[centerPRINT_MAXSTRING], char output[centerPRINT_MAXSTRING]) {//this function auto text wraps a centersay message so that it will display correctly on clients that aren't //running OJP. Clients running OJP do this text wrapping on the client side. //scan thru print text and add new lines where needed. int orgIndex, outputIndex, charCounter; char lastColor = '7'; Q_AddCR(orgtext); for(orgIndex = 0, outputIndex = 0, charCounter = 0; orgIndex < CENTERPRINT_MAXSTRING && outputIndex < CENTERPRINT_MAXSTRING; orgIndex++, charCounter++, outputIndex++) { if(orgtext[orgIndex] == '\n') {//manual newline, reset charCounter charCounter = -1; } if(charCounter == 50) {//this line is too long for the basejka client, add a line break. if( !BG_IsWhiteSpace(orgtext[orgIndex]) && !BG_IsWhiteSpace(orgtext[orgIndex-1]) ) {//we might have cut a word off, attempt to find a spot where we won't cut words off at. int savedOrgIndex = orgIndex; int savedOutputIndex = outputIndex; for(; orgIndex >= 0; orgIndex--, outputIndex--) { if(BG_IsWhiteSpace(orgtext[orgIndex])) {//this location is whitespace, line break from this position //advance the orgIndex back to the first letter of the word that we're going to //wrap to the next line. orgIndex++; break; } } if(orgIndex < 0) {//couldn't find a break in the text, just go ahead and cut off the word mid-word. orgIndex = savedOrgIndex; outputIndex = savedOutputIndex; } } //add line break at proper position. output[outputIndex] = '\n'; //reset charCounter, set to -1 to account for autoincrement charCounter = -1; //decrement orgtext index so we'll try to recopy this char on the next pass. orgIndex--; continue; } //line isn't too long yet, just straight copy this char to the output. output[outputIndex] = orgtext[orgIndex]; if(output[outputIndex] == '\0') {//we're done break; } if(output[outputIndex] == '^' && orgtext[orgIndex+1] != '^') { charCounter -= 2; } } for( orgIndex=0; orgIndex < outputIndex; orgIndex++ ) { if(output[orgIndex] == '^' && ( output[orgIndex+1] >= '0' && output[orgIndex+1] <= '7' )) lastColor = output[orgIndex+1]; else if(output[orgIndex] == '\n') { Com_sprintf(output+orgIndex+1,CENTERPRINT_MAXSTRING-orgIndex-1,"%c%c%s",'^',lastColor,output+orgIndex+1); orgIndex += 2; } } } //[/AdminSys] i forgot there is also a fix but it really didnt seem to be the problem of what was fixed above: you forgot to clear the line ("i") when there is a new line. void CG_CenterPrint( const char *str, int y, int charWidth ) { char *s; //[bugFix19] int i = 0; //[/bugFix19] Q_strncpyz( cg.centerPrint, str, sizeof(cg.centerPrint) ); cg.centerPrintTime = cg.time; cg.centerPrintY = y; cg.centerPrintCharWidth = charWidth; // count the number of lines for centering cg.centerPrintLines = 1; s = cg.centerPrint; while( *s ) { //[bugFix19] i++; if(i >= 50) {//maxed out a line of text, this will make the line spill over onto another line. i = 0; cg.centerPrintLines++; } else if (*s == '\n') { //if (*s == '\n') //[/bugFix19] i = 0; cg.centerPrintLines++; } s++; } } also a fix for blank names which can occur if you try something like name "^1 ". it also doesnt allow clients to use ^8 and ^9 since they really are not colors: The following originally goes to MasterHex who did xMod but it had a bug that wouldnt allow ^'s in the text. The fix for that here though goes to me and dumbledore. void RealCleanName(char *name, char *out, int outlen) { qboolean valid = qfalse; char *wp = out, *rp, *rap; //write, read, and readahead for(rp = name; *rp == ' '; rp++); //eat leading spaces while(*rp) { if (*rp == '^') //oh no, we have a color code { for(rap = rp; *rap && *++rap == '^';*wp++ = '^'); //find the first non^ if (*rap <= '7' && *rap >= '0') //if it's a valid color code (between 7 and 1 and 0) // if (*rap <= '7' && *rap >= '0' + !rs_blacknames.integer) //if it's a valid color code (between 7 and 1 if rs_blacknames.integer is 0, 7 and 0 otherwise) { if (wp - out < outlen) *wp++ = *rp; //copy one ^ if (wp - out < outlen) *wp++ = *rap;//as well as the number } else if (*rap != '8' && *rap != '9') { if (wp - out < outlen) *wp++ = *rp; //copy one ^ if (wp - out < outlen) *wp++ = *rap;//as well as the letter } rp = rap; //skip the color string... it has been written if it's a valid one } else { if (wp - out < outlen) *wp++ = *rp; //length checking... just to make sure we don't run over the edge of the out string and crash the server... o_O } if (*rp) rp++; //read the next one if there is a next one... (a bad color string at the end will cause rp to point to the ending null char) } while(*--wp == ' '); //from the end of the line, look backwards for the first non-space. *++wp = 0; //go back to the space and make a null character (this clips trailing spaces) rp = out; while(*rp) { if (*rp != ' ' && *rp != '^') valid = qtrue; if (*rp == '^') rp++; if (*rp) rp++; } if (!valid) strcpy(out, "Padawan"); //if, after all that, we're left with nothing, name them Padawan } just call that function instead of ClientCleanName Link to comment Share on other sites More sharing options...
JRHockney* Posted March 20, 2006 Share Posted March 20, 2006 Hey! I can actually understand alot of that. And I only know some Java!........Hooray! Link to comment Share on other sites More sharing options...
JRHockney* Posted March 20, 2006 Share Posted March 20, 2006 Hey! I can actually understand alot of that. And I only know some Java!........Hooray! Link to comment Share on other sites More sharing options...
ensiform Posted March 20, 2006 Author Share Posted March 20, 2006 lol and i thought java was weird. i prefer c and c++ much better. Link to comment Share on other sites More sharing options...
razorace Posted March 20, 2006 Share Posted March 20, 2006 Ok, thanks for the fixes Ensiform. However, please make sure that you compiled/tested code before you post it, there's a minor typo in the first code snippet. Link to comment Share on other sites More sharing options...
razorace Posted March 21, 2006 Share Posted March 21, 2006 Say, is it really nessicary to preserve the line color between newlines? Does the game do that normally? Link to comment Share on other sites More sharing options...
Lathain Valtiel Posted March 21, 2006 Share Posted March 21, 2006 Technically, no. That said, it's very convienent and if it's not resource draining I request that it remain in. Link to comment Share on other sites More sharing options...
ensiform Posted March 22, 2006 Author Share Posted March 22, 2006 well its supposed to and there was a fix for it for CG_DrawStringExt but JKA doesnt use that for centerprint drawing and CG_Text_Paint is an engine trap call so i cant really fix it that way and + this makes it so that ppl without client can use it. o rly? it works just fine here. which did u think was the typo? Link to comment Share on other sites More sharing options...
razorace Posted April 22, 2006 Share Posted April 22, 2006 Com_sprintf(output+orgIndex+1,CENTERPRINT_MAXSTRIN G-orgIndex-1,"%c%c%s",'^',lastColor,output+orgIndex+1); The "CENTERPRINT_MAXSTRIN G" has to be a typo. Anyway, sorry to zombie this thread but I finally had some time and I was going over your cp_color_fix.txt file that you sent me. What was the point of it again? I don't understand why you're setting setColor to color. Link to comment Share on other sites More sharing options...
ensiform Posted April 22, 2006 Author Share Posted April 22, 2006 ah well that doesnt even work with jka for cp anyway, the CP doesn't use drawext. i had fixed it for q3 and et. so the auto putting the color code on next line is done now and its server side so ppl without clients can notice the change. LOL! i just noticed it, and it only appears in the code thingy here, its normal in my code its even normal when i click edit to fix it here Link to comment Share on other sites More sharing options...
razorace Posted April 22, 2006 Share Posted April 22, 2006 So, the cp_color_fix.txt stuff wasn't actually needed then? Link to comment Share on other sites More sharing options...
ensiform Posted April 23, 2006 Author Share Posted April 23, 2006 no it wasn't. the textwrapcenterprint above fixes the lose color on new line prob. prolly should send u these in aim or something cuz this board seems to have some weird cut-off values or something. Link to comment Share on other sites More sharing options...
razorace Posted April 23, 2006 Share Posted April 23, 2006 That would be great. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.