

ondrawscript data/scripts/bossname.c
void main(){
void self = getlocalvar("self");
void Name = getentityproperty(self, "name");
int hRes = openborvariant("hresolution");
if(findtarget(self)){
settextobj(37, (hRes-strwidth(Name,0))/2 + 73, 11, 0, 8000, Name); //settextobj(index, x, y, font, z, text)
}
}
strwidth(string)
EXAMPLE: strwidth("HELLO");
- it returns the string width in pixels depending by the font.
- if the width of the character is 6 pixels and the string is "HELLO"
- strwidth("HELLO") will returns 6x5 = 30 (30 pixels)
- useful to align a string in the screen specially if you use multi-byte strings.
// settextobj(int index, int x, int y, int font, int z, char text, int time {optional})
void main(){
void self = getlocalvar("self");
void Name = getentityproperty(self, "name");
int hRes = openborvariant("hresolution");
drawstring((hRes-strwidth(Name,0))/2 + 73, 11, 0, Name);
}
I see a problem here. If you are using ondrawscript, why are you using settextobj? This will constantly create a text obj, over and over, for the same text.This one is simply done with ondrawscript (which I just made for you), and you should use settextobj for this.
void main(){
void self = getlocalvar("self"); // get self
void bossName = getentityproperty(self, "name"); // get boss name
//drawstring(int x, int y, int font#, text, layer)
drawstring( 140, 30,0,bossName);
}
You are right about the use of drawstring which works well, and I kept on not noticing on mine (without a second thought). I didn't check carefully that drawstring still works, and it does. The reason I did put settextobj was because of the crash every time I used it. I got mixed up on using ondrawscript with animationscript in regard to using strings, or I forgot. Using drawstring doesn't work in animationscript, so that's when I use settextobj. I realized I was wrong.I see a problem here. If you are using ondrawscript, why are you using settextobj? This will constantly create a text obj, over and over, for the same text.
I think drawstring would be better in this case.
I hadn't seen this topic, but I talked to him via discord a few days ago and made this code
C-like:void main(){ void self = getlocalvar("self"); // get self void bossName = getentityproperty(self, "name"); // get boss name //drawstring(int x, int y, int font#, text, layer) drawstring( 140, 30,0,bossName); }
But I liked your solution with strwidth so it could be easily placed.
void main(){
void self = getlocalvar("self");
int hres = openborvariant("hresolution");
void name = getentityproperty(self, "name");
drawstring((hres-strwidth(name, 0))/2+73, 11, 0, name);
}