|
Damage above Head problem
#332272
07/08/10 13:37
07/08/10 13:37
|
Joined: Jun 2008
Posts: 428
Rasch
OP
Senior Member
|
OP
Senior Member
Joined: Jun 2008
Posts: 428
|
Hi there, i got a problem. I´ve written a script that shows the dmg or healing over the head of a unit. For that i always check if the health of the unit is the same as before. if not it start a function that checks if the health is over the old value or above. Then it starts another function that creates the text and moves the text up. Everything works fine. My problem now is. I´m using draw_text for this. draw_text(value_str,vTextpos.x,vTextpos.y+move_up,text_color); the problem now is. if my unit gets several dmg in a short time. The string of draw text changes to the new value. Thats ok but my old strings (thos who are flying upwards with the dmg before) also change their value to the new one. DMG Income (252) -> Text above (252) DMG Income (332) -> Text above (332, 332) DMG Income (415) -> Text above (415, 415, 415) normally it should be DMG Income (415) -> Text above (252, 332, 415) I think it depends on draw_text. Can draw_text jsut display on string at the same time even if the functions are seperated? Greets Here´s the code from the unit:
if(save_health != my.health)
{
show_dmg(save_health);
save_health = my.health;
}
Here´s the function show_dmg:
function show_dmg(var save_health)
{
STRING* health_add_str = "#5";
STRING* health_loose_str = "#5";
var health_add = 0;
var health_loose = 0;
VECTOR color;
if(my.health > save_health)
{
health_add = (my.health - save_health);
vec_set(color, vector(100,255,100));
str_for_num(health_add_str, health_add);
dmg_text(health_add_str, color);
}
if(my.health < save_health)
{
health_loose = (save_health - my.health);
vec_set(color, vector(50,50,255));
str_for_num(health_loose_str, health_loose);
dmg_text(health_loose_str, color);
}
}
here´s the dmg_text function:
function dmg_text(STRING* ab_text, VECTOR* color)
{
var hold_text = 0;
var move_up = 0;
var fade = 100;
var draw_var;
VECTOR text_color;
VECTOR vTextpos;
STRING* value_str = "#5";
vec_set(text_color, color);
str_cpy(value_str, ab_text);
while(1)
{
vec_set(vTextpos, vector(my.x,my.y,my.z+my.max_z+40)) ;
vec_to_screen(vTextpos,camera);
move_up -= 2*time_step;
fade -= 3*time_step;
draw_text(value_str,vTextpos.x,vTextpos.y+move_up,text_color);
//draw_textmode(NULL,0,0,fade);
if(fade <= 0)
{
break;
}
wait(1);
}
}
|
|
|
Re: Damage above Head problem
[Re: Rasch]
#332282
07/08/10 14:41
07/08/10 14:41
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
I 'THINK' what is happening is that when dmg_text gets called multiple times in one frame, it is ending up with 'ab_text' is always pointing to the same actual string, being "health_loose_str". Try this version of show_dmg instead...
function show_dmg(var save_health)
{
VECTOR color;
if(my.health > save_health)
{
vec_set(color, vector(100,255,100));
dmg_text(str_for_num(NULL,my.health-save_health), color);
}
if(my.health < save_health)
{
vec_set(color, vector(50,50,255));
dmg_text(str_for_num(NULL, save_health - my.health), color);
}
}
OR
function show_dmg(var save_health)
{
VECTOR color;
STRING* temp_str = str_create("");
if(my.health > save_health)
{
vec_set(color, vector(100,255,100));
str_for_num(temp_str,my.health-save_health)
dmg_text(temp_str, color);
}
if(my.health < save_health)
{
vec_set(color, vector(50,50,255));
str_for_num(temp_str, save_health - my.health)
dmg_text(temp_str, color);
}
wait(1);
str_remove(temp_str);
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Damage above Head problem
[Re: EvilSOB]
#332289
07/08/10 15:30
07/08/10 15:30
|
Joined: Jun 2008
Posts: 428
Rasch
OP
Senior Member
|
OP
Senior Member
Joined: Jun 2008
Posts: 428
|
Both of your solutions do the same as mine. The problem must be in the dmg_text function. Watch the movie to see the problem As you can see the "older" value changes to the new one. - SOLVED -
Last edited by Rasch; 07/09/10 22:53.
|
|
|
Re: Damage above Head problem
[Re: Rasch]
#332291
07/08/10 15:38
07/08/10 15:38
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
I'm not sure if this function still works or not, but I used to call it when the entity was hit (no while loop).
function show_damage(var* pos, damage) {
var duration = 20;
VECTOR loc_pos;
TEXT* txt_damage_points = txt_create(1,2);
txt_damage_points.font = font_create("Arial#25b");
set(txt_damage_points,LIGHT | OUTLINE | CENTER_X | CENTER_Y);
txt_damage_points.red = 255;
txt_damage_points.green = 53;
txt_damage_points.blue = 5;
str_cpy((txt_damage_points.pstring)[0],str_for_num(NULL,damage));
vec_set(loc_pos,pos);
proc_mode = PROC_GLOBAL;
while(duration > 0) {
vec_set(temp,loc_pos);
if(vec_to_screen(temp,camera)) {
set(txt_damage_points,SHOW);
txt_damage_points.pos_x = temp.x;
txt_damage_points.pos_y = temp.y-50+duration;
}
else {
reset(txt_damage_points,SHOW);
}
duration -= time_step;
wait(1);
}
reset(txt_damage_points,SHOW);
ptr_remove((txt_damage_points.pstring)[0]);
ptr_remove(txt_damage_points);
}
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
|