YesNoOk
avatar

AI Detect Enemy's (Helper) Projectile System (Read 11245 times)

Started by ink, May 17, 2017, 08:30:27 pm
Share this topic:

ink

AI Detect Enemy's (Helper) Projectile System
#1  May 17, 2017, 08:30:27 pm
  • ****
  • inktrebuchet
    • USA
    • s236.photobucket.com/albums/ff271/inktrebuchet/?
NOTE: This code replaces the one that I have found people are currently using: trigger? = (enemy, numhelper) . That code may seem to works for some characters but it actually detects any helper being used, not just projectiles! So an enemy with a helper on screen at all times, such as Megaman and his dog Rush will always trigger that code or any enemy that uses a helper for an effect will also trigger that code.

This is a helper that stays bound to the character to detect if an enemy spawns a (Helper) Projectile. That PlayerId can then be used to find out a lot more about the projectile. Including velocity, distance, position on screen etc.

This system does use one root variable (var(48)) and IntPersistIndex in the constants part of the cns has to be set different than most characters defaults. (see notes in code.)

There are plenty of notes included. If anyone thinks of a way to improve this let me know!
 
This goes in state -2
Code:
[state -2, AI Detect Projectile System]
type = helper
trigger1 = ailevel && !numhelper(33333333)
name = "AI Detect Projectile System"
ID = 33333333
stateno = 33333333
postype = p1
ownpal = 1
keyctrl = 0
size.xscale = 1.0
size.yscale = 1.0
supermovetime = 2147483647
pausemovetime = 2147483647
ignorehitpause = 1


This goes in CNS

Spoiler: New Condensed Version (click to see content)

Spoiler: Old Long Version (click to see content)

Examples of use:
Code:
trigger1 = PlayerIDExist(helper(33333333),var(3))
trigger1 = PlayerID(helper(33333333),var(3)),p2bodydist X < 10 ; Distance between character and enemy's projectile is less than 10.






Last Edit: April 06, 2018, 02:56:05 pm by ink

ink

Re: AI Detect Enemy's (Helper) Projectile System
#2  May 23, 2017, 08:17:15 pm
  • ****
  • inktrebuchet
    • USA
    • s236.photobucket.com/albums/ff271/inktrebuchet/?
I experimented with AI being able to slide safely under an enemy's projectile helper today and realized a limitation of this system!

I made a ChangeState something like this:
Code:
;slide under enemy's projectile. 
[State -1, AI slide]
type = ChangeState
value = 1100
triggerall = ailevel 
triggerall = statetype = S || statetype = C
trigger1 = PlayerIdExist(helper(33333333),var(3)) ;projectile exists
trigger1 = (PlayerId(helper(33333333),var(3)), p2bodydist x) / (PlayerId(helper(33333333),var(3)), vel x) > 9 ; 9 = lowest point of moves hitbox .
trigger1 = (PlayerId(helper(33333333),var(3)), p2bodydist x) / (PlayerId(helper(33333333),var(3)), vel x) < 35 ; 35 = when hitboxs lowest point changes to a higher point.
trigger1 = PlayerId(helper(33333333),var(3)), pos y > -69 ; enemy's projectile is higher than the height of character during slide.<<<<<<<<<<<<<<<<<<< NOT accurate because projectiles axis are usually in the middle not the bottom...

Because projectile helper's axis are not at the bottom of the helper the last trigger of this code is not correct. As far as I can tell there is no way to know the size (height) of an enemy's projectile making this AI logic impossible...


Last Edit: May 24, 2017, 07:56:17 pm by ink
Re: AI Detect Enemy's (Helper) Projectile System
#3  May 31, 2017, 08:13:15 pm
  • avatar
  • ****
  • Sr. Black Person
  • Mess with the chuchu you get the pewpew
    • USA
    • network.mugenguild.com/kamekaze/
Yeah the main issue is clsns. I never bothered with in depth projectile detection because outside of full games there's too many variables involved. Solid idea though.
Want to feel useful for a useless show? click here
118/150 Chars, I'm not dead yet....the true surprise is in my thread.
Hahahah fuck you photobucket.

ink

Re: AI Detect Enemy's (Helper) Projectile System
#4  June 01, 2017, 09:41:39 pm
  • ****
  • inktrebuchet
    • USA
    • s236.photobucket.com/albums/ff271/inktrebuchet/?
Yeah, pretty much. I was building a projectile reflector system based off this code, now that all of that helpers data is easily accessed but then realized how broken it would actually be. The only realistic application this one has outside of a full game is knowing when a projectile is coming at the AI and what its speed and distance from the AI is.



Last Edit: June 15, 2017, 04:31:27 pm by ink

ink

Re: AI Detect Enemy's (Helper) Projectile System
#5  June 12, 2017, 04:23:24 pm
  • ****
  • inktrebuchet
    • USA
    • s236.photobucket.com/albums/ff271/inktrebuchet/?
Updated this today, fixed a small bug that would break everything for some characters when a intro was skipped.
Please let me know if you find anything weird or have questions.

     Posted: June 15, 2017, 04:32:46 pm
Updated again with a condensed version of the code.
Re: AI Detect Enemy's (Helper) Projectile System
New #6  June 19, 2018, 03:52:21 am
  • *
    • Brazil

  • Online
Sorry for the bump, but that is to a good cause  ;D
I want to share a C O N D E N S E D version of this awesome code made by Ink.

To accomplish this result I had to use two more variables and some Phantom States techniques to make iterations be possible(and some ridiculous tricks eheh).
Well, here is the code (some explanations in spoiler):

Spoiler, click to toggle visibilty

This goes to State -3:
Code:
[state -3, AI Detect Projectile System]
type = Helper
trigger1 = !NumHelper(33333333)
name = "AI Detect Projectile System"
ID =33333333
stateno = 33333333
postype = p1
ownpal = 1
keyctrl = 0
supermovetime = 2147483647
pausemovetime = 2147483647
ignorehitpause = 1

Code:
[Statedef 33333333]
type = A
movetype = I
physics = N
anim = 9741 ; blank
velset = 0, 0&(var(58):=var(58)+1)
ctrl = 0&(var(0):=Cond(parent,var(48)>0,parent,var(48),58))
 
[state 33333333, clip board] ; AI Common System Helper
type = DisplayToClipboard
trigger1 = 1
text = " Highest Playerid + 1 = %d , Projectile helper's PlayerId = %d"
params = var(0), var(3)
 
[state 33333333, 1] ;keeps track of player ids
type = varadd
trigger1 = PlayerIdExist(var(0)+var(58))
var(0) = 1
 
[state 33333333, 15] ;
type = varset
trigger1 = PlayerIdExist(var(0)-var(59))
trigger1 = cond(root,teamside = 1, PlayerID(var(0)-var(59)),teamside = 2, PlayerID(var(0)-var(59)),teamside = 1)
trigger1 = PlayerID(var(0)-var(59)),hitdefattr = ASC, NP, SP, HP
var(3) = (var(0)-var(59)) ;projectiles ID
 
[state 33333333, 0] ; needed to use past round 1!
type = ParentVarSet
trigger1 = 1
var(48) =  var(0)
 
[State 33333333, 7]
type = ChangeState
trigger1 = 1
value = 33333333+(var(58)=25)
 
;---------------------------------------------------------------------------------
[Statedef 33333334]
type = A
movetype = I
physics = N
velset = 0&(var(59):=var(59)+1), 0&(var(58):=0)
ctrl = 0&(var(59):=var(59)*(var(59)<=10))
 
[State 33333334, BindToRoot]
type = BindToRoot
trigger1 =1
time = 1
facing = 1
pos =0,-2
persistent =1
 
[State 33333334, 7]
type = ChangeState
trigger1 = Time
value = 33333333
Last Edit: June 25, 2018, 10:53:43 pm by Manson Rees

ink

Re: AI Detect Enemy's (Helper) Projectile System
#7  June 25, 2018, 05:01:08 pm
  • ****
  • inktrebuchet
    • USA
    • s236.photobucket.com/albums/ff271/inktrebuchet/?
@Manson Rees: I've come across something weird with your version. For some reason it does not detect projectiles from certain characters, one you could check it against is P.o.T.S.'s Shin Gouki. I looked into this a little but your version's a little more complicated to read, I'll try again when I have more free time. I bet it's from a new playerid spawning before the projectiles playerid is saved, possibly from the 1 tick state change.

Also, I strongly suggest keeping the helperID and state number (33333333) and your var(1) to var(3). This would help keep these two versions compatible if people decide to switch one out to the other. Also, the idea is for this piece of code to be easily copy and pasted to any character with very little effort, which is why (33333333) was chosen. Chances are that's not already being used in any characters, where there is a chance (10000) is being used.

Ink changed to Inktrebuchet in the credits would be appreciated too, if you find a fix.



-edit-
Tried to reapply your code to a different kfm and found another problem. It looks like you updated your code from the one I originally tested.

changing this from the original:
Code:
ctrl = 0&(Cond(parent,var(48)=0,var(0):=58,Cond(parent,var(48)>0,var(0):=parent,var(48),0)))
to this:
Code:
ctrl = 0&(var(48):=Cond(parent,var(48)>0,parent,var(48),58))
has made it not count the playerids at all.

 
Last Edit: June 25, 2018, 08:12:15 pm by ink
Re: AI Detect Enemy's (Helper) Projectile System
#8  June 25, 2018, 10:49:17 pm
  • *
    • Brazil

  • Online
@Manson Rees: I've come across something weird with your version. For some reason it does not detect projectiles from certain characters, one you could check it against is P.o.T.S.'s Shin Gouki. I looked into this a little but your version's a little more complicated to read, I'll try again when I have more free time. I bet it's from a new playerid spawning before the projectiles playerid is saved, possibly from the 1 tick state change.
Fixed.
Just replacing this line:
Code:
velset = 0&(var(59):=var(59)+(!var(59))), 0&(var(58):=var(58)+(PrevStateNo=[10000,10001]))
by that:
Code:
velset = 0, 0&(var(58):=var(58)+1)

In some cases, var(0) isn't actually equals to highest playerID + 1, because var(59) was incrementing before it really needed.

Also, I strongly suggest keeping the helperID and state number (33333333) and your var(1) to var(3). This would help keep these two versions compatible if people decide to switch one out to the other. Also, the idea is for this piece of code to be easily copy and pasted to any character with very little effort, which is why (33333333) was chosen. Chances are that's not already being used in any characters, where there is a chance (10000) is being used.
Yeah, you have a point.
Fixed!

Ink changed to Inktrebuchet in the credits would be appreciated too, if you find a fix.
Of course!

-edit-
Tried to reapply your code to a different kfm and found another problem. It looks like you updated your code from the one I originally tested.

changing this from the original:
Code:
ctrl = 0&(Cond(parent,var(48)=0,var(0):=58,Cond(parent,var(48)>0,var(0):=parent,var(48),0)))
to this:
Code:
ctrl = 0&(var(48):=Cond(parent,var(48)>0,parent,var(48),58))
has made it not count the playerids at all.
Well, the second code I set the wrong var... Because var(0) is the correct one. XD
Fixed.


Instead posting new code in this post, I'll just edit the previous one.
Thanks for your feedback, it is really appreciated. :)