MV how to detect the position, how and when a projectile launched by the player disappeared?

I posted another thread where I asked something similar, I got a response from AquaEcho (thanks 🙂)
that made me realize I wasn't so clear sorry

I wanted to make a single edit with Galv's Map Projectiles where it was dected where the shot fired by the player disappears, either by colliding with a wall or reaching the maximum distance so that when the shot disappears an event using Galv's Event Spawner is placed in the position where the trigger disappeared. This condition would not apply if the trigger collides with an event, in which case no event would be spawned

could someone help me please?

I accept any suggestion 🙂

and thanks again to AquaEcho for trying to help me on the other thread
I'm not using this plugin, but from a quick look into it, I believe the _ttd property of the projectile object determines when they will disappear, so you can either manipulate that or add your own property that would function in a similar way, and increment with every frame or number of pixels that the projectile travelled until a certain number, at which they will do something.

However as for colliding with a "wall"... that's a bit more complicated. Since the projectiles are sprites, you need to have a way for them to interact with the sprites of the map tiles, and those aren't easily accessable in the game's code.
If you have a way to check the coordinates that the projectile is currenty on, then that would be a good start. from the coordinates, you can get the tile Id and then have specific tiles that trigger a collision. Aternatively you can set a region id or terrain tag that would do the same thing.
I'm not using this plugin, but from a quick look into it, I believe the _ttd property of the projectile object determines when they will disappear, so you can either manipulate that or add your own property that would function in a similar way, and increment with every frame or number of pixels that the projectile travelled until a certain number, at which they will do something.

However as for colliding with a "wall"... that's a bit more complicated. Since the projectiles are sprites, you need to have a way for them to interact with the sprites of the map tiles, and those aren't easily accessable in the game's code.
If you have a way to check the coordinates that the projectile is currenty on, then that would be a good start. from the coordinates, you can get the tile Id and then have specific tiles that trigger a collision. Aternatively you can set a region id or terrain tag that would do the same thing.

I think this would work fine, but how would I get the coordinates that the projectile is currently at?
Nevermind, I looked into it a bit more and the plugin already has collision with region ids and terrain tags built in, it's part of checkHitEvent()

You need to manipulate this function and add another branch that checks for a specific region id or terrain tag that you define as your "walls". If the check returns true, invoke a separate function that will do whatever you define in it. Or you can just add a new property, like _collidedwithwall, set it to true and add an if branch to check for it under doHit()

There are probably other ways, this is just off the top of my head atm
Nevermind, I looked into it a bit more and the plugin already has collision with region ids and terrain tags built in, it's part of checkHitEvent()

You need to manipulate this function and add another branch that checks for a specific region id or terrain tag that you define as your "walls". If the check returns true, invoke a separate function that will do whatever you define in it. Or you can just add a new property, like _collidedwithwall, set it to true and add an if branch to check for it under doHit()

There are probably other ways, this is just off the top of my head atm
I think this might work but I don't know how to do it
something else that is not entirely necessary, but a detail: it would be interesting to have something similar to this happen when the projectile disappears when reaching the maximum distance

but if it's too complicated just for him to execute a command when hitting the wall would serve for what I'm trying to do
I could edit the functions for you, but since I don't use either of these plugins I'm not sure what commands exactly you want to trigger when the collision happens/when the projectile disappears.

If you just want to execute some event commands - no problem at all
I could edit the functions for you, but since I don't use either of these plugins I'm not sure what commands exactly you want to trigger when the collision happens/when the projectile disappears.

If you just want to execute some event commands - no problem at all
would be a single command: Galv.SPAWN.event(5,x,y);

where x and y are the position where the projectile disappeared
but it would just have to be the shots that the player would make

it could be something like: if the projectile graph is "file name" it would execute this command

whatever is easier for you employee well
Try to add this part for the wall collision (100 being the wall region id):

Spoiler: code
Sprite_MapProjectile.prototype.checkHitEvent = function() {
// Basic checking for events
var tx = Math.floor(this._obj.x / Galv.PROJ.tileSize);
var ty = Math.floor(this._obj.y / Galv.PROJ.tileSize);

// check regions
if ($gameMap.regionId(tx,ty) == 100) {
Galv.SPAWN.event(5,tx,ty);
}

if (this._obj.regions.contains($gameMap.regionId(tx,ty)) || this._obj.terrains.contains($gameMap.terrainTag(tx,ty))) {
this.doHit();
return null;
};

var events = $gameMap.events();
var event = null;
for (var i = 0; i < events.length; i++) {
var dis = Galv.PROJ.dist(events.screenX(),events.screenY() - Galv.PROJ.eYOff,this.x,this.y);

if (dis < this._hitDist && events != this._obj.sTarget && this.isBlockerEvent(events)) {
event = events;
break;
};
};
return event;
}

Don't forget to add the region id (100 in this case) to the command that spawns the projectile, otherwise it won't disappear
Try to add this part for the wall collision (100 being the wall region id):

Spoiler: code
Sprite_MapProjectile.prototype.checkHitEvent = function() {
// Basic checking for events
var tx = Math.floor(this._obj.x / Galv.PROJ.tileSize);
var ty = Math.floor(this._obj.y / Galv.PROJ.tileSize);

// check regions
if ($gameMap.regionId(tx,ty) == 100) {
Galv.SPAWN.event(5,tx,ty);
}

if (this._obj.regions.contains($gameMap.regionId(tx,ty)) || this._obj.terrains.contains($gameMap.terrainTag(tx,ty))) {
this.doHit();
return null;
};

var events = $gameMap.events();
var event = null;
for (var i = 0; i < events.length; i++) {
var dis = Galv.PROJ.dist(events.screenX(),events.screenY() - Galv.PROJ.eYOff,this.x,this.y);

if (dis < this._hitDist && events != this._obj.sTarget && this.isBlockerEvent(events)) {
event = events;
break;
};
};
return event;
}

Don't forget to add the region id (100 in this case) to the command that spawns the projectile, otherwise it won't disappear
in the plugin's javascript file, right? (Sorry I don't know much about that yet)
should i put it over the old code or should i keep both?
To be on the safe side, save my code as a new plugin and add it to the game
To be on the safe side, save my code as a new plugin and add it to the game

I put it but for some reason the projectile crosses region 100

index.php

1683583423699.png


1683583446626.png
Can you show me the command that spawns the projectile?

Also, add this to the new plugin: (for when the projectile reaches its distance limits)

Spoiler: code
Sprite_MapProjectile.prototype.updateDead = function() {
if (this._obj.ttl <= 0) {
if (this.ttd <= 0) {
var tx = Math.floor(this._obj.x / Galv.PROJ.tileSize);
var ty = Math.floor(this._obj.y / Galv.PROJ.tileSize);
Galv.SPAWN.event(5,tx,ty);

this.opacity -= Galv.PROJ.fadeSpeed;
if (this.opacity <= 0) {
this.dead = true;
Galv.PROJ.requireClean = true;
}
};
this.ttd -= 1;
};
};
Can you show me the command that spawns the projectile?

Also, add this to the new plugin: (for when the projectile reaches its distance limits)

Spoiler: code
Sprite_MapProjectile.prototype.updateDead = function() {
if (this._obj.ttl <= 0) {
if (this.ttd <= 0) {
var tx = Math.floor(this._obj.x / Galv.PROJ.tileSize);
var ty = Math.floor(this._obj.y / Galv.PROJ.tileSize);
Galv.SPAWN.event(5,tx,ty);

this.opacity -= Galv.PROJ.fadeSpeed;
if (this.opacity <= 0) {
this.dead = true;
Galv.PROJ.requireClean = true;
}
};
this.ttd -= 1;
};
};
here
imagem_2023-05-08_191242449.png
1683584172208.png

it uses this value to find out if the projectile was launched by the player
Can you show me the premade settings for projectile id 4?
Can you show me the premade settings for projectile id 4?
-1,'0',8,6,'bullet0(8,5)',1,'|c(1),e,S(1:on)',[1],null,null,666
You forgot to add the region id 🙂 try this:

-1,'0',8,6,'bullet0(8,5)',1,'|c(1),e,S(1:on)',[100],[1],null,null,666
You forgot to add the region id 🙂 try this:

-1,'0',8,6,'bullet0(8,5)',1,'|c(1),e,S(1:on)',[100],[1],null,null,666
1683584895487.png


now the shot disappears even before exiting the player

Original thread: https://forums.rpgmakerweb.com/threads/how-to-detect-the-position-how-and-when-a-projectile-launched-by-the-player-disappeared.157324/