Changing variable when player is near event

Rekkid

Villager
Member
Joined
Jan 3, 2014
Messages
8
Reaction score
0
First Language
English
Primarily Uses
I'm trying to change the value of a variable to the events ID when the player is within range of it. This is what I have but it's not working.


var get_distance = [Math.abs($gamePlayer._x - this.eventId._x), Math.abs($gamePlayer._y - this.eventId._y)];
var target_distance = 100;
if (get_distance[0]<=target_distance && get_distance[1]<=target_distance){

$gameVariables.setValue(5, this.eventId);
}

I am using Qmovement and QABS plugins.
How can I make this work?
 

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
2,599
Reaction score
883
First Language
Dutch
Primarily Uses
RMMV
i think you best use variables to check the players X and Y with "$gameVariables.value(x)"
and its events around "$gameMap.event(this.eventId()"

as "x" being the varID
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,492
Reaction score
408
First Language
German
Primarily Uses
RMMV
The Scripters gave me something to play around with. Iam not a Scripter.
With help of rmmv script call list it got Edited a bit.
Code:
var hitDist = 0;  // just for readability
for (var a = 1; a <= 50; a++) {
  if (!!$gameMap.event(a)) {   // check that event exists
    hitDist = Math.hypot($gameMap.event(a).screenX() - $gamePlayer.screenX(),  
                         $gameMap.event(a).screenY() - $gamePlayer.screenY());
    if (hitDist <= 20) {  // in range?
      $gameSelfSwitches.setValue([$gameMap.mapId(), a, 'A'], true)
  } } }
This example uses Screencoordinates instead of Mapcoordinates. Because those are better for Action Game Swordslash stuff.
This example also checks Events 1 to 50, if its in Range, Self Switch a gets Activated.
20Pixel Radius should count as, on the same Maptile.
This should help you Edit it to your needs, else let us know.
https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-mv-script-call-list.46456/

Iam bad with Syntax, so i cant give you the .ABS example. Wasnt sure if it needs to be thatone.
 

bazrat

Pixel Game Maker MV
Veteran
Joined
Oct 15, 2018
Messages
241
Reaction score
176
First Language
English
Primarily Uses
Other
The Scripters gave me something to play around with. Iam not a Scripter.
With help of rmmv script call list it got Edited a bit.
Code:
var hitDist = 0;  // just for readability
for (var a = 1; a <= 50; a++) {
  if (!!$gameMap.event(a)) {   // check that event exists
    hitDist = Math.hypot($gameMap.event(a).screenX() - $gamePlayer.screenX(), 
                         $gameMap.event(a).screenY() - $gamePlayer.screenY());
    if (hitDist <= 20) {  // in range?
      $gameSelfSwitches.setValue([$gameMap.mapId(), a, 'A'], true)
  } } }
This example uses Screencoordinates instead of Mapcoordinates. Because those are better for Action Game Swordslash stuff.
This example also checks Events 1 to 50, if its in Range, Self Switch a gets Activated.
20Pixel Radius should count as, on the same Maptile.
This should help you Edit it to your needs, else let us know.
https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-mv-script-call-list.46456/

Iam bad with Syntax, so i cant give you the .ABS example. Wasnt sure if it needs to be thatone.
Sounds alot like event sensor plugins could help a bit? There are 2 that can be used together to give different range triggers, mog has one and there is another unnamed one out there. They work with altimits not sure about Q
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,124
Reaction score
10,634
First Language
Czech
Primarily Uses
RMMV
I wonder, is it eventId or eventId()? That could be the culprit.
 

bazrat

Pixel Game Maker MV
Veteran
Joined
Oct 15, 2018
Messages
241
Reaction score
176
First Language
English
Primarily Uses
Other
Im not very good with js but would it make a difference if you did this for your if statement?
Code:
if ((get_distance[0] <= target_distance) && (get_distance[1] <= target_distance))
 

Rekkid

Villager
Member
Joined
Jan 3, 2014
Messages
8
Reaction score
0
First Language
English
Primarily Uses
i think you best use variables to check the players X and Y with "$gameVariables.value(x)"
and its events around "$gameMap.event(this.eventId()"

as "x" being the varID
I edited the code as you said and it still will not work. I don't get any errors or anything, but the variable still doesn't update to the value of the events ID.

The Scripters gave me something to play around with. Iam not a Scripter.
With help of rmmv script call list it got Edited a bit.
Code:
var hitDist = 0;  // just for readability
for (var a = 1; a <= 50; a++) {
  if (!!$gameMap.event(a)) {   // check that event exists
    hitDist = Math.hypot($gameMap.event(a).screenX() - $gamePlayer.screenX(),
                         $gameMap.event(a).screenY() - $gamePlayer.screenY());
    if (hitDist <= 20) {  // in range?
      $gameSelfSwitches.setValue([$gameMap.mapId(), a, 'A'], true)
  } } }
This example uses Screencoordinates instead of Mapcoordinates. Because those are better for Action Game Swordslash stuff.
This example also checks Events 1 to 50, if its in Range, Self Switch a gets Activated.
20Pixel Radius should count as, on the same Maptile.
This should help you Edit it to your needs, else let us know.
https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-mv-script-call-list.46456/

Iam bad with Syntax, so i cant give you the .ABS example. Wasnt sure if it needs to be thatone.
I have not tested this one but I don't think it will work for my needs if its able to trigger on every event on the map. Let me explain further. I made a necromancer class in the game which has a skill that summons minions to attack. So far I was able to summon the minions properly and have them "follow" me between maps using Orange Custom Events plugin. But as they are now they are fairly useless. The AI for enemies that are tagged to be on the player's team is broken. They won't attack enemies unless they are hit first. So my idea was to put this script on all the enemies in the game so when the player walks into range of them the "enemy target" variable was updated with that "enemy" event's ID. Then my "minions" move route would update to move towards that event's ID and use an attack. Maybe I'm going about this all wrong?

EDIT: Finally got some free time so I used Bex's script as a base and edited it to fit my needs and after some messing around I finally got it to work. Thanks for the help everyone!
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts



I've been experimenting with improved memory management again, which allowed me to include items to increase player path length. These are both 44 grid spaces long, and stable. :LZSexcite:
I FINALLY DID IT! 5 years making my very first game and I just officially released it on STEAM..... OMG..... I can say I finished a game! The feelings!!!!!
Stream will be live shortly! I am going to be playing some Among Us! Feel free to drop by!
Ami
tv program always get the ratings (it's the reason why drama series has 1000+ episode),also full and nonsense of censorship (weird blur, a scene getting cut because the unconvenient viewer,but it unconvenient to me either. you never see what the original is)

i know the reason is to take cover the viewer from the negative thing,but i just laughing and mocking of them that they're always suck :guffaw:
Star Chart Idea - Just something I am working on.

Forum statistics

Threads
104,459
Messages
1,006,434
Members
135,966
Latest member
Kleik
Top