|
|
enemy won't damage player
#125069
04/19/07 20:09
04/19/07 20:09
|
Joined: Sep 2003
Posts: 733 Whitefish, Montana
JazzDude
OP
User
|
OP
User
Joined: Sep 2003
Posts: 733
Whitefish, Montana
|
I'm trying to work out an enemy code for the AUM ninja code. I'm placing this function enemy_hit() in the enemy code. Code:
function enemy_hit() { vec_set(temp, player.x); vec_sub(temp,my.x); if(vec_dist (player.x, my.x) <= 20) { attack_percentage = 0; // reset the "attack" animation frames while (attack_percentage < 100) { vec_for_vertex (weapon_tip, my, 128); // get the value in Med vec_for_vertex (weapon_base, my, 64); // get the value in Med if (c_trace (weapon_base, weapon_tip, ignore_me | ignore_passable) > 0) // the enemy has hit something? { if (you != null) { snd_play (wound_wav, 100, 0); you.health -= 10 * time_step; // if the enemy has hit the player, decrease its health } } wait (1); } } wait (1); } I've tried many variations but the player doesn't take damage. Why, oh why? 
|
|
|
Re: enemy won't damage player
[Re: JazzDude]
#125070
04/19/07 21:40
04/19/07 21:40
|
Joined: Apr 2004
Posts: 516 USA
Trooper119
User
|
User
Joined: Apr 2004
Posts: 516
USA
|
Just a quick guess, so this may be way off base, but do you set you to anything? just refrencing you or my can be dangerous some times, I sugest defining your entity as something other than you and referencing it that way, you may be making you.health go down, but if you isn't the player, it doesn't do much good.
A clever person solves a problem. A wise person avoids it. --Einstein
Currently Codeing: Free Lite-C
|
|
|
Re: enemy won't damage player
[Re: Trooper119]
#125071
04/19/07 22:27
04/19/07 22:27
|
Joined: Mar 2007
Posts: 776 Poor village - Poland ;)
tompo
User
|
User
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
|
1. vec_set(temp, player.x);vec_sub(temp,my.x); this is useless in this case. 2. I see 2 wait instrucions but only one while? Where is the firs one? Becouse if firs one is earler than attack_percentage = 0; this is still reseting to 0; or try change this (for test) to while(1) 3. use c_setminmax(me); function and then box 4. c_trace (weapon_base, weapon_tip, ignore_me | ignore_passable | use_box); if(result != 0) && (you == player) {player.health -= 10 *time_step;}
Never say never.
|
|
|
Re: enemy won't damage player
[Re: tompo]
#125072
04/19/07 23:36
04/19/07 23:36
|
Joined: Sep 2003
Posts: 733 Whitefish, Montana
JazzDude
OP
User
|
OP
User
Joined: Sep 2003
Posts: 733
Whitefish, Montana
|
Thanks for the suggestions. It still doesn't work so maybe I missed something. Here's the revision: Code:
function enemy_hit() { c_setminmax(me); if(vec_dist (player.x, my.x) <= 20) { attack_percentage = 0; // reset the "attack" animation frames while (attack_percentage < 100) { vec_for_vertex (weapon_tip, my, 128); // get the value in Med vec_for_vertex (weapon_base, my, 64); // get the value in Med if (c_trace (weapon_base, weapon_tip, ignore_me | ignore_passable| use_box) > 0) // the player has hit something? { if(result != 0) && (you == player) { player.health -= 10 *time_step; snd_play (wound_wav, 100, 0); } } wait (1); } } }
I'm not getting any errors. This is the last little stumbling block in an enemy code for the K of H code so I hope I can get it working. If I can, I'll post the player/enemy script on the contributions forum. 
|
|
|
Re: enemy won't damage player
[Re: JazzDude]
#125074
04/20/07 01:25
04/20/07 01:25
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
You're putting this function in an event right? Not just calling it every frame cycle...
Also, take out use_box from the trace and make sure your vertex numbers are set correctly (vec_for_vertex()).
xXxGuitar511 - Programmer
|
|
|
Re: enemy won't damage player
[Re: xXxGuitar511]
#125075
04/20/07 01:50
04/20/07 01:50
|
Joined: Sep 2003
Posts: 733 Whitefish, Montana
JazzDude
OP
User
|
OP
User
Joined: Sep 2003
Posts: 733
Whitefish, Montana
|
Yeah, I tried all that and more. And then tried again to make sure. This condition if(vec_dist (player.x, my.x) <= 20) seems to be the problem. I use the same piece of code for the player with the condition set to if (mouse_left == 1) and it works fine. I need a better way to trigger it. ================================ Stand by...I think I've solved it. ================================== Drats...another failed inspiration! 
Last edited by JazzDude; 04/20/07 03:37.
|
|
|
Re: enemy won't damage player
[Re: JazzDude]
#125078
04/20/07 05:06
04/20/07 05:06
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
Ok, I think I found your problem.
Are both models using the same skill# for their health? Even if they both define health with the same name, they only need to use the same skill#
xXxGuitar511 - Programmer
|
|
|
|