Qhimm.com Forums

Miscellaneous Forums => General Discussion => Topic started by: Armorvil on 2010-07-02 21:57:09

Title: AI script to tell a monster to die if its MP reach 0 ?
Post by: Armorvil on 2010-07-02 21:57:09
Urgh, I never really know if these kinds of topics go in Game Tweaking or General... ...Feel free to move it if I made the wrong choice.

Anyways, this topic was brought up before, but a long time ago. I tried to search for the info, but it's nowhere to be found (I think they got purged when a bunch of AI-related posts, in the Proud Clod thread, were deleted). And I lost the info I need.

Basically, I need help in coming-up with an AI code that would make an enemy die if it has no MP left. I remember that someone found a code, and it worked - even though all enemies in the formation that shared this code also died, when one of them was MP-killed. This is no problem though, I already planned to only make MP-killable, enemies that appear only one at a time in a formation (I edited my scenes' formations to that end).

I thought I saved the info on my comp, but the only code I found is this :

Code: [Select]
02  2060
03  4180
80
60  00
40
70  0035
12  2060
10  4022
80
60  00
90
12  2060
10  4020
80
60  00
90
12  2060
10  4023
80
60  00
90
12  2060
10  4024
80
60  00
90
73

But I tried to type this in Post-attack (with an older version of PrC, the newest versions being plagued with an Out of range exception when you try to add more than one line), and it didn't work. Once again, any help would be appreciated.
Title: Re: AI script to tell a monster to die if its MP reach 0 ?
Post by: nfitc1 on 2010-07-02 23:11:52
Urgh, I never really know if these kinds of topics go in Game Tweaking or General... ...Feel free to move it if I made the wrong choice.

Anyways, this topic was brought up before, but a long time ago. I tried to search for the info, but it's nowhere to be found (I think they got purged when a bunch of AI-related posts, in the Proud Clod thread, were deleted). And I lost the info I need.

Basically, I need help in coming-up with an AI code that would make an enemy die if it has no MP left. I remember that someone found a code, and it worked - even though all enemies in the formation that shared this code also died, when one of them was MP-killed. This is no problem though, I already planned to only make MP-killable, enemies that appear only one at a time in a formation (I edited my scenes' formations to that end).

I thought I saved the info on my comp, but the only code I found is this :

Code: [Select]
02  2060
03  4180
80
60  00
40
70  0035
12  2060
10  4022
80
60  00
90
12  2060
10  4020
80
60  00
90
12  2060
10  4023
80
60  00
90
12  2060
10  4024
80
60  00
90
73

But I tried to type this in Post-attack (with an older version of PrC, the newest versions being plagued with an Out of range exception when you try to add more than one line), and it didn't work. Once again, any help would be appreciated.

The immediate problem is that "Post-Attack" isn't "Post-Attack" (http://forums.qhimm.com/index.php?topic=10034.msg132693#msg132693).

The best way to do this is to add this function to the formations' "General Counter" script. That way after any actions are performed (it may require damage calculation to trigger this) the formation's "General Counter" would loop through all appropriate enemies and kill off whomever has 0MP. That's the only way I can think to reliably do it.

You're code basically has the right idea though. It'd need to be altered to loop through the appropriate enemies (I haven't tested this, but it's theoretically sound)
Code: [Select]
12 0200
60 04
90
12 0300
02 0200
87
90
02 0300
02 4120
80
61 XXXX  <-- specific enemyID
71 004F
02 0300
03 4180
80
60 00
40
70 0050
02 0300
10 4022
80
60 00
90
02 0300
10 4020
80
60 00
90
02 0300
10 4023
80
60 00
90
02 0300
10 4024
80
60 00
90
12 0200
02 0200
60 01
30
90
02 0200
60 09
43
70 0006
73

Translates to:

Code: [Select]
LocalVar:0200 <- 4
DO
{
LocalVar:0300 <- FlagBit(LocalVar:0200)
If (LocalVar:0300.EnemyID == XXXX)
{
If ( (LocalVar:0300.MHP == 0) )
{
LocalVar:0300.Flag:Unknown(00000004) <- 0
LocalVar:0300.Flag:Invisible <- 0
LocalVar:0300.Flag:Targetable <- 0
LocalVar:0300.Flag:MainScriptActive <- 0
}
}
LocalVar:0200 <- LocalVar:0200 + 1
}  WHILE LocalVar:0300 <= 9
SCRIPT END

That will look through certain enemies and should kill them when their MP runs out. This script is only 100 bytes in size so it would be usuable in all four scenes if needed. You can check for all three ids in the scene if you'd like, that'd only take about 24 or so additional bytes (per script) at most.
Title: Re: AI script to tell a monster to die if its MP reach 0 ?
Post by: obesebear on 2010-07-03 01:51:54
If you're planning to release something, throw it in Game Tweaking.  If you just have a question that you think someone else will easily have the answer to, General.

And then if it's a question where you will need to delve into the game's code and discover something new (and plan to do so) Tech-Related.
Title: Re: AI script to tell a monster to die if its MP reach 0 ?
Post by: Armorvil on 2010-07-03 11:54:03
I just tried your code in the formations' AI, NFITC1 (pasted it in the 4 formations, to make sure), and it doesn't work : the battle goes on as usual. And I also tried to insert it in the enemy's general counter script to no avail. :( Same with the code I got, putting it in the general counter of an enemy doesn't work either  :cry:

Quote
If you're planning to release something, throw it in Game Tweaking.  If you just have a question that you think someone else will easily have the answer to, General.

And then if it's a question where you will need to delve into the game's code and discover something new (and plan to do so) Tech-Related.

OK, thanks for the clarification Obesebear.

EDIT :

Sorry, I finally found the original thread (http://forums.qhimm.com/index.php?topic=8802.0). Titeguy3 was the one who managed to find a working script ^^ Kudos to him :)

I can't believe I couldn't find the thread yesterday, and that I didn't save the right script in my HDD... ...Sorry about that, it's the second time I create a useless topic in a couple days  :-[
Anyways, thanks for trying to help, NFITC1 ;)
Title: Re: AI script to tell a monster to die if its MP reach 0 ?
Post by: Bosola on 2010-07-03 17:18:19
Basically, I need help in coming-up with an AI code that would make an enemy die if it has no MP left. I remember that someone found a code, and it worked - even though all enemies in the formation that shared this code also died, when one of them was MP-killed.

So, if you have two dragons in a fight, but want only one to be MP 'sensitive'. Off the top of my head, your options are:

* create a new, second enemy that uses the same dragon model. Give it its own AI code (verbose!)
* have the AI code only active for monsters with a particular formation ID (neater)
* make both MP sensitive, but make an MP 'death' change a BattleVar that 'deactivates' the MP-sensitivity script on the other monster (if you don't mind which one dragon dies at 0 MP, just want only *one* to be vulnerable to this per battle)


I'll give the code a proper look tonight if I get the chance, see if I can spot what's going on.
Title: Re: AI script to tell a monster to die if its MP reach 0 ?
Post by: nfitc1 on 2010-07-03 18:51:03
I just tried your code in the formations' AI, NFITC1 (pasted it in the 4 formations, to make sure), and it doesn't work : the battle goes on as usual. And I also tried to insert it in the enemy's general counter script to no avail. :( Same with the code I got, putting it in the general counter of an enemy doesn't work either  :cry:

If it doesn't work in the general counter of the formation then you should append that code to the end of the monster's main, just without the flagbit loop. Your original code would work fine for that.

EDIT: I think I can contribute two points to this conversation:

1. I doubt that will actually work. Appending to the end of the main script I mean. Scripts are all designed to be run in a single frame. With that in mind, MP only decreases AFTER the action is performed. Since actions aren't performed until after the script is completely run appending it to the end of the Main script will not work.

Sequence of events:

Enemy0's turn begins
Enemy0's Main script runs
:Stuff happens in Main script
:Enemy0 queues up "Flare" magic attack
:Enemy0's Main script terminates
If Enemy0 has enough MP, Flare will be cast; Otherwise it displays message of not enough MP.
MP is deducted accordingly.

See that the Main script terminates before MP is deducted? Since this is the case, the enemy won't die until its next turn.

2. The jumps in my code are a little off:

Code: [Select]
02   0300
02   4120
80
61   XXXX  <-- specific enemyID
71   004F

Should be:

Code: [Select]
02   0300
02   4120
80
61   XXXX  <-- specific enemyID
71   0050

Try that out again.
Title: Re: AI script to tell a monster to die if its MP reach 0 ?
Post by: Bosola on 2010-07-03 22:28:15
Not sure why general counter isn't working. Should be possible to do a blanket search for all enemies with a certain Index and MP 0, then force-death them. Counter should be on another unit.

Or, put the counter script on Cloud. 'Feed' the script enemy indeces set with a BattleVar established at the start of the battle.


Title: Re: AI script to tell a monster to die if its MP reach 0 ?
Post by: Armorvil on 2010-07-03 23:01:00
I'm glad both of you are interested and desire to help, but I already got what I wanted ;)
My formations are arranged so there's only one MP-killable enemy at a time, so Titeguy's code is perfect  ;D