Simple question. How do I script detecting the collision of an lweapon and an enemy so that I can trigger an effect on impact?
Printable View
Simple question. How do I script detecting the collision of an lweapon and an enemy so that I can trigger an effect on impact?
Anyone have an idea? I've been looking at Tamamo / Mero's Bombchus Script for clues on how to do this. Basically, I'm trying to create arrows that trigger effects on impact like a Bomb Explosion or Fire.
Ya know, that's something I've considered for my quest, but since I got 0 XP in my script skill, I was gonna look around for something for that. No luck so far though.
Thanks to ZoriaRPG, I've learned how to have hold out weapons. All I need now is working collision detection, and I've got the basis for more than half my use items.
Like that, or in some similar manner with var declarations in whatever style you want, or with array indices when that's more appropriate.Code:int q; int w; npc n; lweapon l;
for ( q = Screen->NumLWeapons(); q > 0; q-- ) {
l = Screen->LoadLWeapon(q);
for ( w = Screen->NumNPCs(); w > 0; w-- ){
n = Screen->LoadNPC(w);
if ( Collision(l,n) ) //Do things;
}
}
Okay, I hate to ask this but if you have time, can you explain how it works? It looks like we're tracking the number of active lweapons and NPC's, but is this going to trigger if say I make the on collision effect a bomb blast, and the target is a wall?
Basically, you just check for collisions by brute force with a script, which is probably in your global script. So you iterate over all the lweapons and see if that one is one you want to handle by a custom script or not, then if it is you then have to iterate through all the enemies to see if it collides or not. If it does, then you just add in your desired behavior.
If the target is a wall you can just check for combo data/flags on the map instead of enemies. Same thing, except you don't loop through all the combos on screen and instead just check against 4 at most. std.zh has CombaAt(x,y) to get the combo indices for this.Code:lweapon lw;
npc e;
int lwCount = Screen->NumLWeapons();
int n = Screen->NumNPCs();
for (int i=1;i <= lwCount; i++ ) { //loop through all lweapons on screen
l = Screen->LoadLWeapon(i);
if(l->Type == MEGA_BOMB_YO) { // ...filter out whatever lweapon you are looking for.
for (int j=1; j < n; j++) {
e = Screen->LoadNPC(w);
if ( Collision(l,e) ) {
// they collided
}
}
}
}
And here is where the fun begins. So I can set up that for loop inside my global script to track collisions. Then I should have the individual effects in the individual weapon scripts. Is this correct? I can reference variables used by the global script in item scripts?