07-31-2016, 08:44 AM
Hi,
I've been trying to build an AI for one of my characters, however, when I tested it, the game crashes.
My character has a skill, "Self-Immolation", which converts his HP into MP by pressing DvJ, followed by A; each A alternates between losing HP and regaining MP. Pressing D ends the skill.
My plan is that if the AI has high HP and low MP, it will attempt to use that skill. If the difficulty is normal or higher, it will also check if there are enemies nearby before attempting to use it. My code is as follows:
However, when I tested it, as soon as the AI starts to use Self-Immolation, the game crashes. There are no error messages in the console, and using the skill as a human player doesn't cause problems.
Here's the code for the skill for reference:
Is there anything wrong with my code, or anything I can do to prevent these crashes?
I've been trying to build an AI for one of my characters, however, when I tested it, the game crashes.
My character has a skill, "Self-Immolation", which converts his HP into MP by pressing DvJ, followed by A; each A alternates between losing HP and regaining MP. Pressing D ends the skill.
My plan is that if the AI has high HP and low MP, it will attempt to use that skill. If the difficulty is normal or higher, it will also check if there are enemies nearby before attempting to use it. My code is as follows:
AI-Code:
int ego() { //Self-Immolation if (self.hp > 300 && self.mp < 300 && (abs(self.x - target.x) > 300 || difficulty == 2 )) { DdJ(); //Begin Self-Immolation while(self.hp > 300 && self.mp < 300 && (abs(self.x - target.x) > 300 || difficulty == 2 )) { if(self.frame == 254) { A(1,0); //activate HP loss if(self.frame == 256) { A(1,0); //activate MP gain } } if(self.frame < 250 || self.frame > 258) { return 0; } } if(self.frame == 254) { D(1,0); //End Self-Immolation }else if(self.frame < 250 || self.frame > 258) { return 0; } } return 0; } |
However, when I tested it, as soon as the AI starts to use Self-Immolation, the game crashes. There are no error messages in the console, and using the skill as a human player doesn't cause problems.
Here's the code for the skill for reference:
DATA-Code:
<frame> 250 sacrifice pic: 140 state: 15 wait: 2 next: 251 dvx: 0 dvy: 0 dvz: 0 centerx: 39 centery: 79 hit_a: 0 hit_d: 0 hit_j: 0 sound: data\050.wav wpoint: kind: 1 x: 14 y: 51 weaponact: 20 attacking: 0 cover: 0 dvx: 0 dvy: 0 dvz: 0 wpoint_end: bdy: kind: 0 x: 20 y: 13 w: 37 h: 67 bdy_end: <frame_end> <frame> 251 sacrifice pic: 141 state: 15 wait: 2 next: 252 dvx: 0 dvy: 0 dvz: 0 centerx: 39 centery: 79 hit_a: 0 hit_d: 0 hit_j: 0 sound: data\052.wav wpoint: kind: 1 x: 14 y: 52 weaponact: 20 attacking: 0 cover: 0 dvx: 0 dvy: 0 dvz: 0 wpoint_end: bdy: kind: 0 x: 18 y: 14 w: 39 h: 66 bdy_end: <frame_end> <frame> 252 sacrifice pic: 142 state: 15 wait: 2 next: 253 dvx: 0 dvy: 0 dvz: 0 centerx: 39 centery: 79 hit_a: 0 hit_d: 0 hit_j: 0 wpoint: kind: 1 x: 14 y: 52 weaponact: 20 attacking: 0 cover: 0 dvx: 0 dvy: 0 dvz: 0 wpoint_end: bdy: kind: 0 x: 18 y: 14 w: 38 h: 66 bdy_end: <frame_end> <frame> 253 sacrifice pic: 143 state: 15 wait: 2 next: 254 dvx: 0 dvy: 0 dvz: 0 centerx: 39 centery: 79 hit_a: 0 hit_d: 0 hit_j: 0 wpoint: kind: 1 x: 13 y: 49 weaponact: 20 attacking: 0 cover: 0 dvx: 0 dvy: 0 dvz: 0 wpoint_end: bdy: kind: 0 x: 17 y: 16 w: 39 h: 64 bdy_end: <frame_end> <frame> 254 sacrifice pic: 144 state: 15 wait: 45 next: 999 dvx: 0 dvy: 0 dvz: 0 centerx: 39 centery: 79 hit_a: 255 hit_d: 999 hit_j: 0 wpoint: kind: 1 x: 15 y: 47 weaponact: 20 attacking: 0 cover: 0 dvx: 0 dvy: 0 dvz: 0 wpoint_end: bdy: kind: 0 x: 15 y: 15 w: 42 h: 65 bdy_end: <frame_end> <frame> 255 sacrifice pic: 145 state: 15 wait: 0 next: 256 dvx: 0 dvy: 0 dvz: 0 centerx: 39 centery: 79 hit_a: 256 hit_d: 999 hit_j: 0 mp: 5000 wpoint: kind: 1 x: 17 y: 51 weaponact: 20 attacking: 0 cover: 0 dvx: 0 dvy: 0 dvz: 0 wpoint_end: bdy: kind: 0 x: 18 y: 11 w: 37 h: 68 bdy_end: <frame_end> <frame> 256 sacrifice pic: 145 state: 15 wait: 45 next: 999 dvx: 0 dvy: 0 dvz: 0 centerx: 39 centery: 79 hit_a: 257 hit_d: 999 hit_j: 0 opoint: kind: 1 x: 40 y: 39 action: 10 dvx: 0 dvy: 0 oid: 210 facing: 0 opoint_end: wpoint: kind: 1 x: 17 y: 51 weaponact: 20 attacking: 0 cover: 0 dvx: 0 dvy: 0 dvz: 0 wpoint_end: bdy: kind: 0 x: 18 y: 11 w: 37 h: 68 bdy_end: <frame_end> <frame> 257 sacrifice pic: 146 state: 15 wait: 0 next: 258 dvx: 0 dvy: 0 dvz: 0 centerx: 39 centery: 79 hit_a: 0 hit_d: 999 hit_j: 0 mp: -50 wpoint: kind: 1 x: 19 y: 52 weaponact: 21 attacking: 0 cover: 0 dvx: 0 dvy: 0 dvz: 0 wpoint_end: bdy: kind: 0 x: 20 y: 10 w: 36 h: 69 bdy_end: <frame_end> <frame> 258 sacrifice pic: 144 state: 15 wait: 0 next: 254 dvx: 0 dvy: 0 dvz: 0 centerx: 39 centery: 79 hit_a: 255 hit_d: 999 hit_j: 0 opoint: kind: 1 x: 40 y: 39 action: 40 dvx: 0 dvy: 0 oid: 9001 facing: 0 opoint_end: wpoint: kind: 1 x: 15 y: 47 weaponact: 20 attacking: 0 cover: 0 dvx: 0 dvy: 0 dvz: 0 wpoint_end: bdy: kind: 0 x: 15 y: 15 w: 42 h: 65 bdy_end: <frame_end> |
Is there anything wrong with my code, or anything I can do to prevent these crashes?